@@ -156,7 +156,7 @@ posix_1str(args, func)
156156{
157157 char * path1 ;
158158 int res ;
159- if (!getstrarg (args , & path1 ))
159+ if (!getargs (args , "s" , & path1 ))
160160 return NULL ;
161161 BGN_SAVE
162162 res = (* func )(path1 );
@@ -213,7 +213,7 @@ posix_do_stat(self, args, statfunc)
213213 struct stat st ;
214214 char * path ;
215215 int res ;
216- if (!getstrarg (args , & path ))
216+ if (!getargs (args , "s" , & path ))
217217 return NULL ;
218218 BGN_SAVE
219219 res = (* statfunc )(path , & st );
@@ -290,7 +290,7 @@ posix_listdir(self, args)
290290#ifdef TURBO_C
291291 struct ffblk ep ;
292292 int rv ;
293- if (!getstrarg (args , & name ))
293+ if (!getargs (args , "s" , & name ))
294294 return NULL ;
295295
296296 if (findfirst (name , & ep , 0 ) == -1 )
@@ -320,7 +320,7 @@ posix_listdir(self, args)
320320 int attrib ;
321321 int num = 0 ;
322322
323- if (!getstrarg (args , & name ))
323+ if (!getargs (args , "s" , & name ))
324324 return NULL ;
325325 strcpy ( _name , name );
326326
@@ -365,7 +365,7 @@ posix_listdir(self, args)
365365#ifdef unix
366366 DIR * dirp ;
367367 struct direct * ep ;
368- if (!getstrarg (args , & name ))
368+ if (!getargs (args , "s" , & name ))
369369 return NULL ;
370370 BGN_SAVE
371371 if ((dirp = opendir (name )) == NULL) {
@@ -470,7 +470,7 @@ posix_system(self, args)
470470{
471471 char * command ;
472472 long sts ;
473- if (!getstrarg (args , & command ))
473+ if (!getargs (args , "s" , & command ))
474474 return NULL ;
475475 BGN_SAVE
476476 sts = system (command );
@@ -587,8 +587,6 @@ posix__exit(self, args)
587587 /* NOTREACHED */
588588}
589589
590- /* XXX To do: exece, execp */
591-
592590static object *
593591posix_execv (self , args )
594592 object * self ;
@@ -623,7 +621,7 @@ posix_execv(self, args)
623621 if (argvlist == NULL )
624622 return NULL ;
625623 for (i = 0 ; i < argc ; i ++ ) {
626- if (!getstrarg ((* getitem )(argv , i ), & argvlist [i ])) {
624+ if (!getargs ((* getitem )(argv , i ), "s" , & argvlist [i ])) {
627625 DEL (argvlist );
628626 goto badarg ;
629627 }
@@ -638,6 +636,96 @@ posix_execv(self, args)
638636 return posix_error ();
639637}
640638
639+ static object *
640+ posix_execve (self , args )
641+ object * self ;
642+ object * args ;
643+ {
644+ char * path ;
645+ object * argv , * env ;
646+ char * * argvlist ;
647+ char * * envlist ;
648+ object * key , * val ;
649+ int i , pos , argc , envc ;
650+ object * (* getitem ) PROTO ((object * , int ) );
651+
652+ /* execve has three arguments: (path, argv, env), where
653+ argv is a list or tuple of strings and env is a dictionary
654+ like posix.environ. */
655+
656+ if (!getargs (args , "(sOO)" , & path , & argv , & env ))
657+ return NULL ;
658+ if (is_listobject (argv )) {
659+ argc = getlistsize (argv );
660+ getitem = getlistitem ;
661+ }
662+ else if (is_tupleobject (argv )) {
663+ argc = gettuplesize (argv );
664+ getitem = gettupleitem ;
665+ }
666+ else {
667+ err_setstr (TypeError , "argv must be tuple or list" );
668+ return NULL ;
669+ }
670+ if (!is_dictobject (env )) {
671+ err_setstr (TypeError , "env must be dictionary" );
672+ return NULL ;
673+ }
674+
675+ argvlist = NEW (char * , argc + 1 );
676+ if (argvlist == NULL ) {
677+ err_nomem ();
678+ return NULL ;
679+ }
680+ for (i = 0 ; i < argc ; i ++ ) {
681+ if (!getargs ((* getitem )(argv , i ),
682+ "s;argv must be list of strings" ,
683+ & argvlist [i ])) {
684+ goto fail_1 ;
685+ }
686+ }
687+ argvlist [argc ] = NULL ;
688+
689+ i = getmappingsize (env );
690+ envlist = NEW (char * , i + 1 );
691+ if (envlist == NULL ) {
692+ err_nomem ();
693+ goto fail_1 ;
694+ }
695+ pos = 0 ;
696+ envc = 0 ;
697+ while (mappinggetnext (env , & pos , & key , & val )) {
698+ char * p , * k , * v ;
699+ if (!getargs (key , "s;non-string key in env" , & k ) ||
700+ !getargs (val , "s;non-string value in env" , & v )) {
701+ goto fail_2 ;
702+ }
703+ p = NEW (char , getstringsize (key ) + getstringsize (val ) + 2 );
704+ if (p == NULL ) {
705+ err_nomem ();
706+ goto fail_2 ;
707+ }
708+ sprintf (p , "%s=%s" , k , v );
709+ envlist [envc ++ ] = p ;
710+ }
711+ envlist [envc ] = 0 ;
712+
713+ execve (path , argvlist , envlist );
714+
715+ /* If we get here it's definitely an error */
716+
717+ (void ) posix_error ();
718+
719+ fail_2 :
720+ while (-- envc >= 0 )
721+ DEL (envlist [envc ]);
722+ DEL (envlist );
723+ fail_1 :
724+ DEL (argvlist );
725+
726+ return NULL ;
727+ }
728+
641729static object *
642730posix_fork (self , args )
643731 object * self ;
@@ -839,7 +927,7 @@ posix_readlink(self, args)
839927 char buf [1024 ]; /* XXX Should use MAXPATHLEN */
840928 char * path ;
841929 int n ;
842- if (!getstrarg (args , & path ))
930+ if (!getargs (args , "s" , & path ))
843931 return NULL ;
844932 BGN_SAVE
845933 n = readlink (path , buf , (int ) sizeof buf );
@@ -1189,6 +1277,7 @@ static struct methodlist posix_methods[] = {
11891277#ifndef MSDOS
11901278 {"_exit" , posix__exit },
11911279 {"execv" , posix_execv },
1280+ {"execve" , posix_execve },
11921281 {"fork" , posix_fork },
11931282 {"getegid" , posix_getegid },
11941283 {"geteuid" , posix_geteuid },
0 commit comments