[71380] trunk/base/src/pextlib1.0/system.c

raimue at macports.org raimue at macports.org
Fri Sep 10 16:00:41 PDT 2010


Revision: 71380
          http://trac.macports.org/changeset/71380
Author:   raimue at macports.org
Date:     2010-09-10 16:00:39 -0700 (Fri, 10 Sep 2010)
Log Message:
-----------
pextlib1.0:
Add new 'system -W path' which changes into the given directory before
executing the command.

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

Modified: trunk/base/src/pextlib1.0/system.c
===================================================================
--- trunk/base/src/pextlib1.0/system.c	2010-09-10 22:27:03 UTC (rev 71379)
+++ trunk/base/src/pextlib1.0/system.c	2010-09-10 23:00:39 UTC (rev 71380)
@@ -49,6 +49,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <limits.h>
+#include <errno.h>
 
 #include "system.h"
 #include "Pextlib.h"
@@ -71,7 +72,7 @@
     char *line;
 };
 
-/* usage: system ?-notty? ?-nice value? command */
+/* usage: system ?-notty? ?-nice value? ?-W path? command */
 int SystemCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
     char *buf;
@@ -84,6 +85,7 @@
     int fline, pos, ret;
     int osetsid = 0;
     int oniceval = INT_MAX; /* magic value indicating no change */
+    const char *path = NULL;
     pid_t pid;
     uid_t euid;
     Tcl_Obj *tcl_result;
@@ -91,7 +93,7 @@
     int i;
 
     if (objc < 2) {
-        Tcl_WrongNumArgs(interp, 1, objv, "?-notty? ?-nice value? command");
+        Tcl_WrongNumArgs(interp, 1, objv, "?-notty? ?-nice value? ?-W path? command");
         return TCL_ERROR;
     }
 
@@ -107,6 +109,12 @@
                 Tcl_SetResult(interp, "invalid value for -nice", TCL_STATIC);
                 return TCL_ERROR;
             }
+        } else if (strcmp(arg, "-W") == 0) {
+            i++;
+            if ((path = Tcl_GetString(objv[i])) == NULL) {
+                Tcl_SetResult(interp, "invalid value for -W", TCL_STATIC);
+                return TCL_ERROR;
+            }
         } else {
             tcl_result = Tcl_NewStringObj("bad option ", -1);
             Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(arg, -1));
@@ -154,6 +162,14 @@
                 _exit(1);
             }
         }
+
+        if (path != NULL) {
+            if (chdir(path) == -1) {
+                printf("chdir: %s: %s\n", path, strerror(errno));
+                exit(1);
+            }
+        }
+
         /* XXX ugly string constants */
         args[0] = "sh";
         args[1] = "-c";
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100910/001cb4a1/attachment.html>


More information about the macports-changes mailing list