beta-0.89.2
[luatex.git] / source / texk / kpathsea / absolute.c
blob6fc386b053b48784885bcdc75c194961158afe4f
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. */
27 boolean
28 kpathsea_absolute_p (kpathsea kpse, const_string filename, boolean relative_ok)
30 #ifdef VMS
31 #include <string.h>
32 (void)kpse; /* currenty not used */
33 return strcspn (filename, "]>:") != strlen (filename);
34 #else /* not VMS */
35 boolean absolute;
36 boolean explicit_relative;
38 absolute = IS_DIR_SEP (*filename)
39 #ifdef DOSISH
40 /* Novell allows non-alphanumeric drive letters. */
41 || (*filename && IS_DEVICE_SEP (filename[1]))
42 #endif /* DOSISH */
43 #ifdef WIN32
44 /* UNC names */
45 || (*filename == '\\' && filename[1] == '\\')
46 || (*filename == '/' && filename[1] == '/')
47 #endif /* WIN32 */
48 #ifdef AMIGA
49 /* Colon anywhere means a device. */
50 || strchr (filename, ':')
51 #endif /* AMIGA */
53 explicit_relative
54 = relative_ok
55 #ifdef AMIGA
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
60 #endif /* AMIGA */
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
66 implies relative. */
67 return absolute || explicit_relative;
68 #endif /* not VMS */
71 #if defined (KPSE_COMPAT_API)
72 boolean
73 kpse_absolute_p (const_string filename, boolean relative_ok)
75 return kpathsea_absolute_p (kpse_def, filename, relative_ok);
77 #endif
79 #ifdef TEST
80 int main()
82 char **name;
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");
90 #endif /* TEST */
93 Local variables:
94 standalone-compile-command: "gcc -g -I. -I.. -DTEST absolute.c kpathsea.a"
95 End: