execvp addition to posixmodule.c

lance@fox.com
Thu, 14 Jul 94 16:36:31 PDT

I was going though the posix module and noticed that there
was a execv() and a execve() but no execvp()..
So here it is..

===================================================================
RCS file: /u/lance/CVS/python/Modules/posixmodule.c,v
retrieving revision 1.4
diff -b -c -r1.4 posixmodule.c
*** 1.4 1994/07/14 22:44:46
--- Modules/posixmodule.c 1994/07/14 23:30:30
***************
*** 750,755 ****
--- 750,808 ----
}

static object *
+ posix_execvp(self, args)
+ object *self;
+ object *args;
+ {
+ char *path;
+ object *argv;
+ char **argvlist;
+ int i, argc;
+ object *(*getitem) PROTO((object *, int));
+
+ /* execvp has two arguments: (path, argv), where
+ argv is a list or tuple of strings. */
+
+ if (!getargs(args, "(sO)", &path, &argv))
+ return NULL;
+ if (is_listobject(argv)) {
+ argc = getlistsize(argv);
+ getitem = getlistitem;
+ }
+ else if (is_tupleobject(argv)) {
+ argc = gettuplesize(argv);
+ getitem = gettupleitem;
+ }
+ else {
+ badarg:
+ err_badarg();
+ return NULL;
+ }
+
+ argvlist = NEW(char *, argc+1);
+ if (argvlist == NULL)
+ return NULL;
+ for (i = 0; i < argc; i++) {
+ if (!getargs((*getitem)(argv, i), "s", &argvlist[i])) {
+ DEL(argvlist);
+ goto badarg;
+ }
+ }
+ argvlist[argc] = NULL;
+
+ #ifdef BAD_EXEC_PROTOTYPES
+ execvp(path, (const char **) argvlist);
+ #else
+ execvp(path, argvlist);
+ #endif
+
+ /* If we get here it's definitely an error */
+
+ DEL(argvlist);
+ return posix_error();
+ }
+
+ static object *
posix_fork(self, args)
object *self;
object *args;
***************
*** 1335,1340 ****
--- 1388,1394 ----
{"_exit", posix__exit},
{"execv", posix_execv},
{"execve", posix_execve},
+ {"execvp", posix_execvp},
#ifndef NT
{"fork", posix_fork},
{"getegid", posix_getegid},

--
Lance Ellinghouse                lance@fox.com