2 * OS dependent functions
3 * Copyright (C) 1993-2003,2004,2005,2014 Olly Betts
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 /* NB "c:fred" isn't relative. Eg "c:\data\c:fred" won't work */
33 fAbsoluteFnm(const char *fnm
)
35 /* <drive letter>: or \<path> or /<path>
36 * or \\<host>\... or //<host>/... */
37 unsigned char ch
= (unsigned char)*fnm
;
38 return ch
== '/' || ch
== '\\' ||
39 (ch
&& fnm
[1] == ':' && (ch
| 32) >= 'a' && (ch
| 32) <= 'z');
45 fAbsoluteFnm(const char *fnm
)
47 return (fnm
[0] == '/');
52 /* fDirectory( fnm ) returns fTrue if fnm is a directory; fFalse if fnm is a
53 * file, doesn't exist, or another error occurs (eg disc not in drive, ...)
54 * NB If fnm has a trailing directory separator (e.g. “/” or “/home/olly/”
55 * then it's assumed to be a directory even if it doesn't exist (as is an
59 #if OS_UNIX || OS_WIN32
61 # include <sys/types.h>
62 # include <sys/stat.h>
66 fDirectory(const char *fnm
)
69 if (!fnm
[0] || fnm
[strlen(fnm
) - 1] == FNM_SEP_LEV
71 || fnm
[strlen(fnm
) - 1] == FNM_SEP_LEV2
75 /* On Unix, dereference any symlinks we might encounter */
76 if (lstat(fnm
, &buf
) != 0) return 0;
78 if (stat(fnm
, &buf
) != 0) return 0;
82 return S_ISDIR(buf
.st_mode
);
85 return ((buf
.st_mode
& S_IFMT
) == S_IFDIR
);