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