1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 /* check if path points to an executable file;
16 int FAST_FUNC execable_file(const char *name)
19 return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
22 /* search (*PATHp) for an executable file;
23 * return allocated string containing full path if found;
24 * PATHp points to the component after the one where it was found
26 * you may call find_execable again with this PATHp to continue
28 * return NULL otherwise; (PATHp is undefined)
29 * in all cases (*PATHp) contents will be trashed (s/:/NUL/).
31 char* FAST_FUNC find_execable(const char *filename, char **PATHp)
40 if (*p != '\0') { /* it's not a PATH="foo::bar" situation */
41 p = concat_path_file(p, filename);
42 if (execable_file(p)) {
49 } /* on loop exit p == NULL */
53 /* search $PATH for an executable file;
57 int FAST_FUNC exists_execable(const char *filename)
59 char *path = xstrdup(getenv("PATH"));
61 char *ret = find_execable(filename, &tmp);
70 #if ENABLE_FEATURE_PREFER_APPLETS
71 /* just like the real execvp, but try to launch an applet named 'file' first
73 int FAST_FUNC bb_execvp(const char *file, char *const argv[])
75 return execvp(find_applet_by_name(file) >= 0 ? bb_busybox_exec_path : file,