file system handling patch for libiberty (ver 4a)
Mark E.
snowball3@bigfoot.com
Sat May 13 21:03:00 GMT 2000
In Ver 4 of this patch, IS_SAME_PATH returns true if the paths are *not* the same. This patch
fixes this error.
Include Changelog:
2000-05-03 Mark Elbrecht <snowball3@bigfoot.com>
* filesys.h: New file.
* filesys.h: If not already defined, define DIR_SEPARATOR,
DIR_SEPARATOR_2, and PATH_SEPARATOR.
* filesys.h: Define IS_DIR_SEPARATOR, IS_PATH_SEPARATOR,
IS_ABSOLUTE_PATH, IS_DOS_STYLE_RELATIVE_PATH,
HAS_DOS_STYLE_DRIVE_NAME, IS_SAME_PATH, and IS_SAME_PATH_CHAR.
Libiberty Changelog:
2000-05-03 Mark Elbrecht <snowball3@bigfoot.com>
* libiberty/basename.c (DIR_SEPARATOR, DIR_SEPARATOR_2,
HAVE_DOS_BASED_FILE_SYSTEM): Delete. Now defined by
including filesys.h.
* libiberty/choose-temp.c (DIR_SEPARATOR): Delete. Now defined by
including filesys.h.
(choose_temp_base): Use IS_DIR_SEPARATOR from filesys.h.
(make_temp_file): Likewise.
*** libiberty/basename.c.orig Wed Oct 13 03:18:10 1999
--- libiberty/basename.c Tue Apr 18 18:33:20 2000
*************** BUGS
*** 20,47 ****
#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;
--- 20,28 ----
#include "ansidecl.h"
#include "libiberty.h"
+ #include "filesys.h"
#include <ctype.h>
char *
basename (name)
const char *name;
*** libiberty/choose-temp.c.orig Sat Sep 25 09:11:12 1999
--- libiberty/choose-temp.c Tue Apr 18 17:58:02 2000
***************
*** 1,5 ****
/* Utility to pick a temporary filename prefix.
! Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
--- 1,5 ----
/* Utility to pick a temporary filename prefix.
! Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
*************** Boston, MA 02111-1307, USA. */
*** 45,61 ****
#endif
#include "libiberty.h"
! extern int mkstemps ();
!
! #ifndef IN_GCC
! #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN__) && ! defined (_UWIN))
! #define DIR_SEPARATOR '\\'
! #endif
! #endif
! #ifndef DIR_SEPARATOR
! #define DIR_SEPARATOR '/'
! #endif
/* On MSDOS, write temp files in current dir
because there's no place else we can expect to use. */
--- 45,53 ----
#endif
#include "libiberty.h"
! #include "filesys.h"
! extern int mkstemps ();
/* On MSDOS, write temp files in current dir
because there's no place else we can expect to use. */
*************** choose_temp_base ()
*** 130,137 ****
strcpy (temp_filename, base);
if (len != 0
! && temp_filename[len-1] != '/'
! && temp_filename[len-1] != DIR_SEPARATOR)
temp_filename[len++] = DIR_SEPARATOR;
strcpy (temp_filename + len, TEMP_FILE);
--- 122,128 ----
strcpy (temp_filename, base);
if (len != 0
! && !IS_DIR_SEPARATOR (temp_filename[len-1]))
temp_filename[len++] = DIR_SEPARATOR;
strcpy (temp_filename + len, TEMP_FILE);
*************** make_temp_file (suffix)
*** 183,190 ****
strcpy (temp_filename, base);
if (base_len != 0
! && temp_filename[base_len-1] != '/'
! && temp_filename[base_len-1] != DIR_SEPARATOR)
temp_filename[base_len++] = DIR_SEPARATOR;
strcpy (temp_filename + base_len, TEMP_FILE);
--- 174,180 ----
strcpy (temp_filename, base);
if (base_len != 0
! && !IS_DIR_SEPARATOR (temp_filename[base_len-1]))
temp_filename[base_len++] = DIR_SEPARATOR;
strcpy (temp_filename + base_len, TEMP_FILE);
*** /dev/null Wed May 3 14:16:34 2000
--- include/filesys.h Wed May 3 14:16:06 2000
***************
*** 0 ****
--- 1,115 ----
+ /* Macros to help hide the file system differences between Unix, Windows,
+ and other operating systems.
+
+ Copyright (C) 2000 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+ #ifndef FILE_SYS_H
+ #define FILE_SYS_H
+
+ /* If both DIR_SEPARATOR and PATH_SEPARATOR are already defined,
+ assume that HAVE_DOS_BASED_FILE_SYSTEM and DIR_SEPARATOR_2 have also
+ been defined when appropriate. This is to allow another file to provide
+ custom settings when the defaults would not be appropriate (like
+ when in a cross-compiler environment). */
+ #if !(defined (DIR_SEPARATOR) && defined (PATH_SEPARATOR))
+
+ /* Define the directory separator. */
+ #ifndef DIR_SEPARATOR
+ #define DIR_SEPARATOR '/'
+ #endif
+
+ /* Define DIR_SEPARATOR_2 for DOS, Windows, and OS/2 because they also use
+ '\' as a directory separator. Define HAVE_DOS_BASED_FILE_SYSTEM to
+ enable code that handles drive letters and other oddities. */
+ #if defined (_WIN32) || defined (__MSDOS__) || defined (__OS2__)
+ #ifndef HAVE_DOS_BASED_FILE_SYSTEM
+ #define HAVE_DOS_BASED_FILE_SYSTEM
+ #endif
+ #ifndef DIR_SEPARATOR_2
+ #define DIR_SEPARATOR_2 '\\'
+ #endif
+ #endif
+
+ /* Define PATH_SEPARATOR. Unix and Unix emulators (such as Cygwin) use ':'
+ to separate paths while DOS, Windows, and OS/2 use ';'. */
+ #ifndef PATH_SEPARATOR
+ #if defined (HAVE_DOS_BASED_FILE_SYSTEM) && !defined (__CYGWIN__)
+ #define PATH_SEPARATOR ';'
+ #else /* !HAVE_DOS_BASED_FILE_SYSTEM || __CYGWIN__ */
+ #define PATH_SEPARATOR ':'
+ #endif /* !HAVE_DOS_BASED_FILE_SYSTEM || __CYGWIN__ */
+ #endif
+
+ #endif /* ! (DIR_SEPARATOR && PATH_SEPARATOR) */
+
+ /* Define IS_DIR_SEPARATOR. Determines if a character is
+ a directory 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 */
+
+ /* Define IS_PATH_SEPARATOR. Determines if a character is
+ a path separator. */
+ #define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+
+ /* Define IS_ABSOLUTE_PATH. Determines if a path is absoltue. */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define IS_ABSOLUTE_PATH(f) \
+ (IS_DIR_SEPARATOR(*(f)) || ((f)[0] != '\0' && (f)[1] == ':' && IS_DIR_SEPARATOR((f)[2])))
+ #else
+ #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR(*(f)))
+ #endif
+
+ /* Define IS_DOS_STYLE_RELATIVE_PATH. Determines if path is
+ a DOS-style relative path that takes the form 'x:foo/bar'. */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define IS_DOS_STYLE_RELATIVE_PATH(f) \
+ ((f)[0] != '\0' && (f)[1] == ':' && !IS_DIR_SEPARATOR((f)[2]))
+ #else
+ #define IS_DOS_STYLE_RELATIVE_PATH(f) (0)
+ #endif
+
+ /* Define HAS_DRIVE_NAME. Determines if a path starts with
+ a DOS-style drive name. */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define HAS_DOS_STYLE_DRIVE_NAME(f) ((*(f) != '\0') && ((f)[1] == ':'))
+ #else
+ #define HAS_DOS_STYLE_DRIVE_NAME(f) (0)
+ #endif
+
+ /* Define IS_SAME_PATH. Determine if two paths match.
+ Unix filenames are case-sensitive, while MS Windows filenames are not
+ (even though it preserves case). Therefore, the method of comparing the
+ filenames must differ. This macro assumes the two filenames have already
+ been canonicalized somehow. */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define IS_SAME_PATH(s1, s2) (strcasecmp((s1), (s2)) == 0)
+ #else
+ #define IS_SAME_PATH(s1, s2) (strcmp((s1), (s2)) == 0)
+ #endif
+
+ /* Define IS_SAME_PATH_CHAR. Determine if two path elements match. */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define IS_SAME_PATH_CHAR(a,b) (toupper (a) == toupper (b))
+ #else
+ #define IS_SAME_PATH_CHAR(a,b) ((a) == (b))
+ #endif
+
+ #endif /* FILE_SYS_H */
More information about the Gcc-patches
mailing list