delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/20/09:25:28

Date: Mon, 20 Jan 2003 14:26:51 +0000
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
Sender: rich AT phekda DOT freeserve DOT co DOT uk
To: djgpp-workers AT delorie DOT com
X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: __solve_dir_symlinks bug: c:/ [PATCH]
Message-Id: <E18acrZ-0000rH-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

__solve_dir_symlinks() doesn't cope with drive-qualified
root directories. Patch below.

The patch also lets you build a test program for the __solve_dir_symlinks
sources and run it on arbitrary file names.

OK to commit?

Bye, Rich =]

Index: src/libc/compat/unistd/sdirlink.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/compat/unistd/sdirlink.c,v
retrieving revision 1.5
diff -p -c -3 -r1.5 sdirlink.c
*** src/libc/compat/unistd/sdirlink.c	17 Oct 2002 23:00:25 -0000	1.5
--- src/libc/compat/unistd/sdirlink.c	20 Jan 2003 14:22:19 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
  
*************** int __solve_dir_symlinks(const char * __
*** 12,17 ****
--- 13,19 ----
  {
     char   path_copy[FILENAME_MAX];
     char * last_part;
+    int    is_root = 0;
  
     /* Reject NULLs... */
     if (!__symlink_path || !__real_path)
*************** int __solve_dir_symlinks(const char * __
*** 28,35 ****
     }
  
     /* Handle root directories */
!    if ((__symlink_path[1] == '\0') && 
!       ((__symlink_path[0] == '/') || (__symlink_path[0] == '\\')))
     {
        strcpy(__real_path, __symlink_path);
        return 1;
--- 30,46 ----
     }
  
     /* Handle root directories */
!    if (   ((__symlink_path[0] == '/') || (__symlink_path[0] == '\\'))
!        && (__symlink_path[1] == '\0'))
!      is_root = 1;
! 
!    if (   __symlink_path[0]
!        && (__symlink_path[1] == ':')
!        && ((__symlink_path[2] == '/') || (__symlink_path[2] == '\\'))
!        && (__symlink_path[3] == '\0'))
!      is_root = 1;
! 
!    if (is_root)
     {
        strcpy(__real_path, __symlink_path);
        return 1;
*************** int __solve_dir_symlinks(const char * __
*** 72,74 ****
--- 83,104 ----
     strcat(__real_path, last_part);
     return 1;
  }
+ 
+ #ifdef TEST
+ 
+ #include <stdlib.h>
+ 
+ int main(int argc, char *argv[])
+ {
+   char buf[FILENAME_MAX];
+   int i;
+ 
+   puts("User requested tests:");
+   for (i = 1; i < argc; i++) {
+     __solve_dir_symlinks(argv[i], buf);
+     printf("%s -> %s\n", argv[i], buf);
+   }
+ 
+   return EXIT_SUCCESS;
+ }
+ #endif
Index: tests/libc/compat/unistd/sdirlink.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/compat/unistd/sdirlink.c,v
retrieving revision 1.3
diff -p -c -3 -r1.3 sdirlink.c
*** tests/libc/compat/unistd/sdirlink.c	17 Mar 2001 09:49:52 -0000	1.3
--- tests/libc/compat/unistd/sdirlink.c	20 Jan 2003 14:22:19 -0000
*************** int main(void)
*** 35,40 ****
--- 35,44 ----
         exit(1);
     }
     printf("Running __solve_dir_symlink() testsuite:\n");
+    test_success("/", "/");
+    test_success("c:/", "c:/");
+    test_success("/dev/c", "/dev/c");
+    test_success("/dev/c/", "/dev/c");
     test_success("test1", "test1");
     test_success("test1/", "test1");
     test_success("dir1/test1", "dir1/test1");

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019