Skip to content

Commit

Permalink
Add functionality for converting UNIX paths in arguments and environm…
Browse files Browse the repository at this point in the history
…ent variables to Windows form for native Win32 applications.
  • Loading branch information
Alexpux authored and lazka committed Aug 25, 2024
1 parent f858c02 commit b084abe
Show file tree
Hide file tree
Showing 10 changed files with 988 additions and 4 deletions.
1 change: 1 addition & 0 deletions winsup/cygwin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ DLL_FILES= \
miscfuncs.cc \
mktemp.cc \
msg.cc \
msys2_path_conv.cc \
mount.cc \
net.cc \
netdb.cc \
Expand Down
24 changes: 23 additions & 1 deletion winsup/cygwin/environ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ env_compare (const void *key, const void *memb)
to the child. */
char **
build_env (const char * const *envp, PWCHAR &envblock, int &envc,
bool no_envblock, HANDLE new_token)
bool no_envblock, HANDLE new_token, bool keep_posix)
{
PWCHAR cwinenv = NULL;
size_t winnum = 0;
Expand Down Expand Up @@ -1139,6 +1139,19 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
for (srcp = envp, dstp = newenv, pass_dstp = pass_env; *srcp; srcp++)
{
bool calc_tl = !no_envblock;
#ifdef __MSYS__
/* Don't pass timezone environment to non-msys applications */
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
{
const char *v = *srcp + 3;
if (*v == ':')
goto next1;
for (; *v; v++)
if (!isalpha(*v) && !isdigit(*v) &&
*v != '-' && *v != '+' && *v != ':')
goto next1;
}
#endif
/* Look for entries that require special attention */
for (unsigned i = 0; i < SPENVS_SIZE; i++)
if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
Expand Down Expand Up @@ -1259,6 +1272,15 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
saw_PATH = true;
}
}
#ifdef __MSYS__
else if (!keep_posix) {
char *win_arg = arg_heuristic(*srcp);
debug_printf("WIN32_PATH is %s", win_arg);
p = cstrdup1(win_arg);
if (win_arg != *srcp)
free (win_arg);
}
#endif
else
p = *srcp; /* Don't worry about it */

Expand Down
2 changes: 1 addition & 1 deletion winsup/cygwin/external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ create_winenv (const char * const *env)
int unused_envc;
PWCHAR envblock = NULL;
char **envp = build_env (env ?: environ, envblock, unused_envc, false,
NULL);
NULL, true);
PWCHAR p = envblock;

if (envp)
Expand Down
6 changes: 6 additions & 0 deletions winsup/cygwin/include/sys/cygwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ extern ssize_t cygwin_conv_path_list (cygwin_conv_path_t what, const void *from,
to one of the above values, or to ENOMEM if malloc fails. */
extern void *cygwin_create_path (cygwin_conv_path_t what, const void *from);

extern char * arg_heuristic_with_exclusions (char const * const arg,
char const * exclusions,
size_t exclusions_count);

extern char * arg_heuristic (char const * const);

extern pid_t cygwin_winpid_to_pid (int);
extern int cygwin_posix_path_list_p (const char *);
extern void cygwin_split_path (const char *, char *, char *);
Expand Down
2 changes: 1 addition & 1 deletion winsup/cygwin/local_includes/environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ win_env *getwinenv (const char *name, const char *posix = NULL, win_env * = NULL
char *getwinenveq (const char *name, size_t len, int);

char **build_env (const char * const *envp, PWCHAR &envblock,
int &envc, bool need_envblock, HANDLE new_token);
int &envc, bool need_envblock, HANDLE new_token, bool keep_posix);

char **win32env_to_cygenv (PWCHAR rawenv, bool posify);

Expand Down
4 changes: 4 additions & 0 deletions winsup/cygwin/local_includes/winf.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class av
calloced = 1;
}
}
void replace (int i, const char *arg)
{
argv[i] = cstrdup1 (arg);
}
void dup_all ()
{
for (int i = calloced; i < argc; i++)
Expand Down
Loading

0 comments on commit b084abe

Please sign in to comment.