findprog.h 3.2 KB

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