diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2008-03-12 12:41:50 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2008-03-12 12:41:50 +0000 |
commit | edab6053a24d49f3443fbfdbac2c330caf50b030 (patch) | |
tree | d1b6a47a9305a66c02b67ce3a57e8005cec93f13 /winsup/cygwin/environ.cc | |
parent | 674310fb403f78ecf8fab1bcfdb169cf7ff95390 (diff) | |
download | newlib-edab6053a24d49f3443fbfdbac2c330caf50b030.zip newlib-edab6053a24d49f3443fbfdbac2c330caf50b030.tar.gz newlib-edab6053a24d49f3443fbfdbac2c330caf50b030.tar.bz2 |
* winsup.h (NT_MAX_PATH): Revert ill-advised change to 32767.
Accommodate change throughout.
* cygwin.din (cygwin_conv_path): Export.
(cygwin_conv_path_list): Export.
(cygwin_create_path): Export.
* dcrt0.cc (dll_crt0_1): Use cygwin_conv_path.
* dtable.cc (handle_to_fn): Ditto. Don't expect UNICODE_STRING being
0-terminated.
* environ.cc (env_plist_to_posix): New helper function.
(env_plist_to_win32): Ditto.
(env_path_to_posix): Ditto.
(env_path_to_win32): Ditto.
(return_MAX_PATH): Remove.
(conv_envvars): Use new helper functions. Drop removed members.
(win_env::operator =): Accommodate removal of path length functions.
(win_env::add_cache): Accommodate new env helper function API.
(posify): Ditto.
* environ.h (struct win_env): Ditto. Remove path length function
pointers since they are unused.
* path.cc (warn_msdos): Use cygwin_conv_path.
(getfileattr): Use new tmp_pathbuf::u_get method.
(fillout_mntent): Ditto.
(symlink_info::check): Ditto.
(path_conv::check): Use sizeof (WCHAR) instead of constant 2.
(symlink_info::check_reparse_point): Ditto.
(conv_path_list): Get max size of target string as argument. Call
cygwin_conv_path as helper function.
(cygwin_conv_path): New function.
(cygwin_create_path): New function.
(cygwin_conv_to_win32_path): Just call cygwin_conv_path with size set
to MAX_PATH.
(cygwin_conv_to_full_win32_path): Ditto.
(cygwin_conv_to_posix_path): Ditto.
(cygwin_conv_to_full_posix_path): Ditto.
(conv_path_list_buf_size): Add FIXME comment.
(env_PATH_to_posix): Rename from env_win32_to_posix_path_list.
Add size argument as required for env helper functions.
(cygwin_win32_to_posix_path_list): Call conv_path_list with size set to
MAX_PATH.
(cygwin_posix_to_win32_path_list): Ditto.
(cygwin_conv_path_list): New function.
(cwdstuff::get): Fix length argument in call to sys_wcstombs.
* spawn.cc (find_exec): Use cygwin_conv_path_list.
* tls_pbuf.h (tmp_pathbuf::u_get: New method.
* uinfo.cc (cygheap_user::ontherange): Allocate temporary path buffers
using tmp_pathbuf. Use cygwin_conv_path.
* winf.cc (av::unshift): Use cygwin_conv_path.
* include/cygwin/version.h: Bump API minor number.
* include/sys/cygwin.h: Comment out old cygwin32_XXX API.
Mark old path handling API as deprecated.
(cygwin_conv_path_t): Typedef. Define values.
(cygwin_conv_path): Declare.
(cygwin_create_path): Declare.
(cygwin_conv_path_list): Declare.
Diffstat (limited to 'winsup/cygwin/environ.cc')
-rw-r--r-- | winsup/cygwin/environ.cc | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index 76c6820..514aa5c 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -47,7 +47,37 @@ extern bool allow_server; static char **lastenviron; -extern "C" int env_win32_to_posix_path_list (const char *, char *posix); +/* Helper functions for the below environment variables which have to + be converted Win32<->POSIX. */ +extern "C" ssize_t env_PATH_to_posix (const void *, void *, size_t); + +ssize_t +env_plist_to_posix (const void *win32, void *posix, size_t size) +{ + return cygwin_conv_path_list (CCP_WIN_A_TO_POSIX | CCP_RELATIVE, win32, + posix, size); +} + +ssize_t +env_plist_to_win32 (const void *posix, void *win32, size_t size) +{ + return cygwin_conv_path_list (CCP_POSIX_TO_WIN_A | CCP_RELATIVE, posix, + win32, size); +} + +ssize_t +env_path_to_posix (const void *win32, void *posix, size_t size) +{ + return cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, win32, + posix, size); +} + +ssize_t +env_path_to_win32 (const void *posix, void *win32, size_t size) +{ + return cygwin_conv_path (CCP_POSIX_TO_WIN_A | CCP_ABSOLUTE, posix, + win32, size); +} #define ENVMALLOC \ (CYGWIN_VERSION_DLL_MAKE_COMBINED (user_data->api_major, user_data->api_minor) \ @@ -60,26 +90,16 @@ extern "C" int env_win32_to_posix_path_list (const char *, char *posix); PATH needs to be here because CreateProcess uses it and gdb uses CreateProcess. HOME is here because most shells use it and would be confused by Windows style path names. */ -static int return_MAX_PATH (const char *) {return CYG_MAX_PATH;} static win_env conv_envvars[] = { - {NL ("PATH="), NULL, NULL, env_win32_to_posix_path_list, - cygwin_posix_to_win32_path_list, - cygwin_win32_to_posix_path_list_buf_size, - cygwin_posix_to_win32_path_list_buf_size, true}, - {NL ("HOME="), NULL, NULL, cygwin_conv_to_full_posix_path, - cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH, false}, - {NL ("LD_LIBRARY_PATH="), NULL, NULL, cygwin_win32_to_posix_path_list, - cygwin_posix_to_win32_path_list, - cygwin_win32_to_posix_path_list_buf_size, - cygwin_posix_to_win32_path_list_buf_size, true}, - {NL ("TMPDIR="), NULL, NULL, cygwin_conv_to_full_posix_path, - cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH, false}, - {NL ("TMP="), NULL, NULL, cygwin_conv_to_full_posix_path, - cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH, false}, - {NL ("TEMP="), NULL, NULL, cygwin_conv_to_full_posix_path, - cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH, false}, - {NULL, 0, NULL, NULL, NULL, NULL, 0, 0} + {NL ("PATH="), NULL, NULL, env_PATH_to_posix, env_plist_to_win32, true}, + {NL ("HOME="), NULL, NULL, env_path_to_posix, env_path_to_win32, false}, + {NL ("LD_LIBRARY_PATH="), NULL, NULL, + env_plist_to_posix, env_plist_to_win32, true}, + {NL ("TMPDIR="), NULL, NULL, env_path_to_posix, env_path_to_win32, false}, + {NL ("TMP="), NULL, NULL, env_path_to_posix, env_path_to_win32, false}, + {NL ("TEMP="), NULL, NULL, env_path_to_posix, env_path_to_win32, false}, + {NULL, 0, NULL, NULL, 0, 0} }; static unsigned char conv_start_chars[256] = {0}; @@ -91,8 +111,6 @@ win_env::operator = (struct win_env& x) namelen = x.namelen; toposix = x.toposix; towin32 = x.towin32; - posix_len = x.posix_len; - win32_len = x.win32_len; immediate = false; return *this; } @@ -122,7 +140,7 @@ win_env::add_cache (const char *in_posix, const char *in_native) tmp_pathbuf tp; char *buf = tp.c_get (); strcpy (buf, name + namelen); - towin32 (in_posix, buf); + towin32 (in_posix, buf, NT_MAX_PATH); native = (char *) realloc (native, namelen + 1 + strlen (buf)); strcpy (native, name); strcpy (native + namelen, buf); @@ -191,14 +209,15 @@ posify (char **here, const char *value, char *outenv) memcpy (outenv, src, len); char *newvalue = outenv + len; - if (!conv->toposix (value, newvalue) || _impure_ptr->_errno != EIDRM) + if (!conv->toposix (value, newvalue, NT_MAX_PATH - len) + || _impure_ptr->_errno != EIDRM) conv->add_cache (newvalue, *value != '/' ? value : NULL); else { /* The conversion routine removed elements from a path list so we have to recalculate the windows path to remove elements there, too. */ char cleanvalue[strlen (value) + 1]; - conv->towin32 (newvalue, cleanvalue); + conv->towin32 (newvalue, cleanvalue, sizeof cleanvalue); conv->add_cache (newvalue, cleanvalue); } |