+2020-12-10 Bruno Haible <bruno@clisp.org>
+
+ findprog-in: Don't exit upon out-of-memory.
+ * lib/findprog.h (find_in_given_path): Document ENOMEM as possible error
+ code.
+ * lib/findprog-in.c: Don't include xalloc.h.
+ (find_in_given_path): Call concatenated_filename, not
+ xconcatenated_filename. Call strdup, not xstrdup. Upon out-of-memory,
+ return NULL with errno set.
+ * modules/findprog-in (Depends-on): Remove xconcat-filename, xalloc. Add
+ concat-filename, strdup-posix, malloc-posix.
+
2020-12-09 Bruno Haible <bruno@clisp.org>
fmaf: Work around a bug on FreeBSD 12.2/arm.
#include "filename.h"
#include "concat-filename.h"
-#include "xalloc.h"
#if (defined _WIN32 && !defined __CYGWIN__) || defined __EMX__ || defined __DJGPP__
/* Native Windows, OS/2, DOS */
{
/* Concatenate progname and suffix. */
char *progpathname =
- xconcatenated_filename ("", progname, suffix);
+ concatenated_filename ("", progname, suffix);
+
+ if (progpathname == NULL)
+ return NULL; /* errno is set here */
/* On systems which have the eaccess() system call, let's
use it. On other systems, let's hope that this program
path = "";
{
- int failure_errno;
/* Make a copy, to prepare for destructive modifications. */
- char *path_copy = xstrdup (path);
+ char *path_copy = strdup (path);
+ if (path_copy == NULL)
+ return NULL; /* errno is set here */
+
+ int failure_errno;
char *path_rest;
char *cp;
{
/* Concatenate dir, progname, and suffix. */
char *progpathname =
- xconcatenated_filename (dir, progname, suffix);
+ concatenated_filename (dir, progname, suffix);
+
+ if (progpathname == NULL)
+ {
+ /* errno is set here. */
+ failure_errno = errno;
+ goto failed;
+ }
/* On systems which have the eaccess() system call, let's
use it. On other systems, let's hope that this program
This avoids a second PATH search when the
caller uses execl/execv/execlp/execvp. */
progpathname =
- XNMALLOC (2 + strlen (progname) + 1, char);
+ (char *) malloc (2 + strlen (progname) + 1);
+ if (progpathname == NULL)
+ {
+ /* errno is set here. */
+ failure_errno = errno;
+ goto failed;
+ }
progpathname[0] = '.';
progpathname[1] = NATIVE_SLASH;
memcpy (progpathname + 2, progname,
break;
}
+ failed:
/* Not found in PATH. */
free (path_copy);
- EACCES: means that the program's file cannot be accessed (due to some
issue with one of the ancestor directories) or lacks the execute
permissions.
+ - ENOMEM: means out of memory.
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.