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 80ac_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#ifdef OS_mingw32msvc 90typedef 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# else 108# define UNUSED(x) x 109# endif 110# define NORETURN __attribute__ ((noreturn)) 111#else 112# define UNUSED(x) x 113# define PACKED /* */ 114# define NORETURN /* */ 115#endif 116 117 118/***********************************************************************/ 119/* */ 120/* Include files */ 121/* */ 122/***********************************************************************/ 123 124#define _LARGEFILE64_SOURCE 125#define _GNU_SOURCE 126 127 128#ifdef HAVE_FEATURES_H 129# include <features.h> 130#endif 131 132 133#include <sys/types.h> 134 135#ifdef HAVE_STDLIB_H 136# include <stdlib.h> 137#endif 138 139#include <stdio.h> 140#include <ctype.h> 141 142#ifdef HAVE_UNISTD_H 143# include <unistd.h> 144#endif 145 146#ifdef HAVE_LINUX_UNISTD_H 147# include <linux/unistd.h> 148#endif 149 150#ifdef HAVE_LIBC_H 151# include <libc.h> 152#endif 153 154#ifdef HAVE_GETOPT_H 155# include <getopt.h> 156#endif 157 158#ifdef HAVE_FCNTL_H 159# include <fcntl.h> 160#endif 161 162#ifdef HAVE_LIMITS_H 163# include <limits.h> 164#endif 165 166#ifdef HAVE_SYS_FILE_H 167# include <sys/file.h> 168#endif 169 170#ifdef HAVE_SYS_IOCTL_H 171# ifndef sunos 172# include <sys/ioctl.h> 173#endif 174#endif 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 */ 180 181#ifdef TIME_WITH_SYS_TIME 182# include <sys/time.h> 183# include <time.h> 184#else 185# ifdef HAVE_SYS_TIME_H 186# include <sys/time.h> 187# else 188# include <time.h> 189# endif 190#endif 191 192#ifndef NO_TERMIO 193# ifdef HAVE_TERMIO_H 194# include <termio.h> 195# elif defined HAVE_SYS_TERMIO_H 196# include <sys/termio.h> 197# endif 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> 204# endif 205# endif 206# ifdef HAVE_STTY_H 207# include <sgtty.h> 208# endif 209#endif 210 211 212#if defined(OS_aux) && !defined(_SYSV_SOURCE) 213/* compiled in POSIX mode, this is left out unless SYSV */ 214#define NCC 8 215struct termio { 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 */ 222}; 223extern int ioctl(int fildes, int request, void *arg); 224#endif 225 226 227#ifdef HAVE_MNTENT_H 228# include <mntent.h> 229#endif 230 231#ifdef HAVE_SYS_PARAM_H 232# include <sys/param.h> 233#endif 234 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 239# undef HAVE_TZSET 240# endif 241#else /* BSD */ 242/* ... elsewhere we prefer tzset */ 243# ifdef HAVE_TZSET 244# undef HAVE_GETTIMEOFDAY 245# endif 246#endif 247 248 249#include <sys/stat.h> 250 251#include <errno.h> 252#ifndef errno 253extern int errno; 254#endif 255 256#ifndef OS_mingw32msvc 257#include <pwd.h> 258#else 259typedef unsigned int uid_t; 260#endif 261 262 263#ifdef HAVE_STRING_H 264# include <string.h> 265#else 266# ifdef HAVE_STRINGS_H 267# include <strings.h> 268# endif 269#endif 270 271#ifdef HAVE_MEMORY_H 272# include <memory.h> 273#endif 274 275#ifdef HAVE_MALLOC_H 276# include <malloc.h> 277#endif 278 279#ifdef HAVE_SIGNAL_H 280# include <signal.h> 281#else 282# ifdef HAVE_SYS_SIGNAL_H 283# include <sys/signal.h> 284# endif 285#endif 286 287#ifdef HAVE_UTIME_H 288# include <utime.h> 289#endif 290 291#ifdef HAVE_SYS_WAIT_H 292# ifndef DONT_NEED_WAIT 293# include <sys/wait.h> 294# endif 295#endif 296 297#ifdef HAVE_WCHAR_H 298# include <wchar.h> 299# ifndef HAVE_PUTWC 300# define putwc(c,f) fprintf((f),"%lc",(c)) 301# endif 302#else 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 310# define putwc putc 311#endif 312 313#ifdef HAVE_WCTYPE_H 314# include <wctype.h> 315#else 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) 321#endif 322 323#ifdef HAVE_LOCALE_H 324# include <locale.h> 325#endif 326 327#ifdef USE_FLOPPYD 328 329#ifdef HAVE_SYS_SOCKET_H 330#include <sys/socket.h> 331#endif 332 333#ifdef HAVE_NETINET_IN_H 334#include <netinet/in.h> 335#endif 336 337#ifdef HAVE_ARPA_INET_H 338#include <arpa/inet.h> 339#endif 340 341#ifdef HAVE_NETDB_H 342#include <netdb.h> 343#endif 344 345#ifdef HAVE_X11_XAUTH_H 346#include <X11/Xauth.h> 347#endif 348 349#ifdef HAVE_X11_XLIB_H 350#include <X11/Xlib.h> 351#endif 352 353#endif 354 355#ifndef INADDR_NONE 356#define INADDR_NONE (-1) 357#endif 358 359 360#ifdef sgi 361#define MSGIHACK __EXTENSIONS__ 362#undef __EXTENSIONS__ 363#endif 364#include <math.h> 365#ifdef sgi 366#define __EXTENSIONS__ MSGIHACK 367#undef MSGIHACK 368#endif 369 370/* missing functions */ 371#ifndef HAVE_SRANDOM 372# ifdef OS_mingw32msvc 373# define srandom srand 374# else 375# define srandom srand48 376# endif 377#endif 378 379#ifndef HAVE_RANDOM 380# ifdef OS_mingw32msvc 381# define random (long)rand 382# else 383# define random (long)lrand48 384# endif 385#endif 386 387#ifndef HAVE_STRCHR 388# define strchr index 389#endif 390 391#ifndef HAVE_STRRCHR 392# define strrchr rindex 393#endif 394 395 396#ifndef HAVE_STRDUP 397extern char *strdup(const char *str); 398#endif /* HAVE_STRDUP */ 399 400 401#ifndef HAVE_MEMCPY 402extern char *memcpy(char *s1, const char *s2, size_t n); 403#endif 404 405#ifndef HAVE_MEMSET 406extern char *memset(char *s, char c, size_t n); 407#endif /* HAVE_MEMSET */ 408 409 410#ifndef HAVE_STRPBRK 411extern char *strpbrk(const char *string, const char *brkset); 412#endif /* HAVE_STRPBRK */ 413 414 415#ifndef HAVE_STRTOUL 416unsigned long strtoul(const char *string, char **eptr, int base); 417#endif /* HAVE_STRTOUL */ 418 419#ifndef HAVE_STRSPN 420size_t strspn(const char *s, const char *accept); 421#endif /* HAVE_STRSPN */ 422 423#ifndef HAVE_STRCSPN 424size_t strcspn(const char *s, const char *reject); 425#endif /* HAVE_STRCSPN */ 426 427#ifndef HAVE_STRERROR 428char *strerror(int errno); 429#endif 430 431#ifndef HAVE_ATEXIT 432int atexit(void (*function)(void)); 433 434#ifndef HAVE_ON_EXIT 435void myexit(int code) NORETURN; 436#define exit myexit 437#endif 438 439#endif 440 441 442#ifndef HAVE_MEMMOVE 443# define memmove(DST, SRC, N) bcopy(SRC, DST, N) 444#endif 445 446#ifndef HAVE_STRCASECMP 447int strcasecmp(const char *s1, const char *s2); 448#endif 449 450#ifndef HAVE_STRNCASECMP 451int strncasecmp(const char *s1, const char *s2, size_t n); 452#endif 453 454#ifndef HAVE_GETPASS 455char *getpass(const char *prompt); 456#endif 457 458#ifdef HAVE_WCHAR_H 459 460# ifndef HAVE_WCSDUP 461wchar_t *wcsdup(const wchar_t *wcs); 462# endif 463 464# ifndef HAVE_WCSCASECMP 465int wcscasecmp(const wchar_t *s1, const wchar_t *s2); 466# endif 467 468# ifndef HAVE_WCSNLEN 469size_t wcsnlen(const wchar_t *wcs, size_t l); 470# endif 471 472#endif 473 474#if 0 475#ifndef HAVE_BASENAME 476const char *basename(const char *filename); 477#endif 478#endif 479 480const char *_basename(const char *filename); 481 482void _stripexe(char *filename); 483 484#ifndef __STDC__ 485# ifndef signed 486# define signed /**/ 487# endif 488#endif /* !__STDC__ */ 489 490 491 492/***************************************************************************/ 493/* */ 494/* Prototypes for systems where the functions exist but not the prototypes */ 495/* */ 496/***************************************************************************/ 497 498 499 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. 507 */ 508 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 515 */ 516#if (defined OS_sunos || defined OS_ultrix) 517int read(); 518int write(); 519int fflush(); 520char *strdup(); 521int strcasecmp(); 522int strncasecmp(); 523char *getenv(); 524unsigned long strtoul(); 525int pclose(); 526void exit(); 527char *getpass(); 528int atoi(); 529FILE *fdopen(); 530FILE *popen(); 531#endif 532 533#ifndef MAXPATHLEN 534# ifdef PATH_MAX 535# define MAXPATHLEN PATH_MAX 536# else 537# define MAXPATHLEN 1024 538# endif 539#endif 540 541 542#ifndef OS_linux 543# undef USE_XDF 544#endif 545 546#ifdef NO_XDF 547# undef USE_XDF 548#endif 549 550#ifdef __EMX__ 551#define INCL_BASE 552#define INCL_DOSDEVIOCTL 553#include <os2.h> 554#endif 555 556#ifdef OS_nextstep 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 */ 560struct utimbuf 561{ 562 time_t actime,modtime; 563}; 564#endif 565 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)) 569#endif 570 571#if !defined(S_ISDIR) && defined (_S_IFMT) && defined (_S_IFDIR) 572#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR)) 573#endif 574 575 576#ifdef OS_aix 577/* AIX has an offset_t time, but somehow it is not scalar ==> forget about it 578 */ 579# undef HAVE_OFFSET_T 580#endif 581 582 583#ifdef HAVE_STAT64 584#define MT_STAT stat64 585#define MT_LSTAT lstat64 586#define MT_FSTAT fstat64 587#else 588#define MT_STAT stat 589#define MT_LSTAT lstat 590#define MT_FSTAT fstat 591#endif 592 593 594#ifndef O_LARGEFILE 595#define O_LARGEFILE 0 596#endif 597 598#ifndef __GNUC__ 599#ifndef __inline__ 600#define __inline__ inline 601#endif 602#endif 603 604#endif 605