1 | /* system-dependent definitions for orxonox |
---|
2 | |
---|
3 | Written for GNU fileutils. |
---|
4 | Adapted for autoproject by James R. Van Zandt. |
---|
5 | |
---|
6 | Copyright (C) 89, 91, 92, 93, 94, 1996 Free Software Foundation, Inc. |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | This program is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software Foundation, |
---|
20 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
---|
21 | |
---|
22 | #if HAVE_CONFIG_H |
---|
23 | #include "config.h" |
---|
24 | #endif /* HAVE_CONFIG_H */ |
---|
25 | |
---|
26 | /* Include sys/types.h before this file. */ |
---|
27 | |
---|
28 | #include <sys/stat.h> |
---|
29 | |
---|
30 | #ifdef STAT_MACROS_BROKEN |
---|
31 | #undef S_ISBLK |
---|
32 | #undef S_ISCHR |
---|
33 | #undef S_ISDIR |
---|
34 | #undef S_ISFIFO |
---|
35 | #undef S_ISLNK |
---|
36 | #undef S_ISMPB |
---|
37 | #undef S_ISMPC |
---|
38 | #undef S_ISNWK |
---|
39 | #undef S_ISREG |
---|
40 | #undef S_ISSOCK |
---|
41 | #endif /* STAT_MACROS_BROKEN. */ |
---|
42 | |
---|
43 | #ifndef S_IFMT |
---|
44 | #define S_IFMT 0170000 |
---|
45 | #endif |
---|
46 | #if !defined(S_ISBLK) && defined(S_IFBLK) |
---|
47 | #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) |
---|
48 | #endif |
---|
49 | #if !defined(S_ISCHR) && defined(S_IFCHR) |
---|
50 | #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) |
---|
51 | #endif |
---|
52 | #if !defined(S_ISDIR) && defined(S_IFDIR) |
---|
53 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) |
---|
54 | #endif |
---|
55 | #if !defined(S_ISREG) && defined(S_IFREG) |
---|
56 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
---|
57 | #endif |
---|
58 | #if !defined(S_ISFIFO) && defined(S_IFIFO) |
---|
59 | #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) |
---|
60 | #endif |
---|
61 | #if !defined(S_ISLNK) && defined(S_IFLNK) |
---|
62 | #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) |
---|
63 | #endif |
---|
64 | #if !defined(S_ISSOCK) && defined(S_IFSOCK) |
---|
65 | #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) |
---|
66 | #endif |
---|
67 | #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */ |
---|
68 | #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) |
---|
69 | #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) |
---|
70 | #endif |
---|
71 | #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ |
---|
72 | #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) |
---|
73 | #endif |
---|
74 | |
---|
75 | #ifndef S_IEXEC |
---|
76 | #define S_IEXEC S_IXUSR |
---|
77 | #endif |
---|
78 | |
---|
79 | #ifndef S_IXUSR |
---|
80 | #define S_IXUSR S_IEXEC |
---|
81 | #endif |
---|
82 | #ifndef S_IXGRP |
---|
83 | #define S_IXGRP (S_IEXEC >> 3) |
---|
84 | #endif |
---|
85 | #ifndef S_IXOTH |
---|
86 | #define S_IXOTH (S_IEXEC >> 6) |
---|
87 | #endif |
---|
88 | #ifndef S_IXUGO |
---|
89 | #define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) |
---|
90 | #endif |
---|
91 | |
---|
92 | #if !defined(HAVE_MKFIFO) |
---|
93 | #define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0)) |
---|
94 | #endif |
---|
95 | |
---|
96 | #ifdef HAVE_SYS_PARAM_H |
---|
97 | #include <sys/param.h> |
---|
98 | #endif |
---|
99 | |
---|
100 | /* <unistd.h> should be included before any preprocessor test |
---|
101 | of _POSIX_VERSION. */ |
---|
102 | #ifdef HAVE_UNISTD_H |
---|
103 | #include <unistd.h> |
---|
104 | #endif |
---|
105 | |
---|
106 | #ifndef STDIN_FILENO |
---|
107 | #define STDIN_FILENO 0 |
---|
108 | #endif |
---|
109 | |
---|
110 | #ifndef STDOUT_FILENO |
---|
111 | #define STDOUT_FILENO 1 |
---|
112 | #endif |
---|
113 | |
---|
114 | #ifndef STDERR_FILENO |
---|
115 | #define STDERR_FILENO 2 |
---|
116 | #endif |
---|
117 | |
---|
118 | /* FIXME: Don't use _POSIX_VERSION. */ |
---|
119 | #ifndef _POSIX_VERSION |
---|
120 | off_t lseek (); |
---|
121 | #endif |
---|
122 | |
---|
123 | #ifdef TM_IN_SYS_TIME |
---|
124 | #include <sys/time.h> |
---|
125 | #else |
---|
126 | #include <time.h> |
---|
127 | #endif |
---|
128 | |
---|
129 | /* Since major is a function on SVR4, we can't use `ifndef major'. */ |
---|
130 | #ifdef MAJOR_IN_MKDEV |
---|
131 | #include <sys/mkdev.h> |
---|
132 | #define HAVE_MAJOR |
---|
133 | #endif |
---|
134 | #ifdef MAJOR_IN_SYSMACROS |
---|
135 | #include <sys/sysmacros.h> |
---|
136 | #define HAVE_MAJOR |
---|
137 | #endif |
---|
138 | #ifdef major /* Might be defined in sys/types.h. */ |
---|
139 | #define HAVE_MAJOR |
---|
140 | #endif |
---|
141 | |
---|
142 | #ifndef HAVE_MAJOR |
---|
143 | #define major(dev) (((dev) >> 8) & 0xff) |
---|
144 | #define minor(dev) ((dev) & 0xff) |
---|
145 | #define makedev(maj, min) (((maj) << 8) | (min)) |
---|
146 | #endif |
---|
147 | #undef HAVE_MAJOR |
---|
148 | |
---|
149 | #ifdef HAVE_UTIME_H |
---|
150 | #include <utime.h> |
---|
151 | #endif |
---|
152 | |
---|
153 | /* Some systems (even some that do have <utime.h>) don't declare this |
---|
154 | structure anywhere. */ |
---|
155 | #ifndef HAVE_STRUCT_UTIMBUF |
---|
156 | struct utimbuf |
---|
157 | { |
---|
158 | long actime; |
---|
159 | long modtime; |
---|
160 | }; |
---|
161 | #endif |
---|
162 | |
---|
163 | /* Don't use bcopy! Use memmove if source and destination may overlap, |
---|
164 | memcpy otherwise. */ |
---|
165 | |
---|
166 | #ifdef HAVE_STRING_H |
---|
167 | # if !STDC_HEADERS && HAVE_MEMORY_H |
---|
168 | # include <memory.h> |
---|
169 | # endif |
---|
170 | # include <string.h> |
---|
171 | #else |
---|
172 | # include <strings.h> |
---|
173 | char *memchr (); |
---|
174 | #endif |
---|
175 | |
---|
176 | #include <errno.h> |
---|
177 | #ifndef errno |
---|
178 | extern int errno; |
---|
179 | #endif |
---|
180 | |
---|
181 | #ifdef STDC_HEADERS |
---|
182 | #define getopt system_getopt |
---|
183 | #include <stdlib.h> |
---|
184 | #undef getopt |
---|
185 | #else /* not STDC_HEADERS */ |
---|
186 | char *getenv (); |
---|
187 | #endif /* STDC_HEADERS */ |
---|
188 | |
---|
189 | /* The following test is to work around the gross typo in |
---|
190 | systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE |
---|
191 | is defined to 0, not 1. */ |
---|
192 | #if !EXIT_FAILURE |
---|
193 | # undef EXIT_FAILURE |
---|
194 | # define EXIT_FAILURE 1 |
---|
195 | #endif |
---|
196 | |
---|
197 | #ifndef EXIT_SUCCESS |
---|
198 | # define EXIT_SUCCESS 0 |
---|
199 | #endif |
---|
200 | |
---|
201 | #ifdef HAVE_FCNTL_H |
---|
202 | #include <fcntl.h> |
---|
203 | #else |
---|
204 | #include <sys/file.h> |
---|
205 | #endif |
---|
206 | |
---|
207 | #ifndef SEEK_SET |
---|
208 | #define SEEK_SET 0 |
---|
209 | #define SEEK_CUR 1 |
---|
210 | #define SEEK_END 2 |
---|
211 | #endif |
---|
212 | #ifndef F_OK |
---|
213 | #define F_OK 0 |
---|
214 | #define X_OK 1 |
---|
215 | #define W_OK 2 |
---|
216 | #define R_OK 4 |
---|
217 | #endif |
---|
218 | |
---|
219 | #ifdef HAVE_DIRENT_H |
---|
220 | # include <dirent.h> |
---|
221 | # define NLENGTH(direct) (strlen((direct)->d_name)) |
---|
222 | #else /* not HAVE_DIRENT_H */ |
---|
223 | # define dirent direct |
---|
224 | # define NLENGTH(direct) ((direct)->d_namlen) |
---|
225 | # ifdef HAVE_SYS_NDIR_H |
---|
226 | # include <sys/ndir.h> |
---|
227 | # endif /* HAVE_SYS_NDIR_H */ |
---|
228 | # ifdef HAVE_SYS_DIR_H |
---|
229 | # include <sys/dir.h> |
---|
230 | # endif /* HAVE_SYS_DIR_H */ |
---|
231 | # ifdef HAVE_NDIR_H |
---|
232 | # include <ndir.h> |
---|
233 | # endif /* HAVE_NDIR_H */ |
---|
234 | #endif /* HAVE_DIRENT_H */ |
---|
235 | |
---|
236 | #ifdef CLOSEDIR_VOID |
---|
237 | /* Fake a return value. */ |
---|
238 | #define CLOSEDIR(d) (closedir (d), 0) |
---|
239 | #else |
---|
240 | #define CLOSEDIR(d) closedir (d) |
---|
241 | #endif |
---|
242 | |
---|
243 | /* Get or fake the disk device blocksize. |
---|
244 | Usually defined by sys/param.h (if at all). */ |
---|
245 | #ifndef DEV_BSIZE |
---|
246 | #ifdef BSIZE |
---|
247 | #define DEV_BSIZE BSIZE |
---|
248 | #else /* !BSIZE */ |
---|
249 | #define DEV_BSIZE 4096 |
---|
250 | #endif /* !BSIZE */ |
---|
251 | #endif /* !DEV_BSIZE */ |
---|
252 | |
---|
253 | /* Extract or fake data from a `struct stat'. |
---|
254 | ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes. |
---|
255 | ST_NBLOCKS: Number of 512-byte blocks in the file |
---|
256 | (including indirect blocks). */ |
---|
257 | #ifndef HAVE_ST_BLOCKS |
---|
258 | # define ST_BLKSIZE(statbuf) DEV_BSIZE |
---|
259 | # if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE. */ |
---|
260 | # define ST_NBLOCKS(statbuf) (((statbuf).st_size + 512 - 1) / 512) |
---|
261 | # else /* !_POSIX_SOURCE && BSIZE */ |
---|
262 | # define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size)) |
---|
263 | # endif /* !_POSIX_SOURCE && BSIZE */ |
---|
264 | #else /* HAVE_ST_BLOCKS */ |
---|
265 | /* Some systems, like Sequents, return st_blksize of 0 on pipes. */ |
---|
266 | # define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \ |
---|
267 | ? (statbuf).st_blksize : DEV_BSIZE) |
---|
268 | # if defined(hpux) || defined(__hpux__) || defined(__hpux) |
---|
269 | /* HP-UX counts st_blocks in 1024-byte units. |
---|
270 | This loses when mixing HP-UX and BSD filesystems with NFS. */ |
---|
271 | # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 2) |
---|
272 | # else /* !hpux */ |
---|
273 | # if defined(_AIX) && defined(_I386) |
---|
274 | /* AIX PS/2 counts st_blocks in 4K units. */ |
---|
275 | # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * 8) |
---|
276 | # else /* not AIX PS/2 */ |
---|
277 | # if defined(_CRAY) |
---|
278 | # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks * ST_BLKSIZE(statbuf)/512) |
---|
279 | # else /* not AIX PS/2 nor CRAY */ |
---|
280 | # define ST_NBLOCKS(statbuf) ((statbuf).st_blocks) |
---|
281 | # endif /* not _CRAY */ |
---|
282 | # endif /* not AIX PS/2 */ |
---|
283 | # endif /* !hpux */ |
---|
284 | #endif /* HAVE_ST_BLOCKS */ |
---|
285 | |
---|
286 | /* Convert B 512-byte blocks to kilobytes if K is nonzero, |
---|
287 | otherwise return it unchanged. */ |
---|
288 | #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b)) |
---|
289 | |
---|
290 | #ifndef RETSIGTYPE |
---|
291 | #define RETSIGTYPE void |
---|
292 | #endif |
---|
293 | |
---|
294 | #ifdef __GNUC__ |
---|
295 | # undef alloca |
---|
296 | # define alloca __builtin_alloca |
---|
297 | #else |
---|
298 | # ifdef HAVE_ALLOCA_H |
---|
299 | # include <alloca.h> |
---|
300 | # else |
---|
301 | # ifndef _AIX |
---|
302 | /* AIX alloca decl has to be the first thing in the file, bletch! */ |
---|
303 | char *alloca (); |
---|
304 | # endif |
---|
305 | # endif |
---|
306 | #endif |
---|
307 | |
---|
308 | #include <ctype.h> |
---|
309 | |
---|
310 | /* Jim Meyering writes: |
---|
311 | |
---|
312 | "... Some ctype macros are valid only for character codes that |
---|
313 | isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when |
---|
314 | using /bin/cc or gcc but without giving an ansi option). So, all |
---|
315 | ctype uses should be through macros like ISPRINT... If |
---|
316 | STDC_HEADERS is defined, then autoconf has verified that the ctype |
---|
317 | macros don't need to be guarded with references to isascii. ... |
---|
318 | Defining isascii to 1 should let any compiler worth its salt |
---|
319 | eliminate the && through constant folding." |
---|
320 | |
---|
321 | Bruno Haible adds: |
---|
322 | |
---|
323 | "... Furthermore, isupper(c) etc. have an undefined result if c is |
---|
324 | outside the range -1 <= c <= 255. One is tempted to write isupper(c) |
---|
325 | with c being of type `char', but this is wrong if c is an 8-bit |
---|
326 | character >= 128 which gets sign-extended to a negative value. |
---|
327 | The macro ISUPPER protects against this as well." */ |
---|
328 | |
---|
329 | #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) |
---|
330 | #define IN_CTYPE_DOMAIN(c) 1 |
---|
331 | #else |
---|
332 | #define IN_CTYPE_DOMAIN(c) isascii(c) |
---|
333 | #endif |
---|
334 | |
---|
335 | #ifdef isblank |
---|
336 | #define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c)) |
---|
337 | #else |
---|
338 | #define ISBLANK(c) ((c) == ' ' || (c) == '\t') |
---|
339 | #endif |
---|
340 | #ifdef isgraph |
---|
341 | #define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c)) |
---|
342 | #else |
---|
343 | #define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c)) |
---|
344 | #endif |
---|
345 | |
---|
346 | #define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c)) |
---|
347 | #define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c)) |
---|
348 | #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c)) |
---|
349 | #define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c)) |
---|
350 | #define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c)) |
---|
351 | #define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c)) |
---|
352 | #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) |
---|
353 | #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c)) |
---|
354 | #define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c)) |
---|
355 | #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) |
---|
356 | |
---|
357 | /* ISDIGIT differs from ISDIGIT_LOCALE, as follows: |
---|
358 | - Its arg may be any int or unsigned int; it need not be an unsigned char. |
---|
359 | - It's guaranteed to evaluate its argument exactly once. |
---|
360 | - It's typically faster. |
---|
361 | Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that |
---|
362 | only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless |
---|
363 | it's important to use the locale's definition of `digit' even when the |
---|
364 | host does not conform to Posix. */ |
---|
365 | #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) |
---|
366 | |
---|
367 | #ifndef __P |
---|
368 | #if defined (__GNUC__) || (defined (__STDC__) && __STDC__) |
---|
369 | #define __P(args) args |
---|
370 | #else |
---|
371 | #define __P(args) () |
---|
372 | #endif /* GCC. */ |
---|
373 | #endif /* Not __P. */ |
---|
374 | |
---|
375 | /* Take care of NLS matters. */ |
---|
376 | |
---|
377 | #if HAVE_LOCALE_H |
---|
378 | # include <locale.h> |
---|
379 | #endif |
---|
380 | #if !HAVE_SETLOCALE |
---|
381 | # define setlocale(Category, Locale) /* empty */ |
---|
382 | #endif |
---|
383 | |
---|
384 | #if ENABLE_NLS |
---|
385 | # include <libintl.h> |
---|
386 | # define _(Text) gettext (Text) |
---|
387 | #else |
---|
388 | # undef bindtextdomain |
---|
389 | # define bindtextdomain(Domain, Directory) /* empty */ |
---|
390 | # undef textdomain |
---|
391 | # define textdomain(Domain) /* empty */ |
---|
392 | # define _(Text) Text |
---|
393 | #endif |
---|
394 | |
---|
395 | #define STREQ(a,b) (strcmp((a), (b)) == 0) |
---|