xref: /dflybsd-src/contrib/grep/lib/filename.h (revision 91b9ed38d3db6a8a8ac5b66da1d43e6e331e259a)
1cf28ed85SJohn Marino /* Basic filename support macros.
2*09d4459fSDaniel Fojt    Copyright (C) 2001-2004, 2007-2020 Free Software Foundation, Inc.
3cf28ed85SJohn Marino 
4cf28ed85SJohn Marino    This program is free software: you can redistribute it and/or modify
5cf28ed85SJohn Marino    it under the terms of the GNU General Public License as published by
6cf28ed85SJohn Marino    the Free Software Foundation; either version 3 of the License, or
7cf28ed85SJohn Marino    (at your option) any later version.
8cf28ed85SJohn Marino 
9cf28ed85SJohn Marino    This program is distributed in the hope that it will be useful,
10cf28ed85SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
11cf28ed85SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12cf28ed85SJohn Marino    GNU General Public License for more details.
13cf28ed85SJohn Marino 
14cf28ed85SJohn Marino    You should have received a copy of the GNU General Public License
15*09d4459fSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16cf28ed85SJohn Marino 
17cf28ed85SJohn Marino #ifndef _FILENAME_H
18cf28ed85SJohn Marino #define _FILENAME_H
19cf28ed85SJohn Marino 
20cf28ed85SJohn Marino #ifdef __cplusplus
21cf28ed85SJohn Marino extern "C" {
22cf28ed85SJohn Marino #endif
23cf28ed85SJohn Marino 
24cf28ed85SJohn Marino 
25cf28ed85SJohn Marino /* Pathname support.
26cf28ed85SJohn Marino    ISSLASH(C)           tests whether C is a directory separator character.
27cf28ed85SJohn Marino    IS_ABSOLUTE_PATH(P)  tests whether P is an absolute path.  If it is not,
28cf28ed85SJohn Marino                         it may be concatenated to a directory pathname.
29cf28ed85SJohn Marino    IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
30cf28ed85SJohn Marino  */
31*09d4459fSDaniel Fojt #if defined _WIN32 || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
32cf28ed85SJohn Marino   /* Native Windows, Cygwin, OS/2, DOS */
33cf28ed85SJohn Marino # define ISSLASH(C) ((C) == '/' || (C) == '\\')
34cf28ed85SJohn Marino # define HAS_DEVICE(P) \
35cf28ed85SJohn Marino     ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
36cf28ed85SJohn Marino      && (P)[1] == ':')
37cf28ed85SJohn Marino # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
38cf28ed85SJohn Marino # define IS_PATH_WITH_DIR(P) \
39cf28ed85SJohn Marino     (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
40cf28ed85SJohn Marino # define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
41cf28ed85SJohn Marino #else
42cf28ed85SJohn Marino   /* Unix */
43cf28ed85SJohn Marino # define ISSLASH(C) ((C) == '/')
44cf28ed85SJohn Marino # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
45cf28ed85SJohn Marino # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
46cf28ed85SJohn Marino # define FILE_SYSTEM_PREFIX_LEN(P) 0
47cf28ed85SJohn Marino #endif
48cf28ed85SJohn Marino 
49cf28ed85SJohn Marino 
50cf28ed85SJohn Marino #ifdef __cplusplus
51cf28ed85SJohn Marino }
52cf28ed85SJohn Marino #endif
53cf28ed85SJohn Marino 
54cf28ed85SJohn Marino #endif /* _FILENAME_H */
55