1 /* absolute.c: test if a filename is absolute or explicitly relative.
3 Copyright 1993, 1994, 1995, 2008 Karl Berry.
4 Copyright 1997, 2002, 2005 Olaf Weber.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <http://www.gnu.org/licenses/>. */
19 #include <kpathsea/config.h>
21 #include <kpathsea/absolute.h>
22 #include <kpathsea/c-pathch.h>
24 /* Sorry this is such a system-dependent mess, but I can't see any way
25 to usefully generalize. */
28 kpse_absolute_p P2C(const_string, filename, boolean, relative_ok)
32 return strcspn (filename, "]>:") != strlen (filename);
34 boolean absolute = IS_DIR_SEP (*filename)
36 /* Novell allows non-alphanumeric drive letters. */
37 || (*filename && IS_DEVICE_SEP (filename[1]))
40 /* Colon anywhere means a device. */
41 || strchr (filename, ':')
44 boolean explicit_relative
47 /* Leading / is like `../' on Unix and DOS. Allow Unix syntax,
48 too, though, because of possible patch programs like
49 `UnixDirsII' by Martin Scott. */
50 && IS_DIR_SEP (*filename) || 0
52 && (*filename == '.' && (IS_DIR_SEP (filename[1])
53 || (filename[1] == '.' && IS_DIR_SEP (filename[2]))));
55 /* FIXME: On UNIX an IS_DIR_SEP of any but the last character in the name
57 return absolute || explicit_relative;
65 char *t[] = { "./foo", "\\\\server\\foo\\bar", "ftp://localhost/foo" };
67 for (name = t; name - t < sizeof(t)/sizeof(char*); name++) {
68 printf("Path `%s' %s absolute.\n", *name, (kpse_absolute_p(*name, true) ? "is" : "is not"));