public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: spawn: Treat empty path as the current directory. Date: Tue, 5 Jul 2022 04:50:45 +0000 (GMT) [thread overview] Message-ID: <20220705045045.29046385828E@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fc74dbf22f5c72f023713e7bb8c934ce34589163 commit fc74dbf22f5c72f023713e7bb8c934ce34589163 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Mon Jun 27 21:34:01 2022 +0900 Cygwin: spawn: Treat empty path as the current directory. - With this patch, the empty path (empty element in PATH or PATH is absent) is treated as the current directory as Linux does. This feature is added for Linux compatibility, but it is deprecated. POSIX notes that a conforming application shall use an explicit pathname to specify the current working directory. Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251730.html Diff: --- winsup/cygwin/release/3.4.0 | 4 ++++ winsup/cygwin/spawn.cc | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/release/3.4.0 b/winsup/cygwin/release/3.4.0 index 31b36dcfd..f310912c9 100644 --- a/winsup/cygwin/release/3.4.0 +++ b/winsup/cygwin/release/3.4.0 @@ -21,6 +21,10 @@ What changed: This aligns Cygwin behavior to that of Linux. Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251672.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 + Bug Fixes --------- diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 8e700354a..277f0d1b3 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,14 @@ 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; + /* Search the current directory when PATH is absent. This feature is + added for Linux compatibility, but it is deprecated. POSIX notes + that a conforming application shall use an explicit path name to + specify the current working directory. */ + else if (!(path = getenv (search)) || !*path) + strcpy (tmp, "."); else *stpncpy (tmp, path, NT_MAX_PATH - 1) = '\0'; @@ -130,11 +137,21 @@ 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; + /* An empty path means the current directory. This feature is + added for Linux compatibility, but it is deprecated. POSIX + notes that a conforming application shall use an explicit + pathname to specify the current working directory. */ + else if (tmp_path[0] == '\0') + eotmp = stpcpy (tmp_path, "."); *eotmp++ = '/'; stpcpy (eotmp, name); @@ -155,7 +172,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.
reply other threads:[~2022-07-05 4:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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 * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220705045045.29046385828E@sourceware.org \ --to=tyan0@sourceware.org \ --cc=cygwin-cvs@sourceware.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: linkBe 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).