]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Modernizations suggested by Paul Eggert.
authorBruno Haible <bruno@clisp.org>
Thu, 10 Apr 2003 20:13:43 +0000 (20:13 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:22 +0000 (12:10 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/lib/findprog.c
gettext-tools/lib/findprog.h

index 0f98a8c85c1eb51ef4435394f759a81bb0ca5b53..a994881e25f5e966185343068ced0530daf18ed1 100644 (file)
@@ -1,3 +1,8 @@
+2003-04-10  Bruno Haible  <bruno@clisp.org>
+
+       * findprog.c (find_in_path): Use 'bool' and eaccess().
+       Suggested by Paul Eggert.
+
 2003-04-06  Bruno Haible  <bruno@clisp.org>
 
        * progname.c: Move out all methods depending on ENABLE_RELOCATABLE...
index af0a40573a56c5474243ea893430aaebce8bc489..b820a83036e5ee23c8be2bcf689acde1c3c11696 100644 (file)
@@ -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 <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@
 /* Specification.  */
 #include "findprog.h"
 
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -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] = '/';
index 713f028add1571d2f91ad985e8bebfac77626d7f..81a95b6dc49c1b20151ba0c4301d4fe8d2e55dda 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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);