xref: /netbsd-src/external/gpl3/gcc/dist/fixincludes/system.h (revision b1e838363e3c6fc78a55519254d99869742dd33c)
14fee23f9Smrg /* Get common system includes and various definitions and declarations based
24fee23f9Smrg    on autoconf macros.
34fee23f9Smrg    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009
44fee23f9Smrg    Free Software Foundation, Inc.
54fee23f9Smrg 
64fee23f9Smrg This file is part of GCC.
74fee23f9Smrg 
84fee23f9Smrg GCC is free software; you can redistribute it and/or modify it under
94fee23f9Smrg the terms of the GNU General Public License as published by the Free
104fee23f9Smrg Software Foundation; either version 3, or (at your option) any later
114fee23f9Smrg version.
124fee23f9Smrg 
134fee23f9Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
144fee23f9Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
154fee23f9Smrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
164fee23f9Smrg for more details.
174fee23f9Smrg 
184fee23f9Smrg You should have received a copy of the GNU General Public License
194fee23f9Smrg along with GCC; see the file COPYING3.  If not see
204fee23f9Smrg <http://www.gnu.org/licenses/>.  */
214fee23f9Smrg 
224fee23f9Smrg 
234fee23f9Smrg #ifndef FIXINC_SYSTEM_H
244fee23f9Smrg #define FIXINC_SYSTEM_H
254fee23f9Smrg 
264fee23f9Smrg /* We must include stdarg.h before stdio.h.  */
274fee23f9Smrg #include <stdarg.h>
284fee23f9Smrg 
294fee23f9Smrg #ifdef HAVE_STDDEF_H
304fee23f9Smrg # include <stddef.h>
314fee23f9Smrg #endif
324fee23f9Smrg 
334fee23f9Smrg #include <stdio.h>
344fee23f9Smrg 
354fee23f9Smrg /* Define a generic NULL if one hasn't already been defined.  */
364fee23f9Smrg #ifndef NULL
374fee23f9Smrg #define NULL 0
384fee23f9Smrg #endif
394fee23f9Smrg 
404fee23f9Smrg /* Use the unlocked open routines from libiberty.  */
414fee23f9Smrg #define fopen(PATH,MODE) fopen_unlocked(PATH,MODE)
424fee23f9Smrg #define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE)
434fee23f9Smrg #define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM)
444fee23f9Smrg 
454fee23f9Smrg /* fixincludes is not a multi-threaded application and therefore we
464fee23f9Smrg    do not have to use the locking functions.  In fact, using the locking
474fee23f9Smrg    functions can cause the compiler to be significantly slower under
484fee23f9Smrg    I/O bound conditions (such as -g -O0 on very large source files).
494fee23f9Smrg 
504fee23f9Smrg    HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
514fee23f9Smrg    code is multi-thread safe by default.  If it is set to 0, then do
524fee23f9Smrg    not worry about using the _unlocked functions.
534fee23f9Smrg 
544fee23f9Smrg    fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
554fee23f9Smrg    extensions and need to be prototyped by hand (since we do not
564fee23f9Smrg    define _GNU_SOURCE).  */
574fee23f9Smrg 
584fee23f9Smrg #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
594fee23f9Smrg 
604fee23f9Smrg # ifdef HAVE_PUTC_UNLOCKED
614fee23f9Smrg #  undef putc
624fee23f9Smrg #  define putc(C, Stream) putc_unlocked (C, Stream)
634fee23f9Smrg # endif
644fee23f9Smrg # ifdef HAVE_PUTCHAR_UNLOCKED
654fee23f9Smrg #  undef putchar
664fee23f9Smrg #  define putchar(C) putchar_unlocked (C)
674fee23f9Smrg # endif
684fee23f9Smrg # ifdef HAVE_GETC_UNLOCKED
694fee23f9Smrg #  undef getc
704fee23f9Smrg #  define getc(Stream) getc_unlocked (Stream)
714fee23f9Smrg # endif
724fee23f9Smrg # ifdef HAVE_GETCHAR_UNLOCKED
734fee23f9Smrg #  undef getchar
744fee23f9Smrg #  define getchar() getchar_unlocked ()
754fee23f9Smrg # endif
764fee23f9Smrg # ifdef HAVE_FPUTC_UNLOCKED
774fee23f9Smrg #  undef fputc
784fee23f9Smrg #  define fputc(C, Stream) fputc_unlocked (C, Stream)
794fee23f9Smrg # endif
804fee23f9Smrg 
814fee23f9Smrg # ifdef HAVE_CLEARERR_UNLOCKED
824fee23f9Smrg #  undef clearerr
834fee23f9Smrg #  define clearerr(Stream) clearerr_unlocked (Stream)
844fee23f9Smrg #  if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
854fee23f9Smrg extern void clearerr_unlocked (FILE *);
864fee23f9Smrg #  endif
874fee23f9Smrg # endif
884fee23f9Smrg # ifdef HAVE_FEOF_UNLOCKED
894fee23f9Smrg #  undef feof
904fee23f9Smrg #  define feof(Stream) feof_unlocked (Stream)
914fee23f9Smrg #  if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
924fee23f9Smrg extern int feof_unlocked (FILE *);
934fee23f9Smrg #  endif
944fee23f9Smrg # endif
954fee23f9Smrg # ifdef HAVE_FILENO_UNLOCKED
964fee23f9Smrg #  undef fileno
974fee23f9Smrg #  define fileno(Stream) fileno_unlocked (Stream)
984fee23f9Smrg #  if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
994fee23f9Smrg extern int fileno_unlocked (FILE *);
1004fee23f9Smrg #  endif
1014fee23f9Smrg # endif
1024fee23f9Smrg # ifdef HAVE_FFLUSH_UNLOCKED
1034fee23f9Smrg #  undef fflush
1044fee23f9Smrg #  define fflush(Stream) fflush_unlocked (Stream)
1054fee23f9Smrg #  if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
1064fee23f9Smrg extern int fflush_unlocked (FILE *);
1074fee23f9Smrg #  endif
1084fee23f9Smrg # endif
1094fee23f9Smrg # ifdef HAVE_FGETC_UNLOCKED
1104fee23f9Smrg #  undef fgetc
1114fee23f9Smrg #  define fgetc(Stream) fgetc_unlocked (Stream)
1124fee23f9Smrg #  if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
1134fee23f9Smrg extern int fgetc_unlocked (FILE *);
1144fee23f9Smrg #  endif
1154fee23f9Smrg # endif
1164fee23f9Smrg # ifdef HAVE_FGETS_UNLOCKED
1174fee23f9Smrg #  undef fgets
1184fee23f9Smrg #  define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
1194fee23f9Smrg #  if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
1204fee23f9Smrg extern char *fgets_unlocked (char *, int, FILE *);
1214fee23f9Smrg #  endif
1224fee23f9Smrg # endif
1234fee23f9Smrg # ifdef HAVE_FPUTS_UNLOCKED
1244fee23f9Smrg #  undef fputs
1254fee23f9Smrg #  define fputs(String, Stream) fputs_unlocked (String, Stream)
1264fee23f9Smrg #  if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
1274fee23f9Smrg extern int fputs_unlocked (const char *, FILE *);
1284fee23f9Smrg #  endif
1294fee23f9Smrg # endif
1304fee23f9Smrg # ifdef HAVE_FERROR_UNLOCKED
1314fee23f9Smrg #  undef ferror
1324fee23f9Smrg #  define ferror(Stream) ferror_unlocked (Stream)
1334fee23f9Smrg #  if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
1344fee23f9Smrg extern int ferror_unlocked (FILE *);
1354fee23f9Smrg #  endif
1364fee23f9Smrg # endif
1374fee23f9Smrg # ifdef HAVE_FREAD_UNLOCKED
1384fee23f9Smrg #  undef fread
1394fee23f9Smrg #  define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
1404fee23f9Smrg #  if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
1414fee23f9Smrg extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
1424fee23f9Smrg #  endif
1434fee23f9Smrg # endif
1444fee23f9Smrg # ifdef HAVE_FWRITE_UNLOCKED
1454fee23f9Smrg #  undef fwrite
1464fee23f9Smrg #  define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
1474fee23f9Smrg #  if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
1484fee23f9Smrg extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
1494fee23f9Smrg #  endif
1504fee23f9Smrg # endif
1514fee23f9Smrg # ifdef HAVE_FPRINTF_UNLOCKED
1524fee23f9Smrg #  undef fprintf
1534fee23f9Smrg /* We can't use a function-like macro here because we don't know if
1544fee23f9Smrg    we have varargs macros.  */
1554fee23f9Smrg #  define fprintf fprintf_unlocked
1564fee23f9Smrg #  if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
1574fee23f9Smrg extern int fprintf_unlocked (FILE *, const char *, ...);
1584fee23f9Smrg #  endif
1594fee23f9Smrg # endif
1604fee23f9Smrg 
1614fee23f9Smrg #endif
1624fee23f9Smrg 
1634fee23f9Smrg /* ??? Glibc's fwrite/fread_unlocked macros cause
1644fee23f9Smrg    "warning: signed and unsigned type in conditional expression".  */
1654fee23f9Smrg #undef fread_unlocked
1664fee23f9Smrg #undef fwrite_unlocked
1674fee23f9Smrg 
1684fee23f9Smrg #include <sys/types.h>
1694fee23f9Smrg #include <errno.h>
1704fee23f9Smrg 
1714fee23f9Smrg #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
1724fee23f9Smrg extern int errno;
1734fee23f9Smrg #endif
1744fee23f9Smrg 
1754fee23f9Smrg /* Some of glibc's string inlines cause warnings.  Plus we'd rather
1764fee23f9Smrg    rely on (and therefore test) GCC's string builtins.  */
1774fee23f9Smrg #define __NO_STRING_INLINES
1784fee23f9Smrg 
1794fee23f9Smrg #ifdef HAVE_STRING_H
1804fee23f9Smrg # include <string.h>
1814fee23f9Smrg #else
1824fee23f9Smrg # ifdef HAVE_STRINGS_H
1834fee23f9Smrg #  include <strings.h>
1844fee23f9Smrg # endif
1854fee23f9Smrg #endif
1864fee23f9Smrg 
1874fee23f9Smrg #ifdef HAVE_STDLIB_H
1884fee23f9Smrg # include <stdlib.h>
1894fee23f9Smrg #endif
1904fee23f9Smrg 
1914fee23f9Smrg #ifdef HAVE_UNISTD_H
1924fee23f9Smrg # include <unistd.h>
1934fee23f9Smrg #endif
1944fee23f9Smrg 
1954fee23f9Smrg #ifdef HAVE_FCNTL_H
1964fee23f9Smrg # include <fcntl.h>
1974fee23f9Smrg #else
1984fee23f9Smrg # ifdef HAVE_SYS_FILE_H
1994fee23f9Smrg #  include <sys/file.h>
2004fee23f9Smrg # endif
2014fee23f9Smrg #endif
2024fee23f9Smrg 
2034fee23f9Smrg /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1.  If they
2044fee23f9Smrg    are defined to 0 then we must provide the relevant declaration
2054fee23f9Smrg    here.  These checks will be in the undefined state while configure
2064fee23f9Smrg    is running so be careful to test "defined (HAVE_DECL_*)".  */
2074fee23f9Smrg 
2084fee23f9Smrg #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
2094fee23f9Smrg extern void abort (void);
2104fee23f9Smrg #endif
2114fee23f9Smrg 
212*b1e83836Smrg #if defined (HAVE_DECL_MEMMEM) && !HAVE_DECL_MEMMEM
213*b1e83836Smrg extern void *memmem (const void *, size_t, const void *, size_t);
214*b1e83836Smrg #endif
215*b1e83836Smrg 
2164fee23f9Smrg #if HAVE_SYS_STAT_H
2174fee23f9Smrg # include <sys/stat.h>
2184fee23f9Smrg #endif
2194fee23f9Smrg 
2204fee23f9Smrg /* Test if something is a normal file.  */
2214fee23f9Smrg #ifndef S_ISREG
2224fee23f9Smrg #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
2234fee23f9Smrg #endif
2244fee23f9Smrg 
2254fee23f9Smrg /* Filename handling macros.  */
2264fee23f9Smrg #include "filenames.h"
2274fee23f9Smrg 
2284fee23f9Smrg /* Get libiberty declarations.  */
2294fee23f9Smrg #include "libiberty.h"
2304fee23f9Smrg #include "safe-ctype.h"
2314fee23f9Smrg 
2324fee23f9Smrg #endif /* ! FIXINC_SYSTEM_H */
233