* thread.h: Shorten "current_directory" variables to "cwd_*" throughout.

* path.cc: Ditto.
(normalize_posix_path): Add some extra debugging info.
(chdir): Ditto.  Store chdir'ed posix and MS-DOS directory names in "cache"
here rather than trying to derive them later.
This commit is contained in:
Christopher Faylor 2000-06-13 04:40:36 +00:00
parent a50b13da06
commit 00660f0110
3 changed files with 69 additions and 62 deletions

View File

@ -1,12 +1,21 @@
Tue Jun 13 00:17:04 2000 Christopher Faylor <cgf@cygnus.com>
* thread.h: Shorten "current_directory" variables to "cwd_*"
throughout.
* path.cc: Ditto.
(normalize_posix_path): Add some extra debugging info.
(chdir): Ditto. Store chdir'ed posix and MS-DOS directory names in
"cache" here rather than trying to derive them later.
Sun Jun 11 15:57:00 2000 Corinna Vinschen <corinna@vinschen.de> Sun Jun 11 15:57:00 2000 Corinna Vinschen <corinna@vinschen.de>
* fhandler_random.cc (read): Call CryptAquireContext with * fhandler_random.cc (read): Call CryptAquireContext with
CRYPT_VERIFYCONTEXT. CRYPT_VERIFYCONTEXT.
Thu Jun 8 22:49:00 2000 Corinna Vinschen <corinna@vinschen.de> Thu Jun 8 22:49:00 2000 Corinna Vinschen <corinna@vinschen.de>
* path.cc (path_conv::check): Erase two lines checked in * path.cc (path_conv::check): Erase two lines checked in
by mistake. by mistake.
Thu Jun 8 15:53:00 2000 Corinna Vinschen <corinna@vinschen.de> Thu Jun 8 15:53:00 2000 Corinna Vinschen <corinna@vinschen.de>
@ -15,21 +24,21 @@ Thu Jun 8 15:53:00 2000 Corinna Vinschen <corinna@vinschen.de>
2000-06-07 Kazuhiro Fujieda <fujieda@jaist.ac.jp> 2000-06-07 Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* path.cc (mount_info::init): Eliminate the mount_slash feature. * path.cc (mount_info::init): Eliminate the mount_slash feature.
(mount_slash): Eliminated. (mount_slash): Eliminated.
(mount_info::read_mounts): Eliminate looking up existing entries. The (mount_info::read_mounts): Eliminate looking up existing entries. The
loop for deleting cygpath entries is done only when such entries exist. loop for deleting cygpath entries is done only when such entries exist.
(mount_info::from_registry): Eliminate sorting. (mount_info::from_registry): Eliminate sorting.
(mount_info::add_item): Call add_reg_mount if necessary. Check nmounts (mount_info::add_item): Call add_reg_mount if necessary. Check nmounts
more precisely. Use strcasematch in looking up existing entries. more precisely. Use strcasematch in looking up existing entries.
(mount_info::del_item): Call del_reg_mount if necessary. Use (mount_info::del_item): Call del_reg_mount if necessary. Use
strcasematch. Use memmove instead of memcpy. strcasematch. Use memmove instead of memcpy.
(mount_info::import_v1_registry): Everything is done in this method. (mount_info::import_v1_registry): Everything is done in this method.
(mount_info::to_registry): Eliminated. (mount_info::to_registry): Eliminated.
(mount_info::from_v1_registry): Eliminated. (mount_info::from_v1_registry): Eliminated.
(cygwin_umount): Simply call del_item. (cygwin_umount): Simply call del_item.
* shared.h: Modify the declaration of add_item and del_item. Remove the * shared.h: Modify the declaration of add_item and del_item. Remove the
declaration of from_v1_registry. declaration of from_v1_registry.
Wed Jun 7 23:56:10 2000 Christopher Faylor <cgf@cygnus.com> Wed Jun 7 23:56:10 2000 Christopher Faylor <cgf@cygnus.com>

View File

@ -87,7 +87,7 @@ static char *getcwd_inner (char *buf, size_t ulen, int posix_p);
static void slashify (const char *src, char *dst, int trailing_slash_p); static void slashify (const char *src, char *dst, int trailing_slash_p);
static void backslashify (const char *src, char *dst, int trailing_slash_p); static void backslashify (const char *src, char *dst, int trailing_slash_p);
static int path_prefix_p_ (const char *path1, const char *path2, int len1); static int path_prefix_p_ (const char *path1, const char *path2, int len1);
static int get_current_directory_name (); static int get_cwd_win32 ();
static NO_COPY const char escape_char = '^'; static NO_COPY const char escape_char = '^';
@ -143,13 +143,13 @@ struct symlink_info
support multiple threads. */ support multiple threads. */
#ifdef _MT_SAFE #ifdef _MT_SAFE
#define current_directory_name _reent_winsup()->_current_directory_name #define cwd_win32 _reent_winsup()->_cwd_win32
#define current_directory_posix_name _reent_winsup()->_current_directory_posix_name #define cwd_posix _reent_winsup()->_cwd_posix
#define current_directory_hash _reent_winsup()->_current_directory_hash #define cwd_hash _reent_winsup()->_cwd_hash
#else #else
static char *current_directory_name; static char *cwd_win32;
static char *current_directory_posix_name; static char *cwd_posix;
static unsigned long current_directory_hash; static unsigned long cwd_hash;
#endif #endif
static int static int
@ -555,6 +555,7 @@ normalize_posix_path (const char *cwd, const char *src, char *dst)
const char *src_start = src; const char *src_start = src;
char *dst_start = dst; char *dst_start = dst;
syscall_printf ("cwd %s, src %s", cwd, src);
if (!isslash (src[0])) if (!isslash (src[0]))
{ {
if (strlen (cwd) + 1 + strlen (src) >= MAX_PATH) if (strlen (cwd) + 1 + strlen (src) >= MAX_PATH)
@ -873,7 +874,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *win32_path,
unsigned *flags) unsigned *flags)
{ {
int src_path_len = strlen (src_path); int src_path_len = strlen (src_path);
int trailing_slash_p = (src_path_len > 0 int trailing_slash_p = (src_path_len > 1
&& SLASH_P (src_path[src_path_len - 1])); && SLASH_P (src_path[src_path_len - 1]));
MALLOC_CHECK; MALLOC_CHECK;
int isrelpath; int isrelpath;
@ -916,7 +917,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *win32_path,
if (strpbrk (src_path, ":\\") != NULL) if (strpbrk (src_path, ":\\") != NULL)
{ {
debug_printf ("%s already win32", src_path); debug_printf ("%s already win32", src_path);
rc = normalize_win32_path (current_directory_name, src_path, dst); rc = normalize_win32_path (cwd_win32, src_path, dst);
if (rc) if (rc)
{ {
debug_printf ("normalize_win32_path failed, rc %d", rc); debug_printf ("normalize_win32_path failed, rc %d", rc);
@ -1020,8 +1021,7 @@ fillin:
if (win32_path == NULL) if (win32_path == NULL)
/* nothing to do */; /* nothing to do */;
else if (isrelpath && else if (isrelpath &&
path_prefix_p (current_directory_name, dst, path_prefix_p (cwd_win32, dst, cwdlen = strlen (cwd_win32)))
cwdlen = strlen (current_directory_name)))
{ {
size_t n = strlen (dst); size_t n = strlen (dst);
if (n < cwdlen) if (n < cwdlen)
@ -1031,7 +1031,7 @@ fillin:
if (n == cwdlen) if (n == cwdlen)
dst += cwdlen; dst += cwdlen;
else else
dst += isdirsep (current_directory_name[cwdlen - 1]) ? cwdlen : cwdlen + 1; dst += isdirsep (cwd_win32[cwdlen - 1]) ? cwdlen : cwdlen + 1;
memmove (win32_path, dst, strlen (dst) + 1); memmove (win32_path, dst, strlen (dst) + 1);
if (!*win32_path) if (!*win32_path)
@ -2279,10 +2279,10 @@ hash_path_name (unsigned long hash, const char *name)
Otherwise the inodes same will differ depending on whether a file is Otherwise the inodes same will differ depending on whether a file is
referenced with an absolute value or relatively. */ referenced with an absolute value or relatively. */
if (*name != '\\' && (current_directory_name == NULL || if (*name != '\\' && (cwd_win32 == NULL ||
get_current_directory_name ())) get_cwd_win32 ()))
{ {
hash = current_directory_hash; hash = cwd_hash;
if (name[0] == '.' && name[1] == '\0') if (name[0] == '.' && name[1] == '\0')
return hash; return hash;
hash = hash_path_name (hash, "\\"); hash = hash_path_name (hash, "\\");
@ -2303,21 +2303,21 @@ hashit:
} }
static int static int
get_current_directory_name () get_cwd_win32 ()
{ {
DWORD dlen, len; DWORD dlen, len;
for (dlen = 256; ; dlen *= 2) for (dlen = 256; ; dlen *= 2)
{ {
current_directory_name = (char *) realloc (current_directory_name, dlen + 2); cwd_win32 = (char *) realloc (cwd_win32, dlen + 2);
if ((len = GetCurrentDirectoryA (dlen, current_directory_name)) < dlen) if ((len = GetCurrentDirectoryA (dlen, cwd_win32)) < dlen)
break; break;
} }
if (len == 0) if (len == 0)
__seterrno (); __seterrno ();
else else
current_directory_hash = hash_path_name (0, current_directory_name); cwd_hash = hash_path_name (0, cwd_win32);
return len; return len;
} }
@ -2330,16 +2330,16 @@ getcwd_inner (char *buf, size_t ulen, int posix_p)
char *resbuf = NULL; char *resbuf = NULL;
size_t len = ulen; size_t len = ulen;
if (current_directory_name == NULL && !get_current_directory_name ()) if (cwd_win32 == NULL && !get_cwd_win32 ())
return NULL; return NULL;
if (!posix_p) if (!posix_p)
{ {
if (strlen (current_directory_name) >= len) if (strlen (cwd_win32) >= len)
set_errno (ERANGE); set_errno (ERANGE);
else else
{ {
strcpy (buf, current_directory_name); strcpy (buf, cwd_win32);
resbuf = buf; resbuf = buf;
} }
@ -2347,13 +2347,13 @@ getcwd_inner (char *buf, size_t ulen, int posix_p)
resbuf, resbuf ? resbuf : "", buf, len); resbuf, resbuf ? resbuf : "", buf, len);
return resbuf; return resbuf;
} }
else if (current_directory_posix_name != NULL) else if (cwd_posix != NULL)
{ {
if (strlen (current_directory_posix_name) >= len) if (strlen (cwd_posix) >= len)
set_errno (ERANGE); set_errno (ERANGE);
else else
{ {
strcpy (buf, current_directory_posix_name); strcpy (buf, cwd_posix);
resbuf = buf; resbuf = buf;
} }
@ -2362,19 +2362,19 @@ getcwd_inner (char *buf, size_t ulen, int posix_p)
return resbuf; return resbuf;
} }
/* posix_p required and current_directory_posix_name == NULL */ /* posix_p required and cwd_posix == NULL */
char temp[MAX_PATH]; char temp[MAX_PATH];
/* Turn from Win32 style to our style. */ /* Turn from Win32 style to our style. */
cygwin_shared->mount.conv_to_posix_path (current_directory_name, temp, 0); cygwin_shared->mount.conv_to_posix_path (cwd_win32, temp, 0);
size_t tlen = strlen (temp); size_t tlen = strlen (temp);
current_directory_posix_name = (char *) realloc ( cwd_posix = (char *) realloc (
current_directory_posix_name, tlen + 1); cwd_posix, tlen + 1);
if (current_directory_posix_name != NULL) if (cwd_posix != NULL)
strcpy (current_directory_posix_name, temp); strcpy (cwd_posix, temp);
if (tlen >= ulen) if (tlen >= ulen)
{ {
@ -2425,6 +2425,7 @@ extern "C"
int int
chdir (const char *dir) chdir (const char *dir)
{ {
syscall_printf ("dir %s", dir);
path_conv path (dir); path_conv path (dir);
if (path.error) if (path.error)
@ -2450,18 +2451,15 @@ chdir (const char *dir)
__seterrno (); __seterrno ();
/* Clear the cache until we need to retrieve the directory again. */ /* Clear the cache until we need to retrieve the directory again. */
if (current_directory_name != NULL) free (cwd_win32);
{ cwd_win32 = strdup (path);;
free (current_directory_name);
current_directory_name = NULL;
}
if (current_directory_posix_name != NULL)
{
free (current_directory_posix_name);
current_directory_posix_name = NULL;
}
syscall_printf ("%d = chdir (%s) (dos %s)", res, dir, native_dir); char pathbuf[MAX_PATH];
(void) normalize_posix_path (cwd_posix, dir, pathbuf);
free (cwd_posix);
cwd_posix = strdup (pathbuf);
syscall_printf ("%d = chdir (%s <dos %s>)", res, cwd_posix, cwd_win32);
return res; return res;
} }

View File

@ -75,9 +75,9 @@ struct _winsup_t
/* path.cc */ /* path.cc */
struct mntent _ret; struct mntent _ret;
char *_current_directory_name; char *_cwd_win32;
char *_current_directory_posix_name; char *_cwd_posix;
unsigned long _current_directory_hash; unsigned long _cwd_hash;
int _iteration; int _iteration;
/* strerror */ /* strerror */