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]

file system handling patch for libiberty (ver 3)


Thanks to those who gave feedback. Here is version 3 which implements the suggested changes, plus 
one more. If both DIR_SEPARATOR and PATH_SEPARATOR are defined,
then code doesn't attempt to set DIR_SEPARATOR_2 and HAVE_DOS_BASED_FILE_SYSTEM.
This allows another config file (a config.h generated by a configure script for example) to 
provide its own settings. For example, a package may want to set
DIR_SEPARATOR, PATH_SEPARATOR, etc. to the right values for the target machine,
instead of the host machine.

This patch adds filesys.h to help mask the differences between Unix and the
Microsoft operating systems 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.

*** 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	Sat Apr 29 19:54:20 2000
--- include/filesys.h	Sat Apr 29 19:54:06 2000
***************
*** 0 ****
--- 1,92 ----
+ /* 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.  This macro determines whether 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.  This macro determines whether a character
+    is a path separator.  */
+ #define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+ 
+ /* Define IS_ABSOLUTE_FILENAME. This macro determines whether a
+    character string contains an absolute or relative filename.  */
+ #ifdef HAVE_DOS_BASED_FILE_SYSTEM
+ #define IS_ABSOLUTE_FILENAME(f) \
+ 	(IS_DIR_SEPARATOR(*(f)) || ((f)[0] != '\0' && (f)[1] == ':' && IS_DIR_SEPARATOR((f)[2])))
+ #else
+ #define IS_ABSOLUTE_FILENAME(f) (IS_DIR_SEPARATOR(*(f)))
+ #endif
+ 
+ /* Define FILENAME_CMP. This macro determines 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 */



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