summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2019-09-15 19:47:43 +0200
committerBruno Haible <bruno@clisp.org>2019-09-15 19:47:43 +0200
commit6e9634163167de7f153cdfd1023e5c164485f4bc (patch)
tree940c2bce61848bb503c80ddf6c947a30aab5a1cc
parentccfbc26dce79adcb32bf421ff813247699d70ea5 (diff)
downloadgnulib-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--ChangeLog9
-rw-r--r--lib/findprog-in.c17
-rw-r--r--lib/findprog.h14
3 files changed, 36 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d2eb3aa93..9037573187 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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,

Return to:

Send suggestions and report system problems to the System administrator.