OSDN Git Service

* filenames.h (HAS_DRIVE_SPEC, STRIP_DRIVE_SPEC): New macros.
[pf3gnuchains/gcc-fork.git] / include / filenames.h
1 /* Macros for taking apart, interpreting and processing file names.
2
3    These are here because some non-Posix (a.k.a. DOSish) systems have
4    drive letter brain-damage at the beginning of an absolute file name,
5    use forward- and back-slash in path names interchangeably, and
6    some of them have case-insensitive file names.
7
8    Copyright 2000, 2001, 2007, 2010 Free Software Foundation, Inc.
9
10 This file is part of BFD, the Binary File Descriptor library.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
25
26 #ifndef FILENAMES_H
27 #define FILENAMES_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
34
35 #ifndef HAVE_DOS_BASED_FILE_SYSTEM
36 #define HAVE_DOS_BASED_FILE_SYSTEM 1
37 #endif
38
39 #define IS_DIR_SEPARATOR(c)     ((c) == '/' || (c) == '\\')
40
41 #define HAS_DRIVE_SPEC(f)       (((f)[0]) && ((f)[1] == ':'))
42
43 /* Remove the drive spec from F, assuming HAS_DRIVE_SPEC (f).
44    The result is a pointer to the remainder of F.  */
45 #define STRIP_DRIVE_SPEC(f)     ((f) + 2)
46
47 /* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
48    only semi-absolute.  This is because the users of IS_ABSOLUTE_PATH
49    want to know whether to prepend the current working directory to
50    a file name, which should not be done with a name like d:foo.  */
51 #define IS_ABSOLUTE_PATH(f)     (IS_DIR_SEPARATOR((f)[0]) || HAS_DRIVE_SPEC(f))
52
53 #else  /* not DOSish */
54
55 #define IS_DIR_SEPARATOR(c)     ((c) == '/')
56 #define IS_ABSOLUTE_PATH(f)     (IS_DIR_SEPARATOR((f)[0]))
57
58 #define HAS_DRIVE_SPEC(f)       (0)
59 #define STRIP_DRIVE_SPEC(f)     (f)
60
61 #endif /* not DOSish */
62
63 extern int filename_cmp (const char *s1, const char *s2);
64 #define FILENAME_CMP(s1, s2)    filename_cmp(s1, s2)
65
66 #ifdef __cplusplus
67 }
68 #endif
69
70 #endif /* FILENAMES_H */