75daa659401d3945a1c31c5b553db313fa09af05
[gnulib.git] / lib / pathname.h
1 /* Pathname support.
2    Copyright (C) 2001-2004 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 #ifndef _PATHNAME_H
19 #define _PATHNAME_H
20
21 /* Pathname support.
22    ISSLASH(C)           tests whether C is a directory separator character.
23    IS_ABSOLUTE_PATH(P)  tests whether P is an absolute path.  If it is not,
24                         it may be concatenated to a directory pathname.
25    IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
26  */
27 #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
28   /* Win32, Cygwin, OS/2, DOS */
29 # define ISSLASH(C) ((C) == '/' || (C) == '\\')
30 # define HAS_DEVICE(P) \
31     ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
32      && (P)[1] == ':')
33 # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P))
34 # define IS_PATH_WITH_DIR(P) \
35     (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
36 # define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
37 #else
38   /* Unix */
39 # define ISSLASH(C) ((C) == '/')
40 # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0])
41 # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
42 # define FILESYSTEM_PREFIX_LEN(P) 0
43 #endif
44
45 /* Concatenate a directory pathname, a relative pathname and an optional
46    suffix.  Return a freshly allocated pathname.  */
47 extern char *concatenated_pathname (const char *directory,
48                                     const char *filename, const char *suffix);
49
50 #endif /* _PATHNAME_H */