| 1 | /* Locating a program in PATH. |
| 2 | Copyright (C) 2001-2003, 2009-2020 Free Software Foundation, Inc. |
| 3 | Written by Bruno Haible <[email protected]>, 2001. |
| 4 | |
| 5 | This program is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 17 | |
| 18 | #ifndef _FINDPROG_H |
| 19 | #define _FINDPROG_H |
| 20 | |
| 21 | #include <stdbool.h> |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | |
| 28 | /* Looks up a program in the PATH. |
| 29 | Attempts to determine the pathname that would be called by execlp/execvp |
| 30 | of PROGNAME. If successful, it returns a pathname containing a slash |
| 31 | (either absolute or relative to the current directory). Otherwise, it |
| 32 | returns PROGNAME unmodified. |
| 33 | Because of the latter case, callers should use execlp/execvp, not |
| 34 | execl/execv on the returned pathname. |
| 35 | The returned string is freshly malloc()ed if it is != PROGNAME. */ |
| 36 | extern const char *find_in_path (const char *progname); |
| 37 | |
| 38 | /* Looks up a program in the given PATH-like string. |
| 39 | |
| 40 | The PATH argument consists of a list of directories, separated by ':' or |
| 41 | (on native Windows) by ';'. An empty PATH element designates the current |
| 42 | directory. A null PATH is equivalent to an empty PATH, that is, to the |
| 43 | singleton list that contains only the current directory. |
| 44 | |
| 45 | Determines the pathname that would be called by execlp/execvp of PROGNAME. |
| 46 | - If successful, it returns a pathname containing a slash (either absolute |
| 47 | or relative to the current directory). The returned string can be used |
| 48 | with either execl/execv or execlp/execvp. It is freshly malloc()ed if it |
| 49 | is != PROGNAME. |
| 50 | - Otherwise, it sets errno and returns NULL. |
| 51 | Specific errno values include: |
| 52 | - ENOENT: means that the program's file was not found. |
| 53 | - EACCES: means that the program's file cannot be accessed (due to some |
| 54 | issue with one of the ancestor directories) or lacks the execute |
| 55 | permissions. |
| 56 | If OPTIMIZE_FOR_EXEC is true, the function saves some work, under the |
| 57 | assumption that the resulting pathname will not be accessed directly, |
| 58 | only through execl/execv or execlp/execvp. |
| 59 | |
| 60 | Here, a "slash" means: |
| 61 | - On POSIX systems excluding Cygwin: a '/', |
| 62 | - On Windows, OS/2, DOS platforms: a '/' or '\'. */ |
| 63 | extern const char *find_in_given_path (const char *progname, const char *path, |
| 64 | bool optimize_for_exec); |
| 65 | |
| 66 | |
| 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | #endif /* _FINDPROG_H */ |