X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffindprog.c;h=b064245a3ec5652473e9a42f964796e1c2cfe42a;hb=6a9b156fdf9c71c0bbc8bb0b3aa0262df5674dda;hp=3b8cd39bcda9de7359c4faa9c8e5df459a279c68;hpb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;p=gnulib.git diff --git a/lib/findprog.c b/lib/findprog.c index 3b8cd39bc..b064245a3 100644 --- a/lib/findprog.c +++ b/lib/findprog.c @@ -1,5 +1,5 @@ /* 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 , 2001. This program is free software: you can redistribute it and/or modify @@ -26,8 +26,13 @@ #include #include -#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 * @@ -56,7 +61,14 @@ find_in_path (const char *progname) 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; @@ -75,7 +87,17 @@ find_in_path (const char *progname) 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 @@ -88,7 +110,7 @@ find_in_path (const char *progname) { 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); @@ -112,3 +134,5 @@ find_in_path (const char *progname) return progname; #endif } + +#endif