1 /* absolute.c: test if a filename is absolute or explicitly relative.
3 Copyright 1993, 1994, 1995, 2008, 2009, 2010, 2011 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 kpathsea_absolute_p (kpathsea kpse
, const_string filename
, boolean relative_ok
)
32 (void)kpse
; /* currenty not used */
33 return strcspn (filename
, "]>:") != strlen (filename
);
36 boolean explicit_relative
;
38 absolute
= IS_DIR_SEP (*filename
)
40 /* Novell allows non-alphanumeric drive letters. */
41 || (*filename
&& IS_DEVICE_SEP (filename
[1]))
45 || (*filename
== '\\' && filename
[1] == '\\')
46 || (*filename
== '/' && filename
[1] == '/')
49 /* Colon anywhere means a device. */
50 || strchr (filename
, ':')
56 /* Leading / is like `../' on Unix and DOS. Allow Unix syntax,
57 too, though, because of possible patch programs like
58 `UnixDirsII' by Martin Scott. */
59 && IS_DIR_SEP (*filename
) || 0
61 && (*filename
== '.' && (IS_DIR_SEP (filename
[1])
62 || (filename
[1] == '.' && IS_DIR_SEP (filename
[2]))));
64 (void)kpse
; /* currenty not used */
65 /* FIXME: On UNIX an IS_DIR_SEP of any but the last character in the name
67 return absolute
|| explicit_relative
;
71 #if defined (KPSE_COMPAT_API)
73 kpse_absolute_p (const_string filename
, boolean relative_ok
)
75 return kpathsea_absolute_p (kpse_def
, filename
, relative_ok
);
83 char *t
[] = { "./foo", "\\\\server\\foo\\bar", "ftp://localhost/foo" };
85 for (name
= t
; name
- t
< sizeof(t
)/sizeof(char*); name
++) {
86 printf ("Path `%s' %s absolute.\n", *name
,
87 kpse_absolute_p(*name
, true) ? "is" : "is not");
94 standalone-compile-command: "gcc -g -I. -I.. -DTEST absolute.c kpathsea.a"