summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--winsup/cygwin/ChangeLog8
-rw-r--r--winsup/cygwin/fhandler.cc40
-rw-r--r--winsup/cygwin/path.cc3
-rw-r--r--winsup/cygwin/syscalls.cc12
-rw-r--r--winsup/cygwin/winsup.h2
5 files changed, 38 insertions, 27 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 59e350789..2af256725 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+2004-04-10 Pierre Humblet <pierre.humblet@ieee.org>
+
+ * fhandler.cc (rootdir): Add and use second argument.
+ * winsup.h (rootdir): Add second argument in declaration.
+ * path.cc (fs_info::update): Modify call to rootdir.
+ * syscalls.cc (check_posix_perm): Ditto.
+ (statfs): Ditto. Move syscall_printf near top.
+
2004-04-10 Corinna Vinschen <corinna@vinschen.de>
* Use new unified status_flag accessor methods from classes fhandler_*,
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 682646057..a005e6109 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1028,36 +1028,40 @@ fhandler_base::lock (int, struct __flock64 *)
}
extern "C" char * __stdcall
-rootdir (char *full_path)
+rootdir (const char *full_path, char *root_path)
{
/* Possible choices:
* d:... -> d:/
* \\server\share... -> \\server\share\
- * else current drive.
*/
- char *root = full_path;
+ int len;
+ char *rootp = root_path;
if (full_path[1] == ':')
- strcpy (full_path + 2, "\\");
+ {
+ *rootp++ = *full_path++;
+ *rootp++ = ':';
+ }
else if (full_path[0] == '\\' && full_path[1] == '\\')
{
- char *cp = full_path + 2;
- while (*cp && *cp != '\\')
- cp++;
- if (!*cp)
- {
- set_errno (ENOTDIR);
- return NULL;
- }
- cp++;
- while (*cp && *cp != '\\')
- cp++;
- strcpy (cp, "\\");
+ const char *cp = strchr (full_path + 2, '\\');
+ if (!cp)
+ goto error;
+ while (*++cp && *cp != '\\')
+ ;
+ memcpy (root_path, full_path, (len = cp - full_path));
+ rootp = root_path + len;
}
else
- root = NULL;
+ {
+ error:
+ set_errno (ENOTDIR);
+ return NULL;
+ }
- return root;
+ *rootp++ = '\\';
+ *rootp = '\0';
+ return root_path;
}
int __stdcall
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 057df9acb..1fc9fc3ac 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -361,9 +361,8 @@ fs_info::update (const char *win32_path)
{
char fsname [CYG_MAX_PATH];
char root_dir [CYG_MAX_PATH];
- strncpy (root_dir, win32_path, CYG_MAX_PATH);
- if (!rootdir (root_dir))
+ if (!rootdir (win32_path, root_dir))
{
debug_printf ("Cannot get root component of path %s", win32_path);
clear ();
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index ad99d8ab0..bac1ccb72 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1457,7 +1457,7 @@ check_posix_perm (const char *fname, int v)
if (!allow_ntsec)
return 0;
- char *root = rootdir (strcpy ((char *)alloca (strlen (fname)), fname));
+ char *root = rootdir (fname, (char *)alloca (strlen (fname)));
if (!allow_smbntsec
&& ((root[0] == '\\' && root[1] == '\\')
@@ -1793,7 +1793,9 @@ get_osfhandle (int fd)
extern "C" int
statfs (const char *fname, struct statfs *sfs)
{
- char root_dir[CYG_MAX_PATH];
+ char root[CYG_MAX_PATH];
+
+ syscall_printf ("statfs %s", fname);
if (!sfs)
{
@@ -1802,10 +1804,8 @@ statfs (const char *fname, struct statfs *sfs)
}
path_conv full_path (fname, PC_SYM_FOLLOW | PC_FULL);
- strncpy (root_dir, full_path, CYG_MAX_PATH);
- const char *root = rootdir (root_dir);
-
- syscall_printf ("statfs %s", root);
+ if (!rootdir (full_path, root))
+ return -1;
/* GetDiskFreeSpaceEx must be called before GetDiskFreeSpace on
WinME, to avoid the MS KB 314417 bug */
diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h
index 3dbb3ce89..3e132a174 100644
--- a/winsup/cygwin/winsup.h
+++ b/winsup/cygwin/winsup.h
@@ -240,7 +240,7 @@ int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
__ino64_t __stdcall hash_path_name (__ino64_t hash, const char *name) __attribute__ ((regparm(2)));
void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
-extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1)));
+extern "C" char *__stdcall rootdir (const char *full_path, char *root_path) __attribute__ ((regparm(2)));
/* String manipulation */
extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);