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
110 # define NORETURN __attribute__ ((noreturn))
113 # define PACKED /* */
114 # define NORETURN /* */
118 /***********************************************************************/
122 /***********************************************************************/
124 #define _LARGEFILE64_SOURCE
128 #ifdef HAVE_FEATURES_H
129 # include <features.h>
133 #include <sys/types.h>
146 #ifdef HAVE_LINUX_UNISTD_H
147 # include <linux/unistd.h>
166 #ifdef HAVE_SYS_FILE_H
167 # include <sys/file.h>
170 #ifdef HAVE_SYS_IOCTL_H
172 # include <sys/ioctl.h>
175 /* if we don't have sys/ioctl.h, we rely on unistd to supply a prototype
176 * for it. If it doesn't, we'll only get a (harmless) warning. The idea
177 * is to get mtools compile on as many platforms as possible, but to not
178 * suppress warnings if the platform is broken, as long as these warnings do
179 * not prevent compilation */
181 #ifdef TIME_WITH_SYS_TIME
182 # include <sys/time.h>
185 # ifdef HAVE_SYS_TIME_H
186 # include <sys/time.h>
193 # ifdef HAVE_TERMIO_H
195 # elif defined HAVE_SYS_TERMIO_H
196 # include <sys/termio.h>
198 # if !defined OS_ultrix || !(defined HAVE_TERMIO_H || defined HAVE_TERMIO_H)
199 /* on Ultrix, avoid double inclusion of both termio and termios */
200 # ifdef HAVE_TERMIOS_H
201 # include <termios.h>
202 # elif defined HAVE_SYS_TERMIOS_H
203 # include <sys/termios.h>
212 #if defined(OS_aux) && !defined(_SYSV_SOURCE)
213 /* compiled in POSIX mode, this is left out unless SYSV */
216 unsigned short c_iflag; /* input modes */
217 unsigned short c_oflag; /* output modes */
218 unsigned short c_cflag; /* control modes */
219 unsigned short c_lflag; /* line discipline modes */
220 char c_line; /* line discipline */
221 unsigned char c_cc[NCC]; /* control chars */
223 extern int ioctl(int fildes, int request, void *arg);
231 #ifdef HAVE_SYS_PARAM_H
232 # include <sys/param.h>
235 /* Can only be done here, as BSD is defined in sys/param.h :-( */
236 #if defined BSD || defined __BEOS__
237 /* on BSD and on BEOS, we prefer gettimeofday, ... */
238 # ifdef HAVE_GETTIMEOFDAY
242 /* ... elsewhere we prefer tzset */
244 # undef HAVE_GETTIMEOFDAY
249 #include <sys/stat.h>
256 #ifndef OS_mingw32msvc
259 typedef unsigned int uid_t;
266 # ifdef HAVE_STRINGS_H
267 # include <strings.h>
282 # ifdef HAVE_SYS_SIGNAL_H
283 # include <sys/signal.h>
291 #ifdef HAVE_SYS_WAIT_H
292 # ifndef DONT_NEED_WAIT
293 # include <sys/wait.h>
300 # define putwc(c,f) fprintf((f),"%lc",(c))
303 # define wcscmp strcmp
304 # define wcscasecmp strcasecmp
305 # define wcsdup strdup
306 # define wcslen strlen
307 # define wcschr strchr
308 # define wcspbrk strpbrk
309 # define wchar_t char
316 # define towupper(x) toupper(x)
317 # define towlower(x) tolower(x)
318 # define iswupper(x) isupper(x)
319 # define iswlower(x) islower(x)
320 # define iswcntrl(x) iscntrl(x)
329 #ifdef HAVE_SYS_SOCKET_H
330 #include <sys/socket.h>
333 #ifdef HAVE_NETINET_IN_H
334 #include <netinet/in.h>
337 #ifdef HAVE_ARPA_INET_H
338 #include <arpa/inet.h>
345 #ifdef HAVE_X11_XAUTH_H
346 #include <X11/Xauth.h>
349 #ifdef HAVE_X11_XLIB_H
350 #include <X11/Xlib.h>
356 #define INADDR_NONE (-1)
361 #define MSGIHACK __EXTENSIONS__
362 #undef __EXTENSIONS__
366 #define __EXTENSIONS__ MSGIHACK
370 /* missing functions */
372 # ifdef OS_mingw32msvc
373 # define srandom srand
375 # define srandom srand48
380 # ifdef OS_mingw32msvc
381 # define random (long)rand
383 # define random (long)lrand48
388 # define strchr index
392 # define strrchr rindex
397 extern char *strdup(const char *str);
398 #endif /* HAVE_STRDUP */
402 extern char *memcpy(char *s1, const char *s2, size_t n);
406 extern char *memset(char *s, char c, size_t n);
407 #endif /* HAVE_MEMSET */
411 extern char *strpbrk(const char *string, const char *brkset);
412 #endif /* HAVE_STRPBRK */
416 unsigned long strtoul(const char *string, char **eptr, int base);
417 #endif /* HAVE_STRTOUL */
420 size_t strspn(const char *s, const char *accept);
421 #endif /* HAVE_STRSPN */
424 size_t strcspn(const char *s, const char *reject);
425 #endif /* HAVE_STRCSPN */
427 #ifndef HAVE_STRERROR
428 char *strerror(int errno);
432 int atexit(void (*function)(void));
435 void myexit(int code) NORETURN;
443 # define memmove(DST, SRC, N) bcopy(SRC, DST, N)
446 #ifndef HAVE_STRCASECMP
447 int strcasecmp(const char *s1, const char *s2);
450 #ifndef HAVE_STRNCASECMP
451 int strncasecmp(const char *s1, const char *s2, size_t n);
455 char *getpass(const char *prompt);
461 wchar_t *wcsdup(const wchar_t *wcs);
464 # ifndef HAVE_WCSCASECMP
465 int wcscasecmp(const wchar_t *s1, const wchar_t *s2);
468 # ifndef HAVE_WCSNLEN
469 size_t wcsnlen(const wchar_t *wcs, size_t l);
475 #ifndef HAVE_BASENAME
476 const char *basename(const char *filename);
480 const char *_basename(const char *filename);
482 void _stripexe(char *filename);
488 #endif /* !__STDC__ */
492 /***************************************************************************/
494 /* Prototypes for systems where the functions exist but not the prototypes */
496 /***************************************************************************/
500 /* prototypes which might be missing on some platforms, even if the functions
501 * are present. Do not declare argument types, in order to avoid conflict
502 * on platforms where the prototypes _are_ correct. Indeed, for most of
503 * these, there are _several_ "correct" parameter definitions, and not all
504 * platforms use the same. For instance, some use the const attribute for
505 * strings not modified by the function, and others do not. By using just
506 * the return type, which rarely changes, we avoid these problems.
509 /* Correction: Now it seems that even return values are not standardized :-(
510 For instance DEC-ALPHA, OSF/1 3.2d uses ssize_t as a return type for read
511 and write. NextStep uses a non-void return value for exit, etc. With the
512 advent of 64 bit system, we'll expect more of these problems in the future.
513 Better uncomment the lot, except on SunOS, which is known to have bad
514 incomplete files. Add other OS'es with incomplete include files as needed
516 #if (defined OS_sunos || defined OS_ultrix)
524 unsigned long strtoul();
535 # define MAXPATHLEN PATH_MAX
537 # define MAXPATHLEN 1024
552 #define INCL_DOSDEVIOCTL
557 /* nextstep doesn't have this. Unfortunately, we cannot test its presence
558 using AC_EGREP_HEADER, as we don't know _which_ header to test, and in
559 the general case utime.h might be non-existent */
562 time_t actime,modtime;
566 /* NeXTStep doesn't have these */
567 #if !defined(S_ISREG) && defined (_S_IFMT) && defined (_S_IFREG)
568 #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
571 #if !defined(S_ISDIR) && defined (_S_IFMT) && defined (_S_IFDIR)
572 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
577 /* AIX has an offset_t time, but somehow it is not scalar ==> forget about it
579 # undef HAVE_OFFSET_T
584 #define MT_STAT stat64
585 #define MT_LSTAT lstat64
586 #define MT_FSTAT fstat64
589 #define MT_LSTAT lstat
590 #define MT_FSTAT fstat
595 #define O_LARGEFILE 0
600 #define __inline__ inline