OSDN Git Service

* fhandler.cc (rootdir): Add and use second argument.
authorcorinna <corinna>
Sat, 10 Apr 2004 19:24:55 +0000 (19:24 +0000)
committercorinna <corinna>
Sat, 10 Apr 2004 19:24:55 +0000 (19:24 +0000)
* 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.

winsup/cygwin/ChangeLog
winsup/cygwin/fhandler.cc
winsup/cygwin/path.cc
winsup/cygwin/syscalls.cc
winsup/cygwin/winsup.h

index 59e3507..2af2567 100644 (file)
@@ -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_*,
index 6826460..a005e61 100644 (file)
@@ -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
index 057df9a..1fc9fc3 100644 (file)
@@ -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 ();
index ad99d8a..bac1ccb 100644 (file)
@@ -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 */
index 3dbb3ce..3e132a1 100644 (file)
@@ -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);