Imported Upstream version 4.0.18
[platform/upstream/mtools.git] / sysincludes.h
1 /*  Copyright 1996-1999,2001,2002,2007-2009 Alain Knaff.
2  *  This file is part of mtools.
3  *
4  *  Mtools is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  Mtools is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  * System includes for mtools
18  */
19
20 #ifndef SYSINCLUDES_H
21 #define SYSINCLUDES_H
22
23 #define _LARGEFILE64_SOURCE
24 #define _GNU_SOURCE
25
26 #include "config.h"
27
28
29 /* OS/2 needs __inline__, but for some reason is not autodetected */
30 #ifdef __EMX__
31 # ifndef inline
32 #  define inline __inline__
33 # endif
34 #endif
35
36 /***********************************************************************/
37 /*                                                                     */
38 /* OS dependancies which cannot be covered by the autoconfigure script */
39 /*                                                                     */
40 /***********************************************************************/
41
42
43 #ifdef OS_aux
44 /* A/UX needs POSIX_SOURCE, just as AIX does. Unlike SCO and AIX, it seems
45  * to prefer TERMIO over TERMIOS */
46 #ifndef _POSIX_SOURCE
47 # define _POSIX_SOURCE
48 #endif
49 #ifndef POSIX_SOURCE
50 # define POSIX_SOURCE
51 #endif
52
53 #endif
54
55
56 /* On AIX, we have to prefer strings.h, as string.h lacks a prototype 
57  * for strcasecmp. On most other architectures, it's string.h which seems
58  * to be more complete */
59 #if (defined OS_aix && defined HAVE_STRINGS_H)
60 # undef HAVE_STRING_H
61 #endif
62
63
64 #ifdef OS_ultrix
65 /* on ultrix, if termios present, prefer it instead of termio */
66 # ifdef HAVE_TERMIOS_H
67 #  undef HAVE_TERMIO_H
68 # endif
69 #endif
70
71 #ifdef OS_linux_gnu
72 /* RMS strikes again */
73 # ifndef OS_linux
74 #  define OS_linux
75 # endif
76 #endif
77
78 /* For compiling with MingW, use the following configure line
79
80 ac_cv_func_setpgrp_void=yes ../mtools/configure --build=i386-linux-gnu --host=i386-mingw32 --disable-floppyd --without-x --disable-raw-term --srcdir ../mtools
81
82  */
83 #ifdef OS_mingw32
84 #ifndef OS_mingw32msvc
85 #define OS_mingw32msvc
86 #endif
87 #endif
88
89 #ifndef HAVE_CADDR_T
90 typedef void *caddr_t;
91 #endif
92
93
94 /***********************************************************************/
95 /*                                                                     */
96 /* Compiler dependancies                                               */
97 /*                                                                     */
98 /***********************************************************************/
99
100
101 #if defined __GNUC__ && defined __STDC__
102 /* gcc -traditional doesn't have PACKED, UNUSED and NORETURN */
103 # define PACKED __attribute__ ((packed))
104 # if __GNUC__ == 2 && __GNUC_MINOR__ > 6 || __GNUC__ >= 3
105 /* gcc 2.6.3 doesn't have "unused" */           /* mool */
106 #  define UNUSED(x) x __attribute__ ((unused));x
107 #  define UNUSEDP __attribute__ ((unused))
108 # else
109 #  define UNUSED(x) x
110 #  define UNUSEDP /* */
111 # endif
112 # define NORETURN __attribute__ ((noreturn))
113 #else
114 # define UNUSED(x) x
115 #  define UNUSEDP /* */
116 # define PACKED /* */
117 # define NORETURN /* */
118 #endif
119
120
121 /***********************************************************************/
122 /*                                                                     */
123 /* Include files                                                       */
124 /*                                                                     */
125 /***********************************************************************/
126
127 #define _LARGEFILE64_SOURCE
128 #define _GNU_SOURCE
129
130
131 #ifdef HAVE_FEATURES_H
132 # include <features.h>
133 #endif
134
135
136 #include <sys/types.h>
137
138 #ifdef HAVE_STDLIB_H
139 # include <stdlib.h>
140 #endif
141
142 #include <stdio.h>
143 #include <ctype.h>
144
145 #ifdef HAVE_UNISTD_H
146 # include <unistd.h>
147 #endif
148
149 #ifdef HAVE_LINUX_UNISTD_H
150 # include <linux/unistd.h>
151 #endif
152
153 #ifdef HAVE_LIBC_H
154 # include <libc.h>
155 #endif
156
157 #ifdef HAVE_GETOPT_H
158 # include <getopt.h>
159 #endif
160
161 #ifdef HAVE_FCNTL_H
162 # include <fcntl.h>
163 #endif
164
165 #ifdef HAVE_LIMITS_H
166 # include <limits.h>
167 #endif
168
169 #ifdef HAVE_SYS_FILE_H
170 # include <sys/file.h>
171 #endif
172
173 #ifdef HAVE_SYS_IOCTL_H
174 # ifndef sunos
175 # include <sys/ioctl.h>
176 #endif
177 #endif
178 /* if we don't have sys/ioctl.h, we rely on unistd to supply a prototype
179  * for it. If it doesn't, we'll only get a (harmless) warning. The idea
180  * is to get mtools compile on as many platforms as possible, but to not
181  * suppress warnings if the platform is broken, as long as these warnings do
182  * not prevent compilation */
183
184 #ifdef TIME_WITH_SYS_TIME
185 # include <sys/time.h>
186 # include <time.h>
187 #else
188 # ifdef HAVE_SYS_TIME_H
189 #  include <sys/time.h>
190 # else
191 #  include <time.h>
192 # endif
193 #endif
194
195 #ifndef NO_TERMIO
196 # ifdef HAVE_TERMIO_H
197 #  include <termio.h>
198 # elif defined HAVE_SYS_TERMIO_H
199 #  include <sys/termio.h>
200 # endif
201 # if !defined OS_ultrix || !(defined HAVE_TERMIO_H || defined HAVE_TERMIO_H)
202 /* on Ultrix, avoid double inclusion of both termio and termios */
203 #  ifdef HAVE_TERMIOS_H
204 #   include <termios.h>
205 #  elif defined HAVE_SYS_TERMIOS_H
206 #   include <sys/termios.h>
207 #  endif
208 # endif
209 # ifdef HAVE_STTY_H
210 #  include <sgtty.h>
211 # endif
212 #endif
213
214
215 #if defined(OS_aux) && !defined(_SYSV_SOURCE)
216 /* compiled in POSIX mode, this is left out unless SYSV */
217 #define NCC     8
218 struct termio {
219         unsigned short  c_iflag;        /* input modes */
220         unsigned short  c_oflag;        /* output modes */
221         unsigned short  c_cflag;        /* control modes */
222         unsigned short  c_lflag;        /* line discipline modes */
223         char    c_line;                 /* line discipline */
224         unsigned char   c_cc[NCC];      /* control chars */
225 };
226 extern int ioctl(int fildes, int request, void *arg);
227 #endif
228
229
230 #ifdef HAVE_MNTENT_H
231 # include <mntent.h>
232 #endif
233
234 #ifdef HAVE_SYS_PARAM_H
235 # include <sys/param.h>
236 #endif
237
238 /* Can only be done here, as BSD is defined in sys/param.h :-( */
239 #if defined BSD || defined __BEOS__
240 /* on BSD and on BEOS, we prefer gettimeofday, ... */
241 # ifdef HAVE_GETTIMEOFDAY
242 #  undef HAVE_TZSET
243 # endif
244 #else /* BSD */
245 /* ... elsewhere we prefer tzset */
246 # ifdef HAVE_TZSET
247 #  undef HAVE_GETTIMEOFDAY
248 # endif
249 #endif
250
251
252 #include <sys/stat.h>
253
254 #include <errno.h>
255 #ifndef errno
256 extern int errno;
257 #endif
258
259 #ifndef OS_mingw32msvc
260 #include <pwd.h>
261 #else
262 typedef unsigned int uid_t;
263 #endif
264
265
266 #ifdef HAVE_STRING_H
267 # include <string.h>
268 #else
269 # ifdef HAVE_STRINGS_H
270 #  include <strings.h>
271 # endif
272 #endif
273
274 #ifdef HAVE_MEMORY_H
275 # include <memory.h>
276 #endif
277
278 #ifdef HAVE_MALLOC_H
279 # include <malloc.h>
280 #endif
281
282 #ifdef HAVE_SIGNAL_H
283 # include <signal.h>
284 #else
285 # ifdef HAVE_SYS_SIGNAL_H
286 #  include <sys/signal.h>
287 # endif
288 #endif
289
290 #ifdef HAVE_UTIME_H
291 # include <utime.h>
292 #endif
293
294 #ifdef HAVE_SYS_WAIT_H
295 # ifndef DONT_NEED_WAIT
296 #  include <sys/wait.h>
297 # endif
298 #endif
299
300 #ifdef HAVE_WCHAR_H
301 # include <wchar.h>
302 # ifndef HAVE_PUTWC
303 #  define putwc(c,f) fprintf((f),"%lc",(c))
304 # endif
305 #else
306 # define wcscmp strcmp
307 # define wcscasecmp strcasecmp
308 # define wcsdup strdup
309 # define wcslen strlen
310 # define wcschr strchr
311 # define wcspbrk strpbrk
312 # define wchar_t char
313 # define putwc putc
314 #endif
315
316 #ifdef HAVE_WCTYPE_H
317 # include <wctype.h>
318 #else
319 # define towupper(x) toupper(x)
320 # define towlower(x) tolower(x)
321 # define iswupper(x) isupper(x)
322 # define iswlower(x) islower(x)
323 # define iswcntrl(x) iscntrl(x)
324 #endif
325
326 #ifdef HAVE_LOCALE_H
327 # include <locale.h>
328 #endif
329
330 #ifdef USE_FLOPPYD
331
332 #ifdef HAVE_SYS_SOCKET_H
333 #include <sys/socket.h>
334 #endif
335
336 #ifdef HAVE_NETINET_IN_H
337 #include <netinet/in.h>
338 #endif
339
340 #ifdef HAVE_ARPA_INET_H
341 #include <arpa/inet.h>
342 #endif
343
344 #ifdef HAVE_NETDB_H
345 #include <netdb.h>
346 #endif
347
348 #ifdef HAVE_X11_XAUTH_H
349 #include <X11/Xauth.h>
350 #endif
351
352 #ifdef HAVE_X11_XLIB_H
353 #include <X11/Xlib.h>
354 #endif
355
356 #endif
357
358 #ifndef INADDR_NONE
359 #define INADDR_NONE (-1)
360 #endif
361
362
363 #ifdef sgi
364 #define MSGIHACK __EXTENSIONS__
365 #undef __EXTENSIONS__
366 #endif
367 #include <math.h>
368 #ifdef sgi
369 #define __EXTENSIONS__ MSGIHACK
370 #undef MSGIHACK
371 #endif
372
373 /* missing functions */
374 #ifndef HAVE_SRANDOM
375 # ifdef OS_mingw32msvc
376 #  define srandom srand
377 # else
378 #  define srandom srand48
379 # endif
380 #endif
381
382 #ifndef HAVE_RANDOM
383 # ifdef OS_mingw32msvc
384 #  define random (long)rand
385 # else
386 #  define random (long)lrand48
387 # endif
388 #endif
389
390 #ifndef HAVE_STRCHR
391 # define strchr index
392 #endif
393
394 #ifndef HAVE_STRRCHR
395 # define strrchr rindex
396 #endif
397
398
399 #ifndef HAVE_STRDUP
400 extern char *strdup(const char *str);
401 #endif /* HAVE_STRDUP */
402
403
404 #ifndef HAVE_MEMCPY
405 extern char *memcpy(char *s1, const char *s2, size_t n);
406 #endif
407
408 #ifndef HAVE_MEMSET
409 extern char *memset(char *s, char c, size_t n);
410 #endif /* HAVE_MEMSET */
411
412
413 #ifndef HAVE_STRPBRK
414 extern char *strpbrk(const char *string, const char *brkset);
415 #endif /* HAVE_STRPBRK */
416
417
418 #ifndef HAVE_STRTOUL
419 unsigned long strtoul(const char *string, char **eptr, int base);
420 #endif /* HAVE_STRTOUL */
421
422 #ifndef HAVE_STRSPN
423 size_t strspn(const char *s, const char *accept);
424 #endif /* HAVE_STRSPN */
425
426 #ifndef HAVE_STRCSPN
427 size_t strcspn(const char *s, const char *reject);
428 #endif /* HAVE_STRCSPN */
429
430 #ifndef HAVE_STRERROR
431 char *strerror(int errno);
432 #endif
433
434 #ifndef HAVE_ATEXIT
435 int atexit(void (*function)(void)); 
436
437 #ifndef HAVE_ON_EXIT
438 void myexit(int code) NORETURN;
439 #define exit myexit
440 #endif
441
442 #endif
443
444
445 #ifndef HAVE_MEMMOVE
446 # define memmove(DST, SRC, N) bcopy(SRC, DST, N)
447 #endif
448
449 #ifndef HAVE_STRCASECMP
450 int strcasecmp(const char *s1, const char *s2);
451 #endif
452
453 #ifndef HAVE_STRNCASECMP
454 int strncasecmp(const char *s1, const char *s2, size_t n);
455 #endif
456
457 #ifndef HAVE_GETPASS
458 char *getpass(const char *prompt);
459 #endif
460
461 #ifdef HAVE_WCHAR_H
462
463 # ifndef HAVE_WCSDUP
464 wchar_t *wcsdup(const wchar_t *wcs);
465 # endif
466
467 # ifndef HAVE_WCSCASECMP
468 int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
469 # endif
470
471 # ifndef HAVE_WCSNLEN
472 size_t wcsnlen(const wchar_t *wcs, size_t l);
473 # endif
474
475 #endif
476
477 #if 0
478 #ifndef HAVE_BASENAME
479 const char *basename(const char *filename);
480 #endif
481 #endif
482
483 const char *_basename(const char *filename);
484
485 void _stripexe(char *filename);
486
487 #ifndef __STDC__
488 # ifndef signed
489 #  define signed /**/
490 # endif 
491 #endif /* !__STDC__ */
492
493
494
495 /***************************************************************************/
496 /*                                                                         */
497 /* Prototypes for systems where the functions exist but not the prototypes */
498 /*                                                                         */
499 /***************************************************************************/
500
501
502
503 /* prototypes which might be missing on some platforms, even if the functions
504  * are present.  Do not declare argument types, in order to avoid conflict
505  * on platforms where the prototypes _are_ correct.  Indeed, for most of
506  * these, there are _several_ "correct" parameter definitions, and not all
507  * platforms use the same.  For instance, some use the const attribute for
508  * strings not modified by the function, and others do not.  By using just
509  * the return type, which rarely changes, we avoid these problems.
510  */
511
512 /* Correction:  Now it seems that even return values are not standardized :-(
513   For instance  DEC-ALPHA, OSF/1 3.2d uses ssize_t as a return type for read
514   and write.  NextStep uses a non-void return value for exit, etc.  With the
515   advent of 64 bit system, we'll expect more of these problems in the future.
516   Better uncomment the lot, except on SunOS, which is known to have bad
517   incomplete files.  Add other OS'es with incomplete include files as needed
518   */
519 #if (defined OS_sunos || defined OS_ultrix)
520 int read();
521 int write();
522 int fflush();
523 char *strdup();
524 int strcasecmp();
525 int strncasecmp();
526 char *getenv();
527 unsigned long strtoul();
528 int pclose();
529 void exit();
530 char *getpass();
531 int atoi();
532 FILE *fdopen();
533 FILE *popen();
534 #endif
535
536 #ifndef MAXPATHLEN
537 # ifdef PATH_MAX
538 #  define MAXPATHLEN PATH_MAX
539 # else
540 #  define MAXPATHLEN 1024
541 # endif
542 #endif
543
544
545 #ifndef OS_linux
546 # undef USE_XDF
547 #endif
548
549 #ifdef NO_XDF
550 # undef USE_XDF
551 #endif
552
553 #ifdef __EMX__
554 #define INCL_BASE
555 #define INCL_DOSDEVIOCTL
556 #include <os2.h>
557 #endif
558
559 #ifdef OS_nextstep
560 /* nextstep doesn't have this.  Unfortunately, we cannot test its presence
561    using AC_EGREP_HEADER, as we don't know _which_ header to test, and in
562    the general case utime.h might be non-existent */
563 struct utimbuf
564 {
565   time_t actime,modtime;
566 };
567 #endif
568
569 /* NeXTStep doesn't have these */
570 #if !defined(S_ISREG) && defined (_S_IFMT) && defined (_S_IFREG)
571 #define S_ISREG(mode)   (((mode) & (_S_IFMT)) == (_S_IFREG))
572 #endif
573
574 #if !defined(S_ISDIR) && defined (_S_IFMT) && defined (_S_IFDIR)
575 #define S_ISDIR(mode)   (((mode) & (_S_IFMT)) == (_S_IFDIR))
576 #endif
577
578
579 #ifdef OS_aix
580 /* AIX has an offset_t time, but somehow it is not scalar ==> forget about it
581  */
582 # undef HAVE_OFFSET_T
583 #endif
584
585
586 #ifdef HAVE_STAT64
587 #define MT_STAT stat64
588 #define MT_LSTAT lstat64
589 #define MT_FSTAT fstat64
590 #else
591 #define MT_STAT stat
592 #define MT_LSTAT lstat
593 #define MT_FSTAT fstat
594 #endif
595
596
597 #ifndef O_LARGEFILE
598 #define O_LARGEFILE 0
599 #endif
600
601 #ifndef __GNUC__
602 #ifndef __inline__
603 #define __inline__ inline
604 #endif
605 #endif
606
607 #endif