2
# Taken from xlock, many authors...
6
# Permission to use, copy, modify, and distribute this software and
7
# its documentation for any purpose and without fee is hereby granted,
8
# provided that the above copyright notice appear in all copies and
9
# that both that copyright notice and this permission notice appear in
10
# supporting documentation, and that the name of the author not be
11
# used in advertising or publicity pertaining to distribution of the
12
# software without specific, written prior permission.
14
# This program is distributed in the hope that it will be "useful",
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26
carefulOpen(char *fileName, const char *type)
28
FILE *fp = (FILE *) NULL;
32
s = stat(fileName, &fileStat);
33
if ((s >= 0 && S_ISREG(fileStat.st_mode)) || (s < 0 && type[0] == 'w')) {
34
if ((fp = fopen(fileName, type)) == NULL)
44
readable(char *fileName)
48
if ((fp = carefulOpen(fileName, "r")) == NULL)
55
#define LASTDELIM '\\'
64
baseName(char *fileName)
68
for (i = strlen(fileName); i >= 0; i--) {
69
if (fileName[i] == LASTDELIM
74
return &fileName[i + 1];
80
findFile(char *fileName)
82
if (readable(fileName))
85
char *temp = baseName(fileName);