<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[119838] trunk/base/src/pextlib1.0/flock.c</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/119838">119838</a></dd>
<dt>Author</dt> <dd>cal@macports.org</dd>
<dt>Date</dt> <dd>2014-05-07 16:05:34 -0700 (Wed, 07 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>base: pextlib1.0/flock.c: autoformat to a consistent style
Used: astyle --style=java -s4 -S -K -L -p -U -H -k3 -y -j -c --mode=c.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbasesrcpextlib10flockc">trunk/base/src/pextlib1.0/flock.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbasesrcpextlib10flockc"></a>
<div class="modfile"><h4>Modified: trunk/base/src/pextlib1.0/flock.c (119837 => 119838)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/base/src/pextlib1.0/flock.c        2014-05-07 22:52:58 UTC (rev 119837)
+++ trunk/base/src/pextlib1.0/flock.c        2014-05-07 23:05:34 UTC (rev 119838)
</span><span class="lines">@@ -16,7 +16,7 @@
</span><span class="cx"> * 3. Neither the name of The MacPorts Project nor the names of its contributors
</span><span class="cx"> * may be used to endorse or promote products derived from this software
</span><span class="cx"> * without specific prior written permission.
</span><del>- *
</del><ins>+ *
</ins><span class="cx"> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
</span><span class="cx"> * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
</span><span class="cx"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
</span><span class="lines">@@ -47,139 +47,153 @@
</span><span class="cx"> #include "flock.h"
</span><span class="cx">
</span><span class="cx"> int
</span><del>-FlockCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
-{
-        static const char errorstr[] = "use one of \"-shared\", \"-exclusive\", or \"-unlock\", and optionally \"-noblock\"";
-        int operation = 0, fd, i, ret;
-        int errnoval = 0;
-        int oshared = 0, oexclusive = 0, ounlock = 0, onoblock = 0;
</del><ins>+FlockCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
+ static const char errorstr[] = "use one of \"-shared\", \"-exclusive\", or \"-unlock\", and optionally \"-noblock\"";
+ int operation = 0, fd, i, ret;
+ int errnoval = 0;
+ int oshared = 0, oexclusive = 0, ounlock = 0, onoblock = 0;
</ins><span class="cx"> #if defined(HAVE_LOCKF) && !defined(HAVE_FLOCK)
</span><del>-        off_t curpos;
</del><ins>+ off_t curpos;
</ins><span class="cx"> #endif
</span><del>-        char *res;
-        Tcl_Channel channel;
-        ClientData handle;
</del><ins>+ char *res;
+ Tcl_Channel channel;
+ ClientData handle;
</ins><span class="cx">
</span><del>-        if (objc < 3 || objc > 4) {
-                Tcl_WrongNumArgs(interp, 1, objv, "channelId switches");
-                return TCL_ERROR;
-        }
</del><ins>+ if (objc < 3 || objc > 4) {
+ Tcl_WrongNumArgs(interp, 1, objv, "channelId switches");
+ return TCL_ERROR;
+ }
</ins><span class="cx">
</span><del>-         if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL)
-                return TCL_ERROR;
</del><ins>+ if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL) {
+ return TCL_ERROR;
+ }
</ins><span class="cx">
</span><del>-        if (Tcl_GetChannelHandle(channel, TCL_READABLE|TCL_WRITABLE, &handle) != TCL_OK) {
-                Tcl_SetResult(interp, "error getting channel handle", TCL_STATIC);
-                return TCL_ERROR;
-        }
-        fd = (int)(intptr_t)handle;
</del><ins>+ if (Tcl_GetChannelHandle(channel, TCL_READABLE | TCL_WRITABLE, &handle) != TCL_OK) {
+ Tcl_SetResult(interp, "error getting channel handle", TCL_STATIC);
+ return TCL_ERROR;
+ }
+ fd = (int)(intptr_t)handle;
</ins><span class="cx">
</span><del>-        for (i = 2; i < objc; i++) {
-                char *arg = Tcl_GetString(objv[i]);
-                if (!strcmp(arg, "-shared")) {
-                 oshared = 1;
-                } else if (!strcmp(arg, "-exclusive")) {
-                 oexclusive = 1;
-                } else if (!strcmp(arg, "-unlock")) {
-                 ounlock = 1;
-                } else if (!strcmp(arg, "-noblock")) {
-                 onoblock = 1;
-                }
-        }
</del><ins>+ for (i = 2; i < objc; i++) {
+ char *arg = Tcl_GetString(objv[i]);
+ if (!strcmp(arg, "-shared")) {
+ oshared = 1;
+ }
+ else if (!strcmp(arg, "-exclusive")) {
+ oexclusive = 1;
+ }
+ else if (!strcmp(arg, "-unlock")) {
+ ounlock = 1;
+ }
+ else if (!strcmp(arg, "-noblock")) {
+ onoblock = 1;
+ }
+ }
</ins><span class="cx">
</span><del>-        /* verify the arguments */
</del><ins>+ /* verify the arguments */
</ins><span class="cx">
</span><del>-        if((oshared + oexclusive + ounlock) != 1) {
-         /* only one of the options should have been specified */
-         Tcl_SetResult(interp, (void *) &errorstr, TCL_STATIC);
-         return TCL_ERROR;
-        }
</del><ins>+ if ((oshared + oexclusive + ounlock) != 1) {
+ /* only one of the options should have been specified */
+ Tcl_SetResult(interp, (void *) &errorstr, TCL_STATIC);
+ return TCL_ERROR;
+ }
</ins><span class="cx">
</span><del>-        if(onoblock && ounlock) {
-         /* should not be specified together */
-         Tcl_SetResult(interp, "-noblock cannot be used with -unlock", TCL_STATIC);
-         return TCL_ERROR;
-        }
-        
</del><ins>+ if (onoblock && ounlock) {
+ /* should not be specified together */
+ Tcl_SetResult(interp, "-noblock cannot be used with -unlock", TCL_STATIC);
+ return TCL_ERROR;
+ }
+
</ins><span class="cx"> #if HAVE_FLOCK
</span><del>-        /* prefer flock if present */
-        if(oshared) operation |= LOCK_SH;
</del><ins>+ /* prefer flock if present */
+ if (oshared) {
+ operation |= LOCK_SH;
+ }
</ins><span class="cx">
</span><del>-        if(oexclusive) operation |= LOCK_EX;
</del><ins>+ if (oexclusive) {
+ operation |= LOCK_EX;
+ }
</ins><span class="cx">
</span><del>-        if(ounlock) operation |= LOCK_UN;
</del><ins>+ if (ounlock) {
+ operation |= LOCK_UN;
+ }
</ins><span class="cx">
</span><del>-        if(onoblock) operation |= LOCK_NB;
</del><ins>+ if (onoblock) {
+ operation |= LOCK_NB;
+ }
</ins><span class="cx">
</span><del>-        ret = flock(fd, operation);
-        if(ret == -1) {
-         errnoval = errno;
-        }
</del><ins>+ ret = flock(fd, operation);
+ if (ret == -1) {
+ errnoval = errno;
+ }
</ins><span class="cx"> #else
</span><span class="cx"> #if HAVE_LOCKF
</span><del>-        if(ounlock) operation = F_ULOCK;
</del><ins>+ if (ounlock) {
+ operation = F_ULOCK;
+ }
</ins><span class="cx">
</span><del>-        /* lockf semantics don't map to shared locks. */
-        if(oshared || oexclusive) {
-         if(onoblock) {
-         operation = F_TLOCK;
-         } else {
-         operation = F_LOCK;
-         }
-        }
</del><ins>+ /* lockf semantics don't map to shared locks. */
+ if (oshared || oexclusive) {
+ if (onoblock) {
+ operation = F_TLOCK;
+ }
+ else {
+ operation = F_LOCK;
+ }
+ }
</ins><span class="cx">
</span><del>-        curpos = lseek(fd, 0, SEEK_CUR);
-        if(curpos == -1) {
-                Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
-                return TCL_ERROR;
-        }
</del><ins>+ curpos = lseek(fd, 0, SEEK_CUR);
+ if (curpos == -1) {
+ Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
+ return TCL_ERROR;
+ }
</ins><span class="cx">
</span><del>-        ret = lockf(fd, operation, 0); /* lock entire file */
</del><ins>+ ret = lockf(fd, operation, 0); /* lock entire file */
</ins><span class="cx">
</span><del>-        curpos = lseek(fd, curpos, SEEK_SET);
-        if(curpos == -1) {
-                Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
-                return TCL_ERROR;
-        }
</del><ins>+ curpos = lseek(fd, curpos, SEEK_SET);
+ if (curpos == -1) {
+ Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
+ return TCL_ERROR;
+ }
</ins><span class="cx">
</span><del>-        if(ret == -1) {
-         errnoval = errno;
-         if((oshared || oexclusive)) {
-         /* map the errno val to what we would expect for flock */
-         if(onoblock && errnoval == EAGAIN) {
-         /* on some systems, EAGAIN=EWOULDBLOCK, but lets be safe */
-         errnoval = EWOULDBLOCK;
-         } else if(errnoval == EINVAL) {
-         errnoval = EOPNOTSUPP;
-         }
-         }
-        }
</del><ins>+ if (ret == -1) {
+ errnoval = errno;
+ if ((oshared || oexclusive)) {
+ /* map the errno val to what we would expect for flock */
+ if (onoblock && errnoval == EAGAIN) {
+ /* on some systems, EAGAIN=EWOULDBLOCK, but lets be safe */
+ errnoval = EWOULDBLOCK;
+ }
+ else if (errnoval == EINVAL) {
+ errnoval = EOPNOTSUPP;
+ }
+ }
+ }
</ins><span class="cx"> #else
</span><span class="cx"> #error no available locking implementation
</span><span class="cx"> #endif /* HAVE_LOCKF */
</span><span class="cx"> #endif /* HAVE_FLOCK */
</span><span class="cx">
</span><del>-        if (ret != 0)
-        {
-                switch(errnoval) {
-                        case EAGAIN:
-                                res = "EAGAIN";
-                                break;
-                        case EBADF:
-                                res = "EBADF";
-                                break;
-                        case EINVAL:
-                                res = "EINVAL";
-                                break;
-                        case EOPNOTSUPP:
-                                res = "EOPNOTSUPP";
-                                break;
-                        default:
-                                res = strerror(errno);
-                                break;
-                }
-                Tcl_SetResult(interp, (void *) res, TCL_STATIC);
-                return TCL_ERROR;
-        }
-        return TCL_OK;
</del><ins>+ if (ret != 0) {
+ switch (errnoval) {
+ case EAGAIN:
+ res = "EAGAIN";
+ break;
+ case EBADF:
+ res = "EBADF";
+ break;
+ case EINVAL:
+ res = "EINVAL";
+ break;
+ case EOPNOTSUPP:
+ res = "EOPNOTSUPP";
+ break;
+ default:
+ res = strerror(errno);
+ break;
+ }
+ Tcl_SetResult(interp, (void *) res, TCL_STATIC);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>