2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 POSIX function execvp().
8 #include <aros/debug.h>
15 /*****************************************************************************
27 Executes a file with specified arguments.
30 file - Name of the file to execute.
31 argv - Array of arguments given to main() function of the executed
35 0 in case of success. In case of failure errno is set appropriately
36 and function returns -1.
43 See execve documentation.
50 ******************************************************************************/
52 char *path
= NULL
, *path_item
, *path_ptr
;
53 char default_path
[] = ":/bin:/usr/bin";
58 if(index(file
, '/') || index(file
, ':'))
60 /* file argument is a path, don't search */
61 return execve(file
, argv
, environ
);
64 /* argument is a file, search for this file in PATH variable entries */
68 for(i
= 0; environ
[i
]; i
++)
70 if(strncmp(environ
[i
], name
, strlen(name
)) == 0)
72 path
= &environ
[i
][strlen(name
)+1];
79 path
= getenv("PATH");
88 while((path_item
= strsep(&path_ptr
, ",:")))
90 if(path_item
[0] == '\0')
93 if(full_path
= malloc(strlen(path_item
) + strlen(file
) + 2))
96 strcat(full_path
, path_item
);
97 strcat(full_path
, "/");
98 strcat(full_path
, file
);
100 /* try executing execve with this path */
101 if(execve(full_path
, argv
, environ
) == 0)
108 saved_errno
= EACCES
;
113 saved_errno
= ENOMEM
;
118 /* set ENOENT error if there were errors other than EACCES */
119 if(saved_errno
!= EACCES
)
120 saved_errno
= ENOENT
;