/* Locating a program in PATH.
- Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software: you can redistribute it and/or modify
#include <string.h>
#include <unistd.h>
-#include "xalloc.h"
-#include "filename.h"
+/* Avoid collision between findprog.c and findprog-lgpl.c. */
+#if IN_FINDPROG_LGPL || ! GNULIB_FINDPROG_LGPL
+
+#if !IN_FINDPROG_LGPL
+# include "xalloc.h"
+#endif
+#include "concat-filename.h"
const char *
return progname;
/* Make a copy, to prepare for destructive modifications. */
+# if !IN_FINDPROG_LGPL
path = xstrdup (path);
+# else
+ path = strdup (path);
+ if (path == NULL)
+ /* Out of memory. */
+ return progname;
+# endif
for (path_rest = path; ; path_rest = cp + 1)
{
const char *dir;
dir = ".";
/* Concatenate dir and progname. */
+# if !IN_FINDPROG_LGPL
+ progpathname = xconcatenated_filename (dir, progname, NULL);
+# else
progpathname = concatenated_filename (dir, progname, NULL);
+ if (progpathname == NULL)
+ {
+ /* Out of memory. */
+ free (path);
+ return progname;
+ }
+# endif
/* On systems which have the eaccess() system call, let's use it.
On other systems, let's hope that this program is not installed
{
free (progpathname);
- /* Add the "./" prefix for real, that concatenated_filename()
+ /* Add the "./" prefix for real, that xconcatenated_filename()
optimized away. This avoids a second PATH search when the
caller uses execlp/execvp. */
progpathname = XNMALLOC (2 + strlen (progname) + 1, char);
return progname;
#endif
}
+
+#endif