1 /* Copyright 1996-1999,2001,2002,2007-2009 Alain Knaff.
2 * This file is part of mtools.
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.
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.
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/>.
17 * System includes for mtools
23 #define _LARGEFILE64_SOURCE
29 /* OS/2 needs __inline__, but for some reason is not autodetected */
32 # define inline __inline__
36 /***********************************************************************/
38 /* OS dependancies which cannot be covered by the autoconfigure script */
40 /***********************************************************************/
44 /* A/UX needs POSIX_SOURCE, just as AIX does. Unlike SCO and AIX, it seems
45 * to prefer TERMIO over TERMIOS */
47 # define _POSIX_SOURCE
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)
65 /* on ultrix, if termios present, prefer it instead of termio */
66 # ifdef HAVE_TERMIOS_H
72 /* RMS strikes again */
78 /* For compiling with MingW, use the following configure line
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
84 #ifndef OS_mingw32msvc
85 #define OS_mingw32msvc
90 typedef void *caddr_t;
94 /***********************************************************************/
96 /* Compiler dependancies */
98 /***********************************************************************/
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))
110 # define UNUSEDP /* */
112 # define NORETURN __attribute__ ((noreturn))
115 # define UNUSEDP /* */
116 # define PACKED /* */
117 # define NORETURN /* */
121 /***********************************************************************/
125 /***********************************************************************/
127 #define _LARGEFILE64_SOURCE
131 #ifdef HAVE_FEATURES_H
132 # include <features.h>
136 #include <sys/types.h>
149 #ifdef HAVE_LINUX_UNISTD_H
150 # include <linux/unistd.h>
169 #ifdef HAVE_SYS_FILE_H
170 # include <sys/file.h>
173 #ifdef HAVE_SYS_IOCTL_H
175 # include <sys/ioctl.h>
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 */
184 #ifdef TIME_WITH_SYS_TIME
185 # include <sys/time.h>
188 # ifdef HAVE_SYS_TIME_H
189 # include <sys/time.h>
196 # ifdef HAVE_TERMIO_H
198 # elif defined HAVE_SYS_TERMIO_H
199 # include <sys/termio.h>
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>
215 #if defined(OS_aux) && !defined(_SYSV_SOURCE)
216 /* compiled in POSIX mode, this is left out unless SYSV */
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 */
226 extern int ioctl(int fildes, int request, void *arg);
234 #ifdef HAVE_SYS_PARAM_H
235 # include <sys/param.h>
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
245 /* ... elsewhere we prefer tzset */
247 # undef HAVE_GETTIMEOFDAY
252 #include <sys/stat.h>
259 #ifndef OS_mingw32msvc
262 typedef unsigned int uid_t;
269 # ifdef HAVE_STRINGS_H
270 # include <strings.h>
285 # ifdef HAVE_SYS_SIGNAL_H
286 # include <sys/signal.h>
294 #ifdef HAVE_SYS_WAIT_H
295 # ifndef DONT_NEED_WAIT
296 # include <sys/wait.h>
303 # define putwc(c,f) fprintf((f),"%lc",(c))
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
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)
332 #ifdef HAVE_SYS_SOCKET_H
333 #include <sys/socket.h>
336 #ifdef HAVE_NETINET_IN_H
337 #include <netinet/in.h>
340 #ifdef HAVE_ARPA_INET_H
341 #include <arpa/inet.h>
348 #ifdef HAVE_X11_XAUTH_H
349 #include <X11/Xauth.h>
352 #ifdef HAVE_X11_XLIB_H
353 #include <X11/Xlib.h>
359 #define INADDR_NONE (-1)
364 #define MSGIHACK __EXTENSIONS__
365 #undef __EXTENSIONS__
369 #define __EXTENSIONS__ MSGIHACK
373 /* missing functions */
375 # ifdef OS_mingw32msvc
376 # define srandom srand
378 # define srandom srand48
383 # ifdef OS_mingw32msvc
384 # define random (long)rand
386 # define random (long)lrand48
391 # define strchr index
395 # define strrchr rindex
400 extern char *strdup(const char *str);
401 #endif /* HAVE_STRDUP */
405 extern char *memcpy(char *s1, const char *s2, size_t n);
409 extern char *memset(char *s, char c, size_t n);
410 #endif /* HAVE_MEMSET */
414 extern char *strpbrk(const char *string, const char *brkset);
415 #endif /* HAVE_STRPBRK */
419 unsigned long strtoul(const char *string, char **eptr, int base);
420 #endif /* HAVE_STRTOUL */
423 size_t strspn(const char *s, const char *accept);
424 #endif /* HAVE_STRSPN */
427 size_t strcspn(const char *s, const char *reject);
428 #endif /* HAVE_STRCSPN */
430 #ifndef HAVE_STRERROR
431 char *strerror(int errno);
435 int atexit(void (*function)(void));
438 void myexit(int code) NORETURN;
446 # define memmove(DST, SRC, N) bcopy(SRC, DST, N)
449 #ifndef HAVE_STRCASECMP
450 int strcasecmp(const char *s1, const char *s2);
453 #ifndef HAVE_STRNCASECMP
454 int strncasecmp(const char *s1, const char *s2, size_t n);
458 char *getpass(const char *prompt);
464 wchar_t *wcsdup(const wchar_t *wcs);
467 # ifndef HAVE_WCSCASECMP
468 int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
471 # ifndef HAVE_WCSNLEN
472 size_t wcsnlen(const wchar_t *wcs, size_t l);
478 #ifndef HAVE_BASENAME
479 const char *basename(const char *filename);
483 const char *_basename(const char *filename);
485 void _stripexe(char *filename);
491 #endif /* !__STDC__ */
495 /***************************************************************************/
497 /* Prototypes for systems where the functions exist but not the prototypes */
499 /***************************************************************************/
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.
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
519 #if (defined OS_sunos || defined OS_ultrix)
527 unsigned long strtoul();
538 # define MAXPATHLEN PATH_MAX
540 # define MAXPATHLEN 1024
555 #define INCL_DOSDEVIOCTL
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 */
565 time_t actime,modtime;
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))
574 #if !defined(S_ISDIR) && defined (_S_IFMT) && defined (_S_IFDIR)
575 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
580 /* AIX has an offset_t time, but somehow it is not scalar ==> forget about it
582 # undef HAVE_OFFSET_T
587 #define MT_STAT stat64
588 #define MT_LSTAT lstat64
589 #define MT_FSTAT fstat64
592 #define MT_LSTAT lstat
593 #define MT_FSTAT fstat
598 #define O_LARGEFILE 0
603 #define __inline__ inline