home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / patches / gcc-2_95_2-x86-win32-patches.zi / gcc-2.95.2-patches / broken-down / gcc-2.95.2-libiberty-basename.diff < prev    next >
Encoding:
Text File  |  1999-11-08  |  1.9 KB  |  75 lines

  1. Mon Aug 30 18:09:42 1999  Mumit Khan  <khan@xraylith.wisc.edu>
  2.  
  3.     * basename.c (DIR_SEPARATOR): New macro.
  4.     (DIR_SEPARATOR_2): Likewise.
  5.     (HAVE_DOS_BASED_FILESYSTEM): Likewise.
  6.     (IS_DIR_SEPARATOR): Likewise.
  7.     (main): Handle MSDOS style pathname.
  8.  
  9. Index: gcc-2.95.2/libiberty/basename.c
  10. ===================================================================
  11. RCS file: /homes/khan/src/CVSROOT/gcc-2.95.2/libiberty/basename.c,v
  12. retrieving revision 1.1.1.1
  13. diff -u -3 -p -r1.1.1.1 basename.c
  14. --- gcc-2.95.2/libiberty/basename.c    1999/11/05 01:10:13    1.1.1.1
  15. +++ gcc-2.95.2/libiberty/basename.c    1999/11/05 09:39:14
  16. @@ -14,24 +14,53 @@ DESCRIPTION
  17.      last component of the pathname ("ls.c" in this case).
  18.  
  19.  BUGS
  20. -    Presumes a UNIX style path with UNIX style separators.
  21. +    Presumes a UNIX or DOS/Windows style path with UNIX or DOS/Windows 
  22. +    style separators.
  23.  */
  24.  
  25.  #include "ansidecl.h"
  26.  #include "libiberty.h"
  27. +#include <ctype.h>
  28.  
  29. +#ifndef DIR_SEPARATOR
  30. +#define DIR_SEPARATOR '/'
  31. +#endif
  32. +
  33. +#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
  34. +  defined (__OS2__)
  35. +#define HAVE_DOS_BASED_FILE_SYSTEM
  36. +#ifndef DIR_SEPARATOR_2 
  37. +#define DIR_SEPARATOR_2 '\\'
  38. +#endif
  39. +#endif
  40. +
  41. +/* Define IS_DIR_SEPARATOR.  */
  42. +#ifndef DIR_SEPARATOR_2
  43. +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
  44. +#else /* DIR_SEPARATOR_2 */
  45. +# define IS_DIR_SEPARATOR(ch) \
  46. +    (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
  47. +#endif /* DIR_SEPARATOR_2 */
  48. +
  49.  char *
  50.  basename (name)
  51.       const char *name;
  52.  {
  53. -  const char *base = name;
  54. +  const char *base;
  55.  
  56. -  while (*name)
  57. +#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
  58. +  /* Skip over the disk name in MSDOS pathnames. */
  59. +  if (isalpha (name[0]) && name[1] == ':') 
  60. +    name += 2;
  61. +#endif
  62. +
  63. +  for (base = name; *name; name++)
  64.      {
  65. -      if (*name++ == '/')
  66. +      if (IS_DIR_SEPARATOR (*name))
  67.      {
  68. -      base = name;
  69. +      base = name + 1;
  70.      }
  71.      }
  72.    return (char *) base;
  73.  }
  74. +
  75.