• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 dependencies 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 dependencies                                               */
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 # endif
109 # define NORETURN __attribute__ ((noreturn))
110 # if __GNUC__ >= 8
111 #  define NONULLTERM __attribute__ ((nonstring))
112 # endif
113 #endif
114 
115 #ifndef UNUSED
116 # define UNUSED(x) x
117 # define UNUSEDP /* */
118 #endif
119 
120 #ifndef PACKED
121 # define PACKED /* */
122 #endif
123 
124 #ifndef NORETURN
125 # define NORETURN /* */
126 #endif
127 
128 #ifndef NONULLTERM
129 # define NONULLTERM /* */
130 #endif
131 
132 /***********************************************************************/
133 /*                                                                     */
134 /* Include files                                                       */
135 /*                                                                     */
136 /***********************************************************************/
137 
138 #define _LARGEFILE64_SOURCE
139 #define _GNU_SOURCE
140 
141 
142 #ifdef HAVE_FEATURES_H
143 # include <features.h>
144 #endif
145 
146 
147 #include <sys/types.h>
148 
149 #ifdef HAVE_STDINT_H
150 # include <stdint.h>
151 #endif
152 
153 #ifdef HAVE_INTTYPES_H
154 # include <inttypes.h>
155 #endif
156 
157 #ifdef HAVE_STDLIB_H
158 # include <stdlib.h>
159 #endif
160 
161 #include <stdio.h>
162 #include <ctype.h>
163 
164 #ifdef HAVE_UNISTD_H
165 # include <unistd.h>
166 #endif
167 
168 #ifdef HAVE_LINUX_UNISTD_H
169 # include <linux/unistd.h>
170 #endif
171 
172 #ifdef HAVE_LIBC_H
173 # include <libc.h>
174 #endif
175 
176 #ifdef HAVE_GETOPT_H
177 # include <getopt.h>
178 #endif
179 
180 #ifdef HAVE_FCNTL_H
181 # include <fcntl.h>
182 #endif
183 
184 #ifdef HAVE_LIMITS_H
185 # include <limits.h>
186 #endif
187 
188 #ifdef HAVE_SYS_FILE_H
189 # include <sys/file.h>
190 #endif
191 
192 #ifdef HAVE_SYS_IOCTL_H
193 # ifndef sunos
194 # include <sys/ioctl.h>
195 #endif
196 #endif
197 /* if we don't have sys/ioctl.h, we rely on unistd to supply a prototype
198  * for it. If it doesn't, we'll only get a (harmless) warning. The idea
199  * is to get mtools compile on as many platforms as possible, but to not
200  * suppress warnings if the platform is broken, as long as these warnings do
201  * not prevent compilation */
202 
203 #ifdef TIME_WITH_SYS_TIME
204 # include <sys/time.h>
205 # include <time.h>
206 #else
207 # ifdef HAVE_SYS_TIME_H
208 #  include <sys/time.h>
209 # else
210 #  include <time.h>
211 # endif
212 #endif
213 
214 #ifndef NO_TERMIO
215 # ifdef HAVE_TERMIO_H
216 #  include <termio.h>
217 # elif defined HAVE_SYS_TERMIO_H
218 #  include <sys/termio.h>
219 # endif
220 # if !defined OS_ultrix || !(defined HAVE_TERMIO_H || defined HAVE_TERMIO_H)
221 /* on Ultrix, avoid double inclusion of both termio and termios */
222 #  ifdef HAVE_TERMIOS_H
223 #   include <termios.h>
224 #  elif defined HAVE_SYS_TERMIOS_H
225 #   include <sys/termios.h>
226 #  endif
227 # endif
228 # ifdef HAVE_STTY_H
229 #  include <sgtty.h>
230 # endif
231 #endif
232 
233 
234 #if defined(OS_aux) && !defined(_SYSV_SOURCE)
235 /* compiled in POSIX mode, this is left out unless SYSV */
236 #define	NCC	8
237 struct termio {
238 	unsigned short	c_iflag;	/* input modes */
239 	unsigned short	c_oflag;	/* output modes */
240 	unsigned short	c_cflag;	/* control modes */
241 	unsigned short	c_lflag;	/* line discipline modes */
242 	char	c_line;			/* line discipline */
243 	unsigned char	c_cc[NCC];	/* control chars */
244 };
245 extern int ioctl(int fildes, int request, void *arg);
246 #endif
247 
248 
249 #ifdef HAVE_MNTENT_H
250 # include <mntent.h>
251 #endif
252 
253 #ifdef HAVE_SYS_PARAM_H
254 # include <sys/param.h>
255 #endif
256 
257 /* Can only be done here, as BSD is defined in sys/param.h :-( */
258 #if defined BSD || defined __BEOS__
259 /* on BSD and on BEOS, we prefer gettimeofday, ... */
260 # ifdef HAVE_GETTIMEOFDAY
261 #  undef HAVE_TZSET
262 # endif
263 #else /* BSD */
264 /* ... elsewhere we prefer tzset */
265 # ifdef HAVE_TZSET
266 #  undef HAVE_GETTIMEOFDAY
267 # endif
268 #endif
269 
270 
271 #include <sys/stat.h>
272 
273 #include <errno.h>
274 #ifndef errno
275 extern int errno;
276 #endif
277 
278 #ifndef OS_mingw32msvc
279 #include <pwd.h>
280 #endif
281 
282 
283 #ifdef HAVE_STRING_H
284 # include <string.h>
285 #else
286 # ifdef HAVE_STRINGS_H
287 #  include <strings.h>
288 # endif
289 #endif
290 
291 #ifdef HAVE_MEMORY_H
292 # include <memory.h>
293 #endif
294 
295 #ifdef HAVE_MALLOC_H
296 # include <malloc.h>
297 #endif
298 
299 #ifdef HAVE_IO_H
300 # include <io.h>
301 #endif
302 
303 #ifdef HAVE_SIGNAL_H
304 # include <signal.h>
305 #else
306 # ifdef HAVE_SYS_SIGNAL_H
307 #  include <sys/signal.h>
308 # endif
309 #endif
310 
311 #ifdef HAVE_UTIME_H
312 # include <utime.h>
313 #endif
314 
315 #ifdef HAVE_SYS_WAIT_H
316 # ifndef DONT_NEED_WAIT
317 #  include <sys/wait.h>
318 # endif
319 #endif
320 
321 #ifdef HAVE_WCHAR_H
322 # include <wchar.h>
323 # ifndef HAVE_PUTWC
324 #  define putwc(c,f) fprintf((f),"%lc",(c))
325 # endif
326 #else
327 # define wcscmp strcmp
328 # define wcscasecmp strcasecmp
329 # define wcsdup strdup
330 # define wcslen strlen
331 # define wcschr strchr
332 # define wcspbrk strpbrk
333 # define wchar_t char
334 # define putwc putc
335 #endif
336 
337 #ifdef HAVE_WCTYPE_H
338 # include <wctype.h>
339 #else
340 # define towupper(x) toupper(x)
341 # define towlower(x) tolower(x)
342 # define iswupper(x) isupper(x)
343 # define iswlower(x) islower(x)
344 # define iswcntrl(x) iscntrl(x)
345 #endif
346 
347 #ifdef HAVE_LOCALE_H
348 # include <locale.h>
349 #endif
350 
351 #ifdef HAVE_XLOCALE_H
352 # include <xlocale.h>
353 #endif
354 
355 #ifdef USE_FLOPPYD
356 
357 #ifdef HAVE_SYS_SOCKET_H
358 #include <sys/socket.h>
359 #endif
360 
361 #ifdef HAVE_NETINET_IN_H
362 #include <netinet/in.h>
363 #endif
364 
365 #ifdef HAVE_NETINET_TCP_H
366 #include <netinet/tcp.h>
367 #endif
368 
369 #ifdef HAVE_ARPA_INET_H
370 #include <arpa/inet.h>
371 #endif
372 
373 #ifdef HAVE_NETDB_H
374 #include <netdb.h>
375 #endif
376 
377 #ifdef HAVE_X11_XAUTH_H
378 #include <X11/Xauth.h>
379 #endif
380 
381 #ifdef HAVE_X11_XLIB_H
382 #include <X11/Xlib.h>
383 #endif
384 
385 #endif
386 
387 #ifndef INADDR_NONE
388 #define INADDR_NONE (-1)
389 #endif
390 
391 
392 #ifdef sgi
393 #define MSGIHACK __EXTENSIONS__
394 #undef __EXTENSIONS__
395 #endif
396 #include <math.h>
397 #ifdef sgi
398 #define __EXTENSIONS__ MSGIHACK
399 #undef MSGIHACK
400 #endif
401 
402 /* missing functions */
403 #ifndef HAVE_SRANDOM
404 # ifdef OS_mingw32msvc
405 #  define srandom srand
406 # else
407 #  define srandom srand48
408 # endif
409 #endif
410 
411 #ifndef HAVE_RANDOM
412 # ifdef OS_mingw32msvc
413 #  define random (long)rand
414 # else
415 #  define random (long)lrand48
416 # endif
417 #endif
418 
419 #ifndef HAVE_STRCHR
420 # define strchr index
421 #endif
422 
423 #ifndef HAVE_STRRCHR
424 # define strrchr rindex
425 #endif
426 
427 
428 #ifndef HAVE_STRDUP
429 extern char *strdup(const char *str);
430 #endif /* HAVE_STRDUP */
431 
432 #ifndef HAVE_STRNDUP
433 extern char *strndup(const char *s, size_t n);
434 #endif /* HAVE_STRDUP */
435 
436 #ifndef HAVE_MEMCPY
437 extern char *memcpy(char *s1, const char *s2, size_t n);
438 #endif
439 
440 #ifndef HAVE_MEMSET
441 extern char *memset(char *s, char c, size_t n);
442 #endif /* HAVE_MEMSET */
443 
444 
445 #ifndef HAVE_STRPBRK
446 extern char *strpbrk(const char *string, const char *brkset);
447 #endif /* HAVE_STRPBRK */
448 
449 
450 #ifndef HAVE_STRTOUL
451 unsigned long strtoul(const char *string, char **eptr, int base);
452 #endif /* HAVE_STRTOUL */
453 
454 #ifndef HAVE_STRSPN
455 size_t strspn(const char *s, const char *accept);
456 #endif /* HAVE_STRSPN */
457 
458 #ifndef HAVE_STRCSPN
459 size_t strcspn(const char *s, const char *reject);
460 #endif /* HAVE_STRCSPN */
461 
462 #ifndef HAVE_STRERROR
463 char *strerror(int errno);
464 #endif
465 
466 #ifndef HAVE_ATEXIT
467 int atexit(void (*function)(void));
468 
469 #ifndef HAVE_ON_EXIT
470 void myexit(int code) NORETURN;
471 #define exit myexit
472 #endif
473 
474 #endif
475 
476 
477 #ifndef HAVE_MEMMOVE
478 # define memmove(DST, SRC, N) bcopy(SRC, DST, N)
479 #endif
480 
481 #ifndef HAVE_STRCASECMP
482 int strcasecmp(const char *s1, const char *s2);
483 #endif
484 
485 #ifndef HAVE_STRNCASECMP
486 int strncasecmp(const char *s1, const char *s2, size_t n);
487 #endif
488 
489 #ifndef HAVE_GETPASS
490 char *getpass(const char *prompt);
491 #endif
492 
493 #ifdef HAVE_WCHAR_H
494 
495 # ifndef HAVE_WCSDUP
496 wchar_t *wcsdup(const wchar_t *wcs);
497 # endif
498 
499 # ifndef HAVE_WCSCASECMP
500 int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
501 # endif
502 
503 # ifndef HAVE_WCSNLEN
504 size_t wcsnlen(const wchar_t *wcs, size_t l);
505 # endif
506 
507 #endif
508 
509 #if 0
510 #ifndef HAVE_BASENAME
511 const char *basename(const char *filename);
512 #endif
513 #endif
514 
515 const char *_basename(const char *filename);
516 
517 void _stripexe(char *filename);
518 
519 #ifndef __STDC__
520 # ifndef signed
521 #  define signed /**/
522 # endif
523 #endif /* !__STDC__ */
524 
525 
526 
527 /***************************************************************************/
528 /*                                                                         */
529 /* Prototypes for systems where the functions exist but not the prototypes */
530 /*                                                                         */
531 /***************************************************************************/
532 
533 
534 
535 /* prototypes which might be missing on some platforms, even if the functions
536  * are present.  Do not declare argument types, in order to avoid conflict
537  * on platforms where the prototypes _are_ correct.  Indeed, for most of
538  * these, there are _several_ "correct" parameter definitions, and not all
539  * platforms use the same.  For instance, some use the const attribute for
540  * strings not modified by the function, and others do not.  By using just
541  * the return type, which rarely changes, we avoid these problems.
542  */
543 
544 /* Correction:  Now it seems that even return values are not standardized :-(
545   For instance  DEC-ALPHA, OSF/1 3.2d uses ssize_t as a return type for read
546   and write.  NextStep uses a non-void return value for exit, etc.  With the
547   advent of 64 bit system, we'll expect more of these problems in the future.
548   Better uncomment the lot, except on SunOS, which is known to have bad
549   incomplete files.  Add other OS'es with incomplete include files as needed
550   */
551 #if (defined OS_sunos || defined OS_ultrix)
552 int read();
553 int write();
554 int fflush();
555 char *strdup();
556 int strcasecmp();
557 int strncasecmp();
558 char *getenv();
559 unsigned long strtoul();
560 int pclose();
561 void exit();
562 char *getpass();
563 int atoi();
564 FILE *fdopen();
565 FILE *popen();
566 #endif
567 
568 #ifndef MAXPATHLEN
569 # ifdef PATH_MAX
570 #  define MAXPATHLEN PATH_MAX
571 # else
572 #  define MAXPATHLEN 1024
573 # endif
574 #endif
575 
576 
577 #ifndef OS_linux
578 # undef USE_XDF
579 #endif
580 
581 #ifdef NO_XDF
582 # undef USE_XDF
583 #endif
584 
585 #ifdef __EMX__
586 #define INCL_BASE
587 #define INCL_DOSDEVIOCTL
588 #include <os2.h>
589 #endif
590 
591 #ifdef OS_nextstep
592 /* nextstep doesn't have this.  Unfortunately, we cannot test its presence
593    using AC_EGREP_HEADER, as we don't know _which_ header to test, and in
594    the general case utime.h might be non-existent */
595 struct utimbuf
596 {
597   time_t actime,modtime;
598 };
599 #endif
600 
601 /* NeXTStep doesn't have these */
602 #if !defined(S_ISREG) && defined (_S_IFMT) && defined (_S_IFREG)
603 #define S_ISREG(mode)   (((mode) & (_S_IFMT)) == (_S_IFREG))
604 #endif
605 
606 #if !defined(S_ISDIR) && defined (_S_IFMT) && defined (_S_IFDIR)
607 #define S_ISDIR(mode)   (((mode) & (_S_IFMT)) == (_S_IFDIR))
608 #endif
609 
610 
611 #ifdef OS_aix
612 /* AIX has an offset_t time, but somehow it is not scalar ==> forget about it
613  */
614 # undef HAVE_OFFSET_T
615 #endif
616 
617 
618 #ifdef HAVE_STAT64
619 #define MT_STAT stat64
620 #define MT_LSTAT lstat64
621 #define MT_FSTAT fstat64
622 #else
623 #define MT_STAT stat
624 #define MT_LSTAT lstat
625 #define MT_FSTAT fstat
626 #endif
627 
628 
629 #ifndef O_LARGEFILE
630 #define O_LARGEFILE 0
631 #endif
632 
633 #ifndef __GNUC__
634 #ifndef __inline__
635 #define __inline__ inline
636 #endif
637 #endif
638 
639 #endif
640