bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: psmith@gnu.org
Cc: bug-gnulib@gnu.org
Subject: Re: [PATCH] findprog: Support searching in a specified path string
Date: Sat, 14 Sep 2019 13:20:24 +0200	[thread overview]
Message-ID: <9934807.lb8JWjbBxG@omega> (raw)
In-Reply-To: <0a138dd42c6e97a91ecf796a9caeb660fcf6c568.camel@gnu.org>

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  <bruno@clisp.org>

	findprog-in: Better mimic the system on native Windows.
	Reported by Paul Smith <psmith@gnu.org>.
	* 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	other threads:[~2019-09-14 11:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 23:10 [PATCH] findprog: Support searching in a specified path string Paul Smith
2019-09-06 23:21 ` Paul Smith
2019-09-07 10:42 ` Bruno Haible
2019-09-07 13:17   ` Paul Smith
2019-09-08 11:38     ` Bruno Haible
2019-09-08 14:03       ` Paul Smith
2019-09-08 14:59         ` Bruno Haible
2019-09-08 16:25           ` Bruno Haible
2019-09-08 17:34           ` Paul Smith
2019-09-08 17:48             ` Bruno Haible
2019-09-08 17:59               ` Paul Smith
2019-09-09 18:54                 ` Bruno Haible
2019-09-10 13:18                   ` Paul Smith
2019-09-14 11:20                     ` Bruno Haible [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9934807.lb8JWjbBxG@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=psmith@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).