Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/execable.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/execable.c
r1765 r2725 5 5 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 … … 14 14 * return 0 otherwise; 15 15 */ 16 int execable_file(const char *name)16 int FAST_FUNC execable_file(const char *name) 17 17 { 18 18 struct stat s; … … 20 20 } 21 21 22 /* search $PATHfor an executable file;22 /* search (*PATHp) for an executable file; 23 23 * return allocated string containing full path if found; 24 * return NULL otherwise; 24 * PATHp points to the component after the one where it was found 25 * (or NULL), 26 * you may call find_execable again with this PATHp to continue 27 * (if it's not NULL). 28 * return NULL otherwise; (PATHp is undefined) 29 * in all cases (*PATHp) contents will be trashed (s/:/NUL/). 25 30 */ 26 char *find_execable(const char *filename)31 char* FAST_FUNC find_execable(const char *filename, char **PATHp) 27 32 { 28 char *p ath, *p, *n;33 char *p, *n; 29 34 30 p = path = xstrdup(getenv("PATH"));35 p = *PATHp; 31 36 while (p) { 32 37 n = strchr(p, ':'); … … 36 41 p = concat_path_file(p, filename); 37 42 if (execable_file(p)) { 38 free(path);43 *PATHp = n; 39 44 return p; 40 45 } … … 42 47 } 43 48 p = n; 44 } 45 free(path); 46 return NULL; 49 } /* on loop exit p == NULL */ 50 return p; 47 51 } 48 52 … … 51 55 * return 0 otherwise; 52 56 */ 53 int exists_execable(const char *filename)57 int FAST_FUNC exists_execable(const char *filename) 54 58 { 55 char *ret = find_execable(filename); 59 char *path = xstrdup(getenv("PATH")); 60 char *tmp = path; 61 char *ret = find_execable(filename, &tmp); 62 free(path); 56 63 if (ret) { 57 64 free(ret); … … 64 71 /* just like the real execvp, but try to launch an applet named 'file' first 65 72 */ 66 int bb_execvp(const char *file, char *const argv[])73 int FAST_FUNC bb_execvp(const char *file, char *const argv[]) 67 74 { 68 return execvp(find_applet_by_name(file) ? bb_busybox_exec_path : file,75 return execvp(find_applet_by_name(file) >= 0 ? bb_busybox_exec_path : file, 69 76 argv); 70 77 } 71 78 #endif 79 80 int FAST_FUNC BB_EXECVP_or_die(char **argv) 81 { 82 BB_EXECVP(argv[0], argv); 83 /* SUSv3-mandated exit codes */ 84 xfunc_error_retval = (errno == ENOENT) ? 127 : 126; 85 bb_perror_msg_and_die("can't execute '%s'", argv[0]); 86 }
Note:
See TracChangeset
for help on using the changeset viewer.