1 /* config.h: master configuration file, included first by all compilable
2 source files (not headers).
3
4 Copyright 1993, 1995, 1996, 1997, 2008, 2010, 2011 Karl Berry.
5 Copyright 2000, 2003, 2004, 2005 Olaf Weber.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this library; if not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef KPATHSEA_CONFIG_H
21 #define KPATHSEA_CONFIG_H
22
23 /* System defines are for non-Unix systems only. (Testing for all Unix
24 variations should be done in configure.) Presently the defines used
25 are: AMIGA DOS OS2 WIN32. I do not use any of these systems myself;
26 if you do, I'd be grateful for any changes. */
27
28 #if defined(DJGPP) || defined(__DJGPP__) || \
29 defined(CYGWIN) || defined(__CYGWIN__) || \
30 defined(CYGWIN32) || defined(__CYGWIN32__) || \
31 defined(MINGW32) || defined(__MINGW32__)
32 #define __i386_pc_gnu__
33 #endif
34
35 /* If we have either DOS or OS2, we are DOSISH. Cygwin pretends to be
36 Unix, mostly, so don't include it here. */
37 #if defined(OS2) || \
38 defined(MSDOS) || defined(__MSDOS__) || defined(DOS) || \
39 defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || \
40 defined(DJGPP) || defined(__DJGPP__) || \
41 defined(MINGW32) || defined(__MINGW32__)
42 #define DOSISH
43 #endif
44
45 /* case-insensitive filename comparisons? */
46 #if defined (DOSISH)
47 #define MONOCASE_FILENAMES
48 #endif
49
50 /* NULL device. */
51 #if defined (DOSISH)
52 #define DEV_NULL "NUL"
53 #else
54 #define DEV_NULL "/dev/null"
55 #endif
56
57 #if defined (WIN32) && !defined (__STDC__)
58 #define __STDC__ 1
59 #endif
60
61 /* System dependencies that are figured out by `configure'. */
62 #include <kpathsea/c-auto.h>
63
64 #ifdef __DJGPP__
65 #include <fcntl.h> /* for long filenames' stuff */
66 #include <dir.h> /* for `getdisk' */
67 #include <io.h> /* for `setmode' */
68 #endif
69
70 /* Some drivers have partially integrated kpathsea changes. */
71 #ifndef KPATHSEA
72 #define KPATHSEA 34
73 #endif
74
75 #ifdef __MINGW32__
76 /* In mingw32, the eof() function is part of the !_NO_OLDNAMES section
77 of <io.h>, that is read in automatically via <unistd.h>. We cannot
78 allow that because web2c/lib/eofeoln.c defines a private,
79 incompatible function named eof().
80 But many of the other things defined via !_NO_OLDNAMES are needed,
81 so #define _NO_OLDNAMES cannot be used. So, temporarily define eof
82 as a macro.
83 */
84 #define eof saved_eof
85 #include <kpathsea/c-std.h> /* <stdio.h>, <math.h>, etc. */
86 #undef eof
87 #else
88 #include <kpathsea/c-std.h> /* <stdio.h>, <math.h>, etc. */
89 #endif
90
91 #include <kpathsea/c-proto.h> /* KPSEDLL. */
92
93 /*
94 This must be included after "c-proto.h"
95 but before "lib.h". FP.
96 */
97 #if defined (WIN32) || defined (_WIN32)
98 #include <kpathsea/knj.h>
99 #ifdef __MINGW32__
100 #include <kpathsea/mingw32.h>
101 #else
102 #include <kpathsea/win32lib.h>
103 #endif
104 #endif
105
106 #if defined(WIN32) || defined(WRAP_SNPRINTF)
107 /* All Unix systems known to us have snprintf() and vsnprintf(),
108 while all known Windows systems have _snprintf() and _vsnprintf().
109
110 Consider a call
111 RET = snprintf(BUF, SIZE, FMT, ...)
112 and let LEN be the number that would be written to BUF if SIZE were
113 sufficiently large (not counting the trailing null byte).
114
115 C99 requires that snprintf
116 (A) modifies at most the first SIZE bytes of BUF,
117 (B) writes a trailing null byte except when SIZE=0, and
118 (C) always returns LEN.
119
120 All known implementations (except some ancient buggy ones, e.g., for
121 64-bit Solaris 7 from Oct. 1998) satisfy (A). As long as LEN<SIZE
122 they all write a trailing null byte and return LEN.
123
124 Condition (C) is, however, violated for LEN>=SIZE by some older
125 implementations (SUSv2, glibc <= 2.0.6, etc.) and for Windows even
126 (B) is violated..
127
128 TeX Live does not require the full C99 semantics, but will need that
129 (1) there is always a trailing null byte, and
130 (2) for LEN>=SIZE the return value is either >=SIZE or <0, i.e.,
131 (unsigned)RET >= (unsigned)SIZE.
132
133 A violation of (2) is detected by configure (except when cross
134 compiling) and by a runtime check in the initialization routine
135 kpathsea_set_program_name.
136
137 A violation of (1) is handled here through static inline wrapper
138 functions. */
139
140
141 #undef snprintf
142 #undef vsnprintf
143
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147
148 static inline int
kpse_vsnprintf(char * str,size_t size,const char * format,va_list ap)149 kpse_vsnprintf (char *str, size_t size, const char *format, va_list ap)
150 {
151 #ifdef WIN32
152 int ret = _vsnprintf (str, size, format, ap);
153 #else
154 int ret = vsnprintf (str, size, format, ap);
155 #endif
156 if (size > 0 && (unsigned)ret >= (unsigned)size)
157 str [size - 1] = '\0';
158 return ret;
159 }
160
161 static inline int
kpse_snprintf(char * str,size_t size,const char * format,...)162 kpse_snprintf (char *str, size_t size, const char *format, ...)
163 {
164 int ret;
165 va_list ap;
166
167 va_start (ap, format);
168 ret = kpse_vsnprintf (str, size, format, ap);
169 va_end (ap);
170 return ret;
171 }
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #define snprintf kpse_snprintf
178 #define vsnprintf kpse_vsnprintf
179
180 #endif /* WIN32 || WRAP_SNPRINTF */
181
182 /* Transform filename characters for use in hash tables. */
183 #if defined(MONOCASE_FILENAMES)
184 #if defined(WIN32) && !defined(__i386_pc_gnu__)
185 /* This is way faster under Win32. */
186 #define TRANSFORM(x) ((unsigned)CharLower((LPTSTR)(BYTE)(x)))
187 #else
188 #define TRANSFORM(x) (tolower(x))
189 #endif
190 #else
191 #define TRANSFORM(x) (x)
192 #endif
193
194 #include <kpathsea/debug.h> /* Runtime tracing. */
195 #include <kpathsea/lib.h> /* STREQ, etc. */
196 #include <kpathsea/types.h> /* <sys/types.h>, boolean, string, etc. */
197 #include <kpathsea/progname.h> /* for kpse_invocation_*name */
198
199
200 /* If you want to find subdirectories in a directory with non-Unix
201 semantics (specifically, if a directory with no subdirectories does
202 not have exactly two links), define this. */
203 #if !defined (VMS) && !defined (VMCMS)
204 #if !defined (DOSISH) || defined(__DJGPP__)
205 /* Surprise! DJGPP returns st_nlink exactly like on Unix. */
206 #define ST_NLINK_TRICK
207 #endif /* either not DOSISH or __DJGPP__ */
208 #endif /* not DOS and not VMS and not VMCMS */
209
210 #ifdef AMIGA
211 /* No popen/pclose on Amiga, but rather than put #ifdef's in tex-make.c,
212 let's get rid of the functions here. (CallMF will automatically
213 generate fonts.) pclose must not be simply empty, since it still
214 occurs in a comparison. */
215 #define popen(cmd, mode) NULL
216 #define pclose(file) 0
217 #endif /* AMIGA */
218
219 #ifdef OS2
220 #define access ln_access
221 #define chmod ln_chmod
222 #define creat ln_creat
223 #define fopen ln_fopen
224 #define freopen ln_freopen
225 #define lstat ln_lstat
226 #define open ln_open
227 #define remove ln_remove
228 #define rename ln_rename
229 #define sopen ln_sopen
230 #define stat ln_stat
231 #define unlink ln_unlink
232 #endif /* OS2 */
233
234 #endif /* not KPATHSEA_CONFIG_H */
235