diff options
author | Christopher Faylor <me@cgf.cx> | 2000-10-02 02:26:04 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-10-02 02:26:04 +0000 |
commit | 9fc09d00f7579eab987fabffbe14fdb210a45637 (patch) | |
tree | 476981be354ffea18888b8df0fd7af0c848f90ee /winsup/cygwin/path.cc | |
parent | 0ce83ef6b8e1e7b113c1081d5ca203f5cac0e7b2 (diff) | |
download | cygnal-9fc09d00f7579eab987fabffbe14fdb210a45637.tar.gz cygnal-9fc09d00f7579eab987fabffbe14fdb210a45637.tar.bz2 cygnal-9fc09d00f7579eab987fabffbe14fdb210a45637.zip |
* cygheap.cc (cygheap_init): Born again function.
(_cmalloc): Reorganize to accomodate muto locking.
(_cfree): Use muto lock to avoid multi-thread problems.
* cygheap.h (incygheap): Just use cygheap_max to find upper cygwin heap bounds.
* dcrt0.cc (dll_crt0_1): Reinstitute cygheap_init call.
* path.cc (getcwd): Just return cwdstuff::get result, allowing correct handling
of negative length.
(cwdstuff::get): Malloc a buffer if one is not available.
Diffstat (limited to 'winsup/cygwin/path.cc')
-rw-r--r-- | winsup/cygwin/path.cc | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 856bdeff5..ad60e07a1 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2436,36 +2436,7 @@ hashit: char * getcwd (char *buf, size_t ulen) { - char *res; - char *usebuf, uselen; - - if (buf != NULL) - { - usebuf = buf; - uselen = TRUE; - } - else - { - if (ulen >= 0) - uselen = TRUE; - else - { - uselen = FALSE; - ulen = MAX_PATH + 1; - } - - usebuf = (char *) malloc (ulen); - usebuf [ulen - 1] = '\0'; - } - - res = cygcwd.get (usebuf, 1, 1, ulen); - - if (res && !uselen) - usebuf = (char *) realloc (usebuf, strlen (usebuf) + 1); - else if (!res && buf == NULL) - free (usebuf); - - return res; + return cygcwd.get (buf, 1, 1, ulen); } /* getwd: standards? */ @@ -2481,6 +2452,7 @@ extern "C" int chdir (const char *dir) { + MALLOC_CHECK; syscall_printf ("dir %s", dir); path_conv path (dir, PC_FULL | PC_SYM_FOLLOW); @@ -2529,6 +2501,7 @@ chdir (const char *dir) it was worth locking just for strace. */ syscall_printf ("%d = chdir() cygcwd.posix '%s' native '%s'", res, cygcwd.posix, native_dir); + MALLOC_CHECK; return res; } @@ -2962,8 +2935,7 @@ cwdstuff::set (const char *win32_cwd, const char *posix_cwd) char * cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen) { - size_t len = ulen; - + MALLOC_CHECK; if (!get_initial ()) /* Get initial cwd and set cwd lock */ return NULL; @@ -2982,6 +2954,8 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen) } else { + if (need_posix && !buf) + buf = (char *) malloc (strlen (tocopy) + 1); strcpy (buf, tocopy); if (!buf[0]) /* Should only happen when chroot */ strcpy (buf, "/"); @@ -2989,7 +2963,8 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen) lock->release (); syscall_printf ("(%s) = cwdstuff::get (%p, %d, %d, %d)", - buf, buf, len, need_posix, with_chroot); + buf, buf, ulen, need_posix, with_chroot); + MALLOC_CHECK; return buf; } @@ -3002,5 +2977,6 @@ cwdstuff::copy (char * &posix_cwd, char * &win32_cwd, DWORD hash_cwd) posix_cwd = cstrdup (posix); win32_cwd = cstrdup (win32); hash_cwd = hash; + MALLOC_CHECK; lock->release (); } |