2
dnl Copyright (C) 1993-2004 Free Software Foundation, Inc.
3
dnl This file is free software, distributed under the terms of the GNU
4
dnl General Public License. As a special exception to the GNU General
5
dnl Public License, this file may be distributed as part of a program
6
dnl that contains a configuration script generated by Autoconf, under
7
dnl the same distribution terms as the rest of that program.
9
dnl From Bruno Haible, Marcus Daniels, Sam Steingold.
13
AC_DEFUN([CL_FILECHARSET],
14
[AC_REQUIRE([AC_PROG_CC])dnl
15
AC_REQUIRE([CL_CLOSEDIR])dnl
16
AC_MSG_CHECKING(for the valid characters in filenames)
17
AC_CACHE_VAL(cl_cv_os_valid_filename_char,[
18
if test $cross_compiling = no; then
19
dnl Create the subdirectory the test program will use for its files.
21
cat > conftest.c <<EOF
23
#include <sys/types.h>
25
/* Declare chdir(). */
33
#ifdef OPEN_NEEDS_SYS_FILE_H
36
/* Declare opendir(), readdir(), closedir(). */
37
#include <$ac_header_dirent>
39
#define SDIRENT struct dirent
41
#define SDIRENT struct direct
44
/* A small program which checks for each character whether or not it is
45
* valid in filenames. */
49
#if defined(__CYGWIN32__) || defined(__MINGW32__)
50
/* The test below would cause a dialog box to pop up (ch == ':'),
51
and create files which cause "rm -rf conftest*" to hang
52
(ch == '"') || (ch == '<') || (ch == '>') || (ch == 197) || (ch == 206).
53
Also, it would make appear that (ch >= 'A') && (ch <= 'Z') doesn't work,
54
because it would create files in lower case. But we don't want to forbid
55
upper case letters in file names. */
56
printf("(ch >= 1) && (ch <= 127) && (ch != 34) && (ch != 42) && (ch != 47) && (ch != 58) && (ch != 60) && (ch != 62) && (ch != 63) && (ch != 92) || (ch == 131) || (ch >= 160) && (ch != 197) && (ch != 206)\n");
61
if (chdir("conftestdir") < 0) exit(1);
62
for (i = 0; i < N; i++) legal[i] = 0;
63
strcpy(filename,"a_z");
64
for (i = 0; i < N; i++)
67
/* Determine whether the filename is valid: create a file
68
* and check that it is present afterwards, under the same name. */
69
{ int fd = open(filename, O_CREAT | O_RDWR, 0644);
71
{ DIR* dirp = opendir(".");
74
while ((d = readdir(dirp)))
75
{ if (!strcmp(d->d_name,".")) continue;
76
if (!strcmp(d->d_name,"..")) continue;
77
if (!strncmp(d->d_name,".nfs",4)) continue;
78
if (!strcmp(d->d_name,filename)) legal[i] = 1;
79
/* Remove the file even if its name is something else. */
86
/* Output a boolean expression equivalent to legal[ch] (0 <= ch < N). */
91
if (! legal[z]) { z++; continue; }
93
if (need_or) printf(" || ");
95
if ((z < N) && legal[z])
96
{ do { do { z++; } while ((z < N) && legal[z]);
99
} while ((z < N) && legal[z]);
101
if (x > 0) premises++;
102
if (y < N-1) premises++;
103
for (i = x; i <= y; i++)
106
if (premises > 1) printf("(");
108
if (x > 0) { printf("(ch >= %d)",x); need_and = 1; }
110
{ if (need_and) printf(" && ");
111
printf("(ch <= %d)",y);
114
for (i = x; i <= y; i++)
116
{ if (need_and) printf(" && ");
117
printf("(ch != %d)",i);
120
if (!need_and) printf("1");
122
if (premises > 1) printf(")");
127
{ printf("(ch == %d)",x); z++; }
138
cl_cv_os_valid_filename_char=`./conftest`
139
# Workaround a problem with NFS on Solaris 7, where unlink()ed files reappear
140
# immediately under a different name and disappear only after 1. the process
141
# doing readdir() has exited and 2. waiting a second or two.
142
# Even "rm -rf conftestdir" goes into an endless loop, eating CPU time, under
145
while test -n "`ls conftestdir/.nfs* 2>/dev/null`"; do
146
echo "waiting for NFS..."
147
rm -f conftestdir/.nfs* 2>/dev/null
149
period=`expr 2 '*' $period`
151
# Now it's safe to do "rm -rf conftestdir".
155
if test -z "$cl_cv_os_valid_filename_char"; then
156
cl_cv_os_valid_filename_charset="guessing 7-bit"
158
if test "$cl_cv_os_valid_filename_char" = '((ch >= 1) && (ch != 47))'; then
159
cl_cv_os_valid_filename_charset="8-bit"
161
cl_cv_os_valid_filename_charset="7-bit"
164
AC_MSG_RESULT($cl_cv_os_valid_filename_charset)
165
if test -n "$cl_cv_os_valid_filename_char"; then
166
AC_DEFINE_UNQUOTED(VALID_FILENAME_CHAR,$cl_cv_os_valid_filename_char,[expression in ch which is true if ch is a valid character in filenames])