This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

(libiberty) basename dos/win tweak


Libibery basename() doesn't handle DOS style pathnames correctly, and
causes binutils to act weird at times (eg., `ar crv libfoo.a foo\bar.o'
adds foo\bar.o as the archive member, not bar.o as expected).

The change matches what GCC currently does when it deals with DOS based 
FS.

Mon Aug 30 18:09:42 1999  Mumit Khan  <khan@xraylith.wisc.edu>

	* basename.c (DIR_SEPARATOR): New macro.
	(DIR_SEPARATOR_2): Likewise.
	(HAVE_DOS_BASED_FILESYSTEM): Likewise.
	(IS_DIR_SEPARATOR): Likewise.
	(main): Handle MSDOS style pathname.

Index: basename.c
===================================================================
RCS file: /homes/khan/src/CVSROOT/gcc-2.95/libiberty/basename.c,v
retrieving revision 1.1.1.1
diff -3 -p -c -r1.1.1.1 basename.c
*** basename.c	1999/06/14 21:05:49	1.1.1.1
--- basename.c	1999/08/30 23:06:46
*************** DESCRIPTION
*** 14,37 ****
  	last component of the pathname ("ls.c" in this case).
  
  BUGS
! 	Presumes a UNIX style path with UNIX style separators.
  */
  
  #include "ansidecl.h"
  #include "libiberty.h"
  
  char *
  basename (name)
       const char *name;
  {
!   const char *base = name;
  
!   while (*name)
      {
!       if (*name++ == '/')
  	{
! 	  base = name;
  	}
      }
    return (char *) base;
  }
--- 14,66 ----
  	last component of the pathname ("ls.c" in this case).
  
  BUGS
! 	Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows 
! 	style separators.
  */
  
  #include "ansidecl.h"
  #include "libiberty.h"
+ #include <ctype.h>
  
+ #ifndef DIR_SEPARATOR
+ #define DIR_SEPARATOR '/'
+ #endif
+ 
+ #if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+   defined (__OS2__)
+ #define HAVE_DOS_BASED_FILE_SYSTEM
+ #ifndef DIR_SEPARATOR_2 
+ #define DIR_SEPARATOR_2 '\\'
+ #endif
+ #endif
+ 
+ /* Define IS_DIR_SEPARATOR.  */
+ #ifndef DIR_SEPARATOR_2
+ # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+ #else /* DIR_SEPARATOR_2 */
+ # define IS_DIR_SEPARATOR(ch) \
+ 	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+ #endif /* DIR_SEPARATOR_2 */
+ 
  char *
  basename (name)
       const char *name;
  {
!   const char *base;
  
! #if defined (HAVE_DOS_BASED_FILE_SYSTEM)
!   /* Skip over the disk name in MSDOS pathnames. */
!   if (isalpha (name[0]) && name[1] == ':') 
!     name += 2;
! #endif
! 
!   for (base = name; *name; name++)
      {
!       if (IS_DIR_SEPARATOR (*name))
  	{
! 	  base = name + 1;
  	}
      }
    return (char *) base;
  }
+ 

Regards,
Mumit


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]