file system handling patch for libiberty (rev 2)

Mark E. snowball3@bigfoot.com
Thu Apr 27 11:32:00 GMT 2000


Hello,
This patch adds filesys.h to help mask the differences between Unix and the
Microsoft OSes and changes basename.c and choose-temp.c to use it.

Include Changelog:

2000-04-27 Mark Elbrecht <snowball3@bigfoot.com>

	* include/filesys.h: New file. Defines macros DIR_SEPARATOR,
	   DIR_SEPARATOR_2, IS_DIR_SEPARATOR, PATH_SEPARATOR,
	  IS_PATH_SEPARATOR, IS_ABSOLUTE_FILENAME, and FILENAME_CMP.

Libiberty Changelog:

2000-04-27 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.

*** /dev/null	Thu Apr 27 14:18:43 2000
--- include/filesys.h	Thu Apr 27 14:16:54 2000
***************
*** 0 ****
--- 1,85 ----
+ /* Macros that hide the differences between Unix, Windows,
+    and other file 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
+ 
+ /* GCC's config files may have already defined DIR_SEPARATOR,
+    HAVE_DOS_BASED_FILE_SYSTEM, DIR_SEPARATOR_2, and IS_DIR_SEPARATOR,
+    so care is taken to not define them again.  */
+ 
+ /* Define the directory separator.  */
+ #ifndef DIR_SEPARATOR
+ #define DIR_SEPARATOR '/'
+ #endif
+ 
+ /* DOS, Windows, and OS/2 also use '\' as a directory separator.
+    Also 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 IS_DIR_SEPARATOR.  Use this macro in place of testing for '/'. */
+ #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 PATH_SEPARATOR. Unix and Unix emulators (like Cygwin) use ':',
+    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
+ 
+ /* Define IS_PATH_SEPARATOR.  Use this macro in place of testing for ':'.  */
+ #define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+ 
+ /* Define IS_ABSOLUTE_FILENAME. Use this macro in place of testing if
+    the first character in a string is '/'.  */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define IS_ABSOLUTE_FILENAME(f) \
+ 	IS_DIR_SEPARATOR(*f) || (f[1] == ':' && IS_DIR_SEPARATOR(f[2]))
+ #else
+ #define IS_ABSOLUTE_FILENAME(f) IS_DIR_SEPARATOR(*f)
+ #endif
+ 
+ /* Define FILENAME_CMP. Use this macro to determine whether two filenames
+    are the same.  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 FILENAME_CMP(s1, s2) strcasecmp(s1, s2)
+ #else
+ #define FILENAME_CMP(s1, s2) strcmp(s1, s2)
+ #endif
+ 
+ #endif /* FILE_SYS_H */
*** 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);
  



More information about the Gcc-patches mailing list