diff options
author | Paul Smith <psmith@gnu.org> | 2019-09-15 19:47:43 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-09-15 19:47:43 +0200 |
commit | 6e9634163167de7f153cdfd1023e5c164485f4bc (patch) | |
tree | 940c2bce61848bb503c80ddf6c947a30aab5a1cc | |
parent | ccfbc26dce79adcb32bf421ff813247699d70ea5 (diff) | |
download | gnulib-6e9634163167de7f153cdfd1023e5c164485f4bc.tar.gz gnulib-6e9634163167de7f153cdfd1023e5c164485f4bc.tar.bz2 |
findprog-in: Set errno when the search fails.
* lib/findprog-in.c: Include <errno.h>.
(find_in_given_path): Set errno before returning NULL.
* lib/findprog.h (find_in_given_path): Update comment accordingly.
Define the term "slash".
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib/findprog-in.c | 17 | ||||
-rw-r--r-- | lib/findprog.h | 14 |
3 files changed, 36 insertions, 4 deletions
@@ -1 +1,10 @@ +2019-09-15 Paul Smith <psmith@gnu.org> + Bruno Haible <bruno@clisp.org> + + findprog-in: Set errno when the search fails. + * lib/findprog-in.c: Include <errno.h>. + (find_in_given_path): Set errno before returning NULL. + * lib/findprog.h (find_in_given_path): Update comment accordingly. + Define the term "slash". + 2019-09-15 Bruno Haible <bruno@clisp.org> diff --git a/lib/findprog-in.c b/lib/findprog-in.c index d601e060d9..5e906805d8 100644 --- a/lib/findprog-in.c +++ b/lib/findprog-in.c @@ -23,2 +23,3 @@ +#include <errno.h> #include <stdbool.h> @@ -100,2 +101,3 @@ find_in_given_path (const char *progname, const char *path, with such a suffix is actually executable. */ + int failure_errno; size_t i; @@ -115,2 +117,3 @@ find_in_given_path (const char *progname, const char *path, /* Try all platform-dependent suffixes. */ + failure_errno = ENOENT; for (i = 0; i < sizeof (suffixes) / sizeof (suffixes[0]); i++) @@ -145,2 +148,5 @@ find_in_given_path (const char *progname, const char *path, + if (errno != ENOENT) + failure_errno = errno; + free (progpathname); @@ -149,2 +155,3 @@ find_in_given_path (const char *progname, const char *path, + errno = failure_errno; return NULL; @@ -160,2 +167,3 @@ find_in_given_path (const char *progname, const char *path, { + int failure_errno; /* Make a copy, to prepare for destructive modifications. */ @@ -165,2 +173,3 @@ find_in_given_path (const char *progname, const char *path, + failure_errno = ENOENT; for (path_rest = path_copy; ; path_rest = cp + 1) @@ -224,2 +233,5 @@ find_in_given_path (const char *progname, const char *path, + if (errno != ENOENT) + failure_errno = errno; + free (progpathname); @@ -234,5 +246,6 @@ find_in_given_path (const char *progname, const char *path, free (path_copy); - } - return NULL; + errno = failure_errno; + return NULL; + } } diff --git a/lib/findprog.h b/lib/findprog.h index f7b44071fb..804f02a03c 100644 --- a/lib/findprog.h +++ b/lib/findprog.h @@ -38,2 +38,3 @@ extern const char *find_in_path (const char *progname); /* Looks up a program in the given PATH-like string. + The PATH argument consists of a list of directories, separated by ':' or @@ -42,2 +43,3 @@ extern const char *find_in_path (const char *progname); singleton list that contains only the current directory. + Determines the pathname that would be called by execlp/execvp of PROGNAME. @@ -47,6 +49,14 @@ extern const char *find_in_path (const char *progname); is != PROGNAME. - - Otherwise, it returns NULL. + - Otherwise, it sets errno and returns NULL. + Specific errno values include: + - ENOENT: means that the program's file was not found. + - EACCESS: means that the program's file was found but lacks the + execute permissions. If OPTIMIZE_FOR_EXEC is true, the function saves some work, under the assumption that the resulting pathname will not be accessed directly, - only through execl/execv or execlp/execvp. */ + only through execl/execv or execlp/execvp. + + Here, a "slash" means: + - On POSIX systems excluding Cygwin: a '/', + - On Windows, OS/2, DOS platforms: a '/' or '\'. */ extern const char *find_in_given_path (const char *progname, const char *path, |