From: Bruno Haible Date: Thu, 10 Apr 2003 20:13:43 +0000 (+0000) Subject: Modernizations suggested by Paul Eggert. X-Git-Tag: v0.12~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f482268489ffb36081c889bfe1d8d38e3c1430e;p=thirdparty%2Fgettext.git Modernizations suggested by Paul Eggert. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 0f98a8c85..a994881e2 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-04-10 Bruno Haible + + * findprog.c (find_in_path): Use 'bool' and eaccess(). + Suggested by Paul Eggert. + 2003-04-06 Bruno Haible * progname.c: Move out all methods depending on ENABLE_RELOCATABLE... diff --git a/gettext-tools/lib/findprog.c b/gettext-tools/lib/findprog.c index af0a40573..b820a8303 100644 --- a/gettext-tools/lib/findprog.c +++ b/gettext-tools/lib/findprog.c @@ -1,5 +1,5 @@ /* Locating a program in PATH. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ /* Specification. */ #include "findprog.h" +#include #include #include @@ -64,11 +65,12 @@ find_in_path (const char *progname) path = xstrdup (path); for (dir = path; ; dir = cp + 1) { - int last; + bool last; char *progpathname; /* Extract next directory in PATH. */ - for (cp = dir; *cp != '\0' && *cp != ':'; cp++); + for (cp = dir; *cp != '\0' && *cp != ':'; cp++) + ; last = (*cp == '\0'); *cp = '\0'; @@ -79,9 +81,11 @@ find_in_path (const char *progname) /* Concatenate dir and progname. */ progpathname = concatenated_pathname (dir, progname, NULL); - /* This program is usually not installed setuid or setgid, therefore - it is ok to call access() despite its design flaw. */ - if (access (progpathname, X_OK) == 0) + /* On systems which have the eaccess() system call, let's use it. + On other systems, let's hope that this program is not installed + setuid or setgid, so that it is ok to call access() despite its + design flaw. */ + if (eaccess (progpathname, X_OK) == 0) { /* Found! */ if (strcmp (progpathname, progname) == 0) @@ -89,7 +93,8 @@ find_in_path (const char *progname) free (progpathname); /* Add the "./" prefix for real, that concatenated_pathname() - optimized away. */ + optimized away. This avoids a second PATH search when the + caller uses execlp/execvp. */ progpathname = xmalloc (2 + strlen (progname) + 1); progpathname[0] = '.'; progpathname[1] = '/'; diff --git a/gettext-tools/lib/findprog.h b/gettext-tools/lib/findprog.h index 713f028ad..81a95b6dc 100644 --- a/gettext-tools/lib/findprog.h +++ b/gettext-tools/lib/findprog.h @@ -1,5 +1,5 @@ /* Locating a program in PATH. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -20,5 +20,8 @@ Attempt to determine the pathname that would be called by execlp/execvp of PROGNAME. If successful, return a pathname containing a slash (either absolute or relative to the current directory). Otherwise, - return PROGNAME unmodified. */ + return PROGNAME unmodified. + Because of the latter case, callers should use execlp/execvp, not + execl/execv on the returned pathname. + The returned string is freshly malloc()ed if it is != PROGNAME. */ extern const char *find_in_path (const char *progname);