Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r--winsup/cygwin/spawn.cc51
1 files changed, 41 insertions, 10 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index ee004666b..0c6eb5cc5 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -84,21 +84,34 @@ perhaps_suffix (const char *prog, path_conv &buf)
const char * __stdcall
find_exec (const char *name, path_conv& buf, const char *mywinenv,
- int null_if_notfound, const char **known_suffix)
+ unsigned opt, const char **known_suffix)
{
const char *suffix = "";
debug_printf ("find_exec (%s)", name);
char *retval = buf;
+ char tmp[MAX_PATH];
+ const char *posix = (opt & FE_NATIVE) ? NULL : name;
+ bool has_slash = strchr (name, '/');
/* Check to see if file can be opened as is first.
Win32 systems always check . first, but PATH may not be set up to
do this. */
- if ((suffix = perhaps_suffix (name, buf)) != NULL)
- goto out;
+ if ((has_slash || opt & FE_CWD)
+ && (suffix = perhaps_suffix (name, buf)) != NULL)
+ {
+ if (posix && !has_slash)
+ {
+ tmp[0] = '.';
+ tmp[1] = '/';
+ strcpy (tmp + 2, name);
+ posix = tmp;
+ }
+ goto out;
+ }
win_env *winpath;
const char *path;
- char tmp[MAX_PATH];
+ const char *posix_path;
/* Return the error condition if this is an absolute path or if there
is no PATH to search. */
@@ -111,14 +124,17 @@ find_exec (const char *name, path_conv& buf, const char *mywinenv,
debug_printf ("%s%s", mywinenv, path);
+ posix = (opt & FE_NATIVE) ? NULL : tmp;
+ posix_path = winpath->get_posix () - 1;
/* Iterate over the specified path, looking for the file with and
without executable extensions. */
do
{
+ posix_path++;
char *eotmp = strccpy (tmp, &path, ';');
/* An empty path or '.' means the current directory, but we've
already tried that. */
- if (tmp[0] == '\0' || (tmp[0] == '.' && tmp[1] == '\0'))
+ if (opt & FE_CWD && (tmp[0] == '\0' || (tmp[0] == '.' && tmp[1] == '\0')))
continue;
*eotmp++ = '\\';
@@ -127,19 +143,32 @@ find_exec (const char *name, path_conv& buf, const char *mywinenv,
debug_printf ("trying %s", tmp);
if ((suffix = perhaps_suffix (tmp, buf)) != NULL)
- goto out;
+ {
+ if (posix == tmp)
+ {
+ eotmp = strccpy (tmp, &posix_path, ':');
+ if (eotmp == tmp)
+ *eotmp++ = '.';
+ *eotmp++ = '/';
+ strcpy (eotmp, name);
+ }
+ goto out;
+ }
}
- while (*path && *++path);
+ while (*path && *++path && (posix_path = strchr (posix_path, ':')));
errout:
+ posix = NULL;
/* Couldn't find anything in the given path.
Take the appropriate action based on null_if_not_found. */
- if (null_if_notfound)
+ if (opt & FE_NNF)
retval = NULL;
- else
+ else if (opt & FE_NATIVE)
buf.check (name);
out:
+ if (posix)
+ buf.set_path (posix);
debug_printf ("%s = find_exec (%s)", (char *) buf, name);
if (known_suffix)
*known_suffix = suffix ?: strchr (buf, '\0');
@@ -466,7 +495,9 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
if (arg1)
newargv.unshift (arg1);
- find_exec (pgm, real_path, "PATH=", 0, &ext);
+ /* FIXME: This should not be using FE_NATIVE. It should be putting
+ the posix path on the argv list. */
+ find_exec (pgm, real_path, "PATH=", FE_NATIVE, &ext);
newargv.unshift (real_path, 1);
}