[119838] trunk/base/src/pextlib1.0/flock.c

cal at macports.org cal at macports.org
Wed May 7 16:05:34 PDT 2014


Revision: 119838
          https://trac.macports.org/changeset/119838
Author:   cal at macports.org
Date:     2014-05-07 16:05:34 -0700 (Wed, 07 May 2014)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/flock.c

Modified: trunk/base/src/pextlib1.0/flock.c
===================================================================
--- 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)
@@ -16,7 +16,7 @@
  * 3. Neither the name of The MacPorts Project nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -47,139 +47,153 @@
 #include "flock.h"
 
 int
-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;
+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;
 #if defined(HAVE_LOCKF) && !defined(HAVE_FLOCK)
-	off_t curpos;
+    off_t curpos;
 #endif
-	char *res;
-	Tcl_Channel channel;
-	ClientData handle;
+    char *res;
+    Tcl_Channel channel;
+    ClientData handle;
 
-	if (objc < 3 || objc > 4) {
-		Tcl_WrongNumArgs(interp, 1, objv, "channelId switches");
-		return TCL_ERROR;
-	}
+    if (objc < 3 || objc > 4) {
+        Tcl_WrongNumArgs(interp, 1, objv, "channelId switches");
+        return TCL_ERROR;
+    }
 
-    	if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL)
-		return TCL_ERROR;
+    if ((channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL)) == NULL) {
+        return TCL_ERROR;
+    }
 
-	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;
+    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;
 
-	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;
-		}
-	}
+    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;
+        }
+    }
 
-	/* verify the arguments */
+    /* verify the arguments */
 
-	if((oshared + oexclusive + ounlock) != 1) {
-	  /* only one of the options should have been specified */
-	  Tcl_SetResult(interp, (void *) &errorstr, TCL_STATIC);
-	  return TCL_ERROR;
-	}
+    if ((oshared + oexclusive + ounlock) != 1) {
+        /* only one of the options should have been specified */
+        Tcl_SetResult(interp, (void *) &errorstr, TCL_STATIC);
+        return TCL_ERROR;
+    }
 
-	if(onoblock && ounlock) {
-	  /* should not be specified together */
-	  Tcl_SetResult(interp, "-noblock cannot be used with -unlock", TCL_STATIC);
-	  return TCL_ERROR;
-	}
-	  
+    if (onoblock && ounlock) {
+        /* should not be specified together */
+        Tcl_SetResult(interp, "-noblock cannot be used with -unlock", TCL_STATIC);
+        return TCL_ERROR;
+    }
+
 #if HAVE_FLOCK
-	/* prefer flock if present */
-	if(oshared) operation |= LOCK_SH;
+    /* prefer flock if present */
+    if (oshared) {
+        operation |= LOCK_SH;
+    }
 
-	if(oexclusive) operation |= LOCK_EX;
+    if (oexclusive) {
+        operation |= LOCK_EX;
+    }
 
-	if(ounlock) operation |= LOCK_UN;
+    if (ounlock) {
+        operation |= LOCK_UN;
+    }
 
-	if(onoblock) operation |= LOCK_NB;
+    if (onoblock) {
+        operation |= LOCK_NB;
+    }
 
-	ret = flock(fd, operation);
-	if(ret == -1) {
-	  errnoval = errno;
-	}
+    ret = flock(fd, operation);
+    if (ret == -1) {
+        errnoval = errno;
+    }
 #else
 #if HAVE_LOCKF
-	if(ounlock) operation = F_ULOCK;
+    if (ounlock) {
+        operation = F_ULOCK;
+    }
 
-	/* lockf semantics don't map to shared locks. */
-	if(oshared || oexclusive) {
-	  if(onoblock) {
-	    operation = F_TLOCK;
-	  } else {
-	    operation = F_LOCK;
-	  }
-	}
+    /* lockf semantics don't map to shared locks. */
+    if (oshared || oexclusive) {
+        if (onoblock) {
+            operation = F_TLOCK;
+        }
+        else {
+            operation = F_LOCK;
+        }
+    }
 
-	curpos = lseek(fd, 0, SEEK_CUR);
-	if(curpos == -1) {
-		Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
-		return TCL_ERROR;
-	}
+    curpos = lseek(fd, 0, SEEK_CUR);
+    if (curpos == -1) {
+        Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
+        return TCL_ERROR;
+    }
 
-	ret = lockf(fd, operation, 0); /* lock entire file */
+    ret = lockf(fd, operation, 0); /* lock entire file */
 
-	curpos = lseek(fd, curpos, SEEK_SET);
-	if(curpos == -1) {
-		Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
-		return TCL_ERROR;
-	}
+    curpos = lseek(fd, curpos, SEEK_SET);
+    if (curpos == -1) {
+        Tcl_SetResult(interp, (void *) "Seek error", TCL_STATIC);
+        return TCL_ERROR;
+    }
 
-	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;
-	    }
-	  }
-	}
+    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;
+            }
+        }
+    }
 #else
 #error no available locking implementation
 #endif /* HAVE_LOCKF */
 #endif /* HAVE_FLOCK */
 
-	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;
+    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;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140507/c9fffd88/attachment.html>


More information about the macports-changes mailing list