system.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* Get common system includes and various definitions and declarations based
  2. on autoconf macros.
  3. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009
  4. Free Software Foundation, Inc.
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 3, or (at your option) any later
  9. version.
  10. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING3. If not see
  16. <http://www.gnu.org/licenses/>. */
  17. #ifndef FIXINC_SYSTEM_H
  18. #define FIXINC_SYSTEM_H
  19. /* We must include stdarg.h before stdio.h. */
  20. #include <stdarg.h>
  21. #ifdef HAVE_STDDEF_H
  22. # include <stddef.h>
  23. #endif
  24. #include <stdio.h>
  25. /* Define a generic NULL if one hasn't already been defined. */
  26. #ifndef NULL
  27. #define NULL 0
  28. #endif
  29. /* Use the unlocked open routines from libiberty. */
  30. #define fopen(PATH,MODE) fopen_unlocked(PATH,MODE)
  31. #define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE)
  32. #define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM)
  33. /* fixincludes is not a multi-threaded application and therefore we
  34. do not have to use the locking functions. In fact, using the locking
  35. functions can cause the compiler to be significantly slower under
  36. I/O bound conditions (such as -g -O0 on very large source files).
  37. HAVE_DECL_PUTC_UNLOCKED actually indicates whether or not the stdio
  38. code is multi-thread safe by default. If it is set to 0, then do
  39. not worry about using the _unlocked functions.
  40. fputs_unlocked, fwrite_unlocked, and fprintf_unlocked are
  41. extensions and need to be prototyped by hand (since we do not
  42. define _GNU_SOURCE). */
  43. #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
  44. # ifdef HAVE_PUTC_UNLOCKED
  45. # undef putc
  46. # define putc(C, Stream) putc_unlocked (C, Stream)
  47. # endif
  48. # ifdef HAVE_PUTCHAR_UNLOCKED
  49. # undef putchar
  50. # define putchar(C) putchar_unlocked (C)
  51. # endif
  52. # ifdef HAVE_GETC_UNLOCKED
  53. # undef getc
  54. # define getc(Stream) getc_unlocked (Stream)
  55. # endif
  56. # ifdef HAVE_GETCHAR_UNLOCKED
  57. # undef getchar
  58. # define getchar() getchar_unlocked ()
  59. # endif
  60. # ifdef HAVE_FPUTC_UNLOCKED
  61. # undef fputc
  62. # define fputc(C, Stream) fputc_unlocked (C, Stream)
  63. # endif
  64. # ifdef HAVE_CLEARERR_UNLOCKED
  65. # undef clearerr
  66. # define clearerr(Stream) clearerr_unlocked (Stream)
  67. # if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
  68. extern void clearerr_unlocked (FILE *);
  69. # endif
  70. # endif
  71. # ifdef HAVE_FEOF_UNLOCKED
  72. # undef feof
  73. # define feof(Stream) feof_unlocked (Stream)
  74. # if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
  75. extern int feof_unlocked (FILE *);
  76. # endif
  77. # endif
  78. # ifdef HAVE_FILENO_UNLOCKED
  79. # undef fileno
  80. # define fileno(Stream) fileno_unlocked (Stream)
  81. # if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
  82. extern int fileno_unlocked (FILE *);
  83. # endif
  84. # endif
  85. # ifdef HAVE_FFLUSH_UNLOCKED
  86. # undef fflush
  87. # define fflush(Stream) fflush_unlocked (Stream)
  88. # if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
  89. extern int fflush_unlocked (FILE *);
  90. # endif
  91. # endif
  92. # ifdef HAVE_FGETC_UNLOCKED
  93. # undef fgetc
  94. # define fgetc(Stream) fgetc_unlocked (Stream)
  95. # if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
  96. extern int fgetc_unlocked (FILE *);
  97. # endif
  98. # endif
  99. # ifdef HAVE_FGETS_UNLOCKED
  100. # undef fgets
  101. # define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
  102. # if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
  103. extern char *fgets_unlocked (char *, int, FILE *);
  104. # endif
  105. # endif
  106. # ifdef HAVE_FPUTS_UNLOCKED
  107. # undef fputs
  108. # define fputs(String, Stream) fputs_unlocked (String, Stream)
  109. # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
  110. extern int fputs_unlocked (const char *, FILE *);
  111. # endif
  112. # endif
  113. # ifdef HAVE_FERROR_UNLOCKED
  114. # undef ferror
  115. # define ferror(Stream) ferror_unlocked (Stream)
  116. # if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
  117. extern int ferror_unlocked (FILE *);
  118. # endif
  119. # endif
  120. # ifdef HAVE_FREAD_UNLOCKED
  121. # undef fread
  122. # define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
  123. # if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
  124. extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
  125. # endif
  126. # endif
  127. # ifdef HAVE_FWRITE_UNLOCKED
  128. # undef fwrite
  129. # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
  130. # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
  131. extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
  132. # endif
  133. # endif
  134. # ifdef HAVE_FPRINTF_UNLOCKED
  135. # undef fprintf
  136. /* We can't use a function-like macro here because we don't know if
  137. we have varargs macros. */
  138. # define fprintf fprintf_unlocked
  139. # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
  140. extern int fprintf_unlocked (FILE *, const char *, ...);
  141. # endif
  142. # endif
  143. #endif
  144. /* ??? Glibc's fwrite/fread_unlocked macros cause
  145. "warning: signed and unsigned type in conditional expression". */
  146. #undef fread_unlocked
  147. #undef fwrite_unlocked
  148. #include <sys/types.h>
  149. #include <errno.h>
  150. #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
  151. extern int errno;
  152. #endif
  153. /* Some of glibc's string inlines cause warnings. Plus we'd rather
  154. rely on (and therefore test) GCC's string builtins. */
  155. #define __NO_STRING_INLINES
  156. #ifdef HAVE_STRING_H
  157. # include <string.h>
  158. #else
  159. # ifdef HAVE_STRINGS_H
  160. # include <strings.h>
  161. # endif
  162. #endif
  163. #ifdef HAVE_STDLIB_H
  164. # include <stdlib.h>
  165. #endif
  166. #ifdef HAVE_UNISTD_H
  167. # include <unistd.h>
  168. #endif
  169. #ifdef HAVE_FCNTL_H
  170. # include <fcntl.h>
  171. #else
  172. # ifdef HAVE_SYS_FILE_H
  173. # include <sys/file.h>
  174. # endif
  175. #endif
  176. /* The HAVE_DECL_* macros are three-state, undefined, 0 or 1. If they
  177. are defined to 0 then we must provide the relevant declaration
  178. here. These checks will be in the undefined state while configure
  179. is running so be careful to test "defined (HAVE_DECL_*)". */
  180. #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
  181. extern void abort (void);
  182. #endif
  183. #if HAVE_SYS_STAT_H
  184. # include <sys/stat.h>
  185. #endif
  186. /* Test if something is a normal file. */
  187. #ifndef S_ISREG
  188. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  189. #endif
  190. /* Filename handling macros. */
  191. #include "filenames.h"
  192. /* Get libiberty declarations. */
  193. #include "libiberty.h"
  194. #include "safe-ctype.h"
  195. #endif /* ! FIXINC_SYSTEM_H */