public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: spawn: Treat empty path as the current directory.
@ 2022-06-27 12:44 Takashi Yano
  2022-06-30 15:45 ` Ken Brown
  0 siblings, 1 reply; 11+ messages in thread
From: Takashi Yano @ 2022-06-27 12:44 UTC (permalink / raw)
  To: cygwin-patches

- With this patch, the empty path (empty element in PATH or PATH is
  absent) is treated as the current directory as Linux does.
Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251730.html
---
 winsup/cygwin/release/3.3.6 |  4 ++++
 winsup/cygwin/spawn.cc      | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/release/3.3.6 b/winsup/cygwin/release/3.3.6
index f1a4b7812..ad4069568 100644
--- a/winsup/cygwin/release/3.3.6
+++ b/winsup/cygwin/release/3.3.6
@@ -22,3 +22,7 @@ Bug Fixes
   if events are inquired in multiple pollfd entries on the same fd
   at the same time.
   Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251732.html
+
+- Treat an empty path (empty element in PATH or PATH is absent) as
+  the current directory as Linux does.
+  Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251730.html
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index e0f1247e1..292cd5a42 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -95,6 +95,7 @@ find_exec (const char *name, path_conv& buf, const char *search,
   char *tmp = tp.c_get ();
   bool has_slash = !!strpbrk (name, "/\\");
   int err = 0;
+  bool eopath = false;
 
   debug_printf ("find_exec (%s)", name);
 
@@ -118,8 +119,10 @@ find_exec (const char *name, path_conv& buf, const char *search,
      the name of an environment variable. */
   if (strchr (search, '/'))
     *stpncpy (tmp, search, NT_MAX_PATH - 1) = '\0';
-  else if (has_slash || isdrive (name) || !(path = getenv (search)) || !*path)
+  else if (has_slash || isdrive (name))
     goto errout;
+  else if (!(path = getenv (search)) || !*path)
+    strcpy (tmp, "."); /* Search the current directory when PATH is absent */
   else
     *stpncpy (tmp, path, NT_MAX_PATH - 1) = '\0';
 
@@ -130,11 +133,17 @@ find_exec (const char *name, path_conv& buf, const char *search,
   do
     {
       char *eotmp = strccpy (tmp_path, &path, ':');
+      if (*path)
+	path++;
+      else
+	eopath = true;
       /* An empty path or '.' means the current directory, but we've
 	 already tried that.  */
       if ((opt & FE_CWD) && (tmp_path[0] == '\0'
 			     || (tmp_path[0] == '.' && tmp_path[1] == '\0')))
 	continue;
+      else if (tmp_path[0] == '\0') /* An empty path means the current dir. */
+	eotmp = stpcpy (tmp_path, ".");
 
       *eotmp++ = '/';
       stpcpy (eotmp, name);
@@ -155,7 +164,7 @@ find_exec (const char *name, path_conv& buf, const char *search,
 	}
 
     }
-  while (*path && *++path);
+  while (!eopath);
 
  errout:
   /* Couldn't find anything in the given path.
-- 
2.36.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-07-05  4:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 12:44 [PATCH] Cygwin: spawn: Treat empty path as the current directory Takashi Yano
2022-06-30 15:45 ` Ken Brown
2022-06-30 18:35   ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2022-06-30 19:03     ` Brian Inglis
2022-06-30 19:04     ` Takashi Yano
2022-07-01  1:16   ` Ken Brown
2022-07-01 23:31     ` Takashi Yano
2022-07-02  1:32       ` Ken Brown
2022-07-04  8:37         ` Corinna Vinschen
2022-07-04 23:05           ` Ken Brown
2022-07-05  4:54             ` Takashi Yano

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).