bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] findprog: Support searching in a specified path string


From: Bruno Haible
Subject: Re: [PATCH] findprog: Support searching in a specified path string
Date: Sat, 14 Sep 2019 13:20:24 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-159-generic; KDE/5.18.0; x86_64; ; )

Hi Paul,

> note that
> on Windows, which is the only place this matters, so far,  IIRC it is
> illegal to use "prog.exe.exe" so if an extension is already provided
> the system won't search again

Indeed, the native Windows execlp() function behaves like this:
  - If the caller specifies "prog.exe.exe" or "prog.foo.exe" and
    that file will be exists, it will be found and executed.
  - If the caller specifies "prog.exe" or "prog.foo" but that file
    does not exist, the search will NOT extend to "prog.exe.exe" or
    "prog.foo.exe", respectively.

I'm updating the code (patch below).

> I actually don't see any need for this optimization, especially
> compared to the added complexity of the API and docs: the suffix check
> needs to be done somewhere after all.

But on platforms like Cygwin, it would be done twice.


2019-09-14  Bruno Haible  <address@hidden>

        findprog-in: Better mimic the system on native Windows.
        Reported by Paul Smith <address@hidden>.
        * lib/findprog-in.c (find_in_given_path): On native Windows, don't try
        non-empty suffixes when the file name already contains a '.'.

diff --git a/lib/findprog-in.c b/lib/findprog-in.c
index 99b3c31..d601e06 100644
--- a/lib/findprog-in.c
+++ b/lib/findprog-in.c
@@ -118,8 +118,9 @@ find_in_given_path (const char *progname, const char *path,
                 const char *suffix = suffixes[i];
 
                 #if defined _WIN32 && !defined __CYGWIN__ /* Native Windows */
-                /* File names without a '.' are not considered executable.  */
-                if (*suffix != '\0' || strchr (progbasename, '.') != NULL)
+                /* File names without a '.' are not considered executable, and
+                   for file names with a '.' no additional suffix is tried.  */
+                if ((*suffix != '\0') != (strchr (progbasename, '.') != NULL))
                 #endif
                   {
                     /* Concatenate progname and suffix.  */
@@ -185,8 +186,9 @@ find_in_given_path (const char *progname, const char *path,
             const char *suffix = suffixes[i];
 
             #if defined _WIN32 && !defined __CYGWIN__ /* Native Windows */
-            /* File names without a '.' are not considered executable.  */
-            if (*suffix != '\0' || strchr (progname, '.') != NULL)
+            /* File names without a '.' are not considered executable, and
+               for file names with a '.' no additional suffix is tried.  */
+            if ((*suffix != '\0') != (strchr (progname, '.') != NULL))
             #endif
               {
                 /* Concatenate dir, progname, and suffix.  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]