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