00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LIBCPP_SYSTEM_H
00025 #define LIBCPP_SYSTEM_H
00026
00027
00028 #include <stdarg.h>
00029
00030 #ifdef HAVE_STDDEF_H
00031 # include <stddef.h>
00032 #endif
00033
00034 #include <stdio.h>
00035
00036
00037 #ifndef NULL
00038 #define NULL 0
00039 #endif
00040
00041
00042 #define fopen(PATH,MODE) fopen_unlocked(PATH,MODE)
00043 #define fdopen(FILDES,MODE) fdopen_unlocked(FILDES,MODE)
00044 #define freopen(PATH,MODE,STREAM) freopen_unlocked(PATH,MODE,STREAM)
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #if defined HAVE_DECL_PUTC_UNLOCKED && HAVE_DECL_PUTC_UNLOCKED
00060
00061 # ifdef HAVE_PUTC_UNLOCKED
00062 # undef putc
00063 # define putc(C, Stream) putc_unlocked (C, Stream)
00064 # endif
00065 # ifdef HAVE_PUTCHAR_UNLOCKED
00066 # undef putchar
00067 # define putchar(C) putchar_unlocked (C)
00068 # endif
00069 # ifdef HAVE_GETC_UNLOCKED
00070 # undef getc
00071 # define getc(Stream) getc_unlocked (Stream)
00072 # endif
00073 # ifdef HAVE_GETCHAR_UNLOCKED
00074 # undef getchar
00075 # define getchar() getchar_unlocked ()
00076 # endif
00077 # ifdef HAVE_FPUTC_UNLOCKED
00078 # undef fputc
00079 # define fputc(C, Stream) fputc_unlocked (C, Stream)
00080 # endif
00081
00082 # ifdef HAVE_CLEARERR_UNLOCKED
00083 # undef clearerr
00084 # define clearerr(Stream) clearerr_unlocked (Stream)
00085 # if defined (HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED
00086 extern void clearerr_unlocked (FILE *);
00087 # endif
00088 # endif
00089 # ifdef HAVE_FEOF_UNLOCKED
00090 # undef feof
00091 # define feof(Stream) feof_unlocked (Stream)
00092 # if defined (HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED
00093 extern int feof_unlocked (FILE *);
00094 # endif
00095 # endif
00096 # ifdef HAVE_FILENO_UNLOCKED
00097 # undef fileno
00098 # define fileno(Stream) fileno_unlocked (Stream)
00099 # if defined (HAVE_DECL_FILENO_UNLOCKED) && !HAVE_DECL_FILENO_UNLOCKED
00100 extern int fileno_unlocked (FILE *);
00101 # endif
00102 # endif
00103 # ifdef HAVE_FFLUSH_UNLOCKED
00104 # undef fflush
00105 # define fflush(Stream) fflush_unlocked (Stream)
00106 # if defined (HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED
00107 extern int fflush_unlocked (FILE *);
00108 # endif
00109 # endif
00110 # ifdef HAVE_FGETC_UNLOCKED
00111 # undef fgetc
00112 # define fgetc(Stream) fgetc_unlocked (Stream)
00113 # if defined (HAVE_DECL_FGETC_UNLOCKED) && !HAVE_DECL_FGETC_UNLOCKED
00114 extern int fgetc_unlocked (FILE *);
00115 # endif
00116 # endif
00117 # ifdef HAVE_FGETS_UNLOCKED
00118 # undef fgets
00119 # define fgets(S, n, Stream) fgets_unlocked (S, n, Stream)
00120 # if defined (HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED
00121 extern char *fgets_unlocked (char *, int, FILE *);
00122 # endif
00123 # endif
00124 # ifdef HAVE_FPUTS_UNLOCKED
00125 # undef fputs
00126 # define fputs(String, Stream) fputs_unlocked (String, Stream)
00127 # if defined (HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED
00128 extern int fputs_unlocked (const char *, FILE *);
00129 # endif
00130 # endif
00131 # ifdef HAVE_FERROR_UNLOCKED
00132 # undef ferror
00133 # define ferror(Stream) ferror_unlocked (Stream)
00134 # if defined (HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED
00135 extern int ferror_unlocked (FILE *);
00136 # endif
00137 # endif
00138 # ifdef HAVE_FREAD_UNLOCKED
00139 # undef fread
00140 # define fread(Ptr, Size, N, Stream) fread_unlocked (Ptr, Size, N, Stream)
00141 # if defined (HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED
00142 extern size_t fread_unlocked (void *, size_t, size_t, FILE *);
00143 # endif
00144 # endif
00145 # ifdef HAVE_FWRITE_UNLOCKED
00146 # undef fwrite
00147 # define fwrite(Ptr, Size, N, Stream) fwrite_unlocked (Ptr, Size, N, Stream)
00148 # if defined (HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED
00149 extern size_t fwrite_unlocked (const void *, size_t, size_t, FILE *);
00150 # endif
00151 # endif
00152 # ifdef HAVE_FPRINTF_UNLOCKED
00153 # undef fprintf
00154
00155
00156 # define fprintf fprintf_unlocked
00157 # if defined (HAVE_DECL_FPRINTF_UNLOCKED) && !HAVE_DECL_FPRINTF_UNLOCKED
00158 extern int fprintf_unlocked (FILE *, const char *, ...);
00159 # endif
00160 # endif
00161
00162 #endif
00163
00164
00165
00166 #undef fread_unlocked
00167 #undef fwrite_unlocked
00168
00169 #include <sys/types.h>
00170 #include <errno.h>
00171
00172 #if !defined (errno) && defined (HAVE_DECL_ERRNO) && !HAVE_DECL_ERRNO
00173 extern int errno;
00174 #endif
00175
00176
00177
00178 #define __NO_STRING_INLINES
00179
00180 #ifdef STRING_WITH_STRINGS
00181 # include <string.h>
00182 # include <strings.h>
00183 #else
00184 # ifdef HAVE_STRING_H
00185 # include <string.h>
00186 # else
00187 # ifdef HAVE_STRINGS_H
00188 # include <strings.h>
00189 # endif
00190 # endif
00191 #endif
00192
00193 #ifdef HAVE_STDLIB_H
00194 # include <stdlib.h>
00195 #endif
00196
00197 #ifdef HAVE_UNISTD_H
00198 # include <unistd.h>
00199 #endif
00200
00201 #if HAVE_LIMITS_H
00202 # include <limits.h>
00203 #endif
00204
00205
00206
00207
00208
00209 #define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
00210
00211
00212 #define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
00213 ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
00214 #define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
00215
00216
00217 #ifndef UCHAR_MAX
00218 # define UCHAR_MAX INTTYPE_MAXIMUM (unsigned char)
00219 #endif
00220
00221 #ifdef TIME_WITH_SYS_TIME
00222 # include <sys/time.h>
00223 # include <time.h>
00224 #else
00225 # if HAVE_SYS_TIME_H
00226 # include <sys/time.h>
00227 # else
00228 # ifdef HAVE_TIME_H
00229 # include <time.h>
00230 # endif
00231 # endif
00232 #endif
00233
00234 #ifdef HAVE_FCNTL_H
00235 # include <fcntl.h>
00236 #else
00237 # ifdef HAVE_SYS_FILE_H
00238 # include <sys/file.h>
00239 # endif
00240 #endif
00241
00242 #ifdef HAVE_LOCALE_H
00243 # include <locale.h>
00244 #endif
00245
00246 #ifdef HAVE_LANGINFO_CODESET
00247 # include <langinfo.h>
00248 #endif
00249
00250 #ifndef HAVE_SETLOCALE
00251 # define setlocale(category, locale) (locale)
00252 #endif
00253
00254 #ifdef ENABLE_NLS
00255 #include <libintl.h>
00256 #else
00257
00258 # undef dgettext
00259 # define dgettext(package, msgid) (msgid)
00260 #endif
00261
00262 #ifndef _
00263 # define _(msgid) dgettext (PACKAGE, msgid)
00264 #endif
00265
00266 #ifndef N_
00267 # define N_(msgid) msgid
00268 #endif
00269
00270
00271
00272
00273
00274 #undef MIN
00275 #undef MAX
00276 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
00277 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
00278
00279
00280
00281
00282
00283
00284 #if defined (HAVE_DECL_ABORT) && !HAVE_DECL_ABORT
00285 extern void abort (void);
00286 #endif
00287
00288 #if HAVE_SYS_STAT_H
00289 # include <sys/stat.h>
00290 #endif
00291
00292
00293 #ifndef S_ISREG
00294 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
00295 #endif
00296
00297
00298 #ifndef S_ISDIR
00299 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
00300 #endif
00301
00302
00303 #ifndef S_ISCHR
00304 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
00305 #endif
00306
00307
00308 #ifndef S_ISBLK
00309 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
00310 #endif
00311
00312
00313 #ifndef S_ISSOCK
00314 # ifdef S_IFSOCK
00315 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
00316 # else
00317 # define S_ISSOCK(m) 0
00318 # endif
00319 #endif
00320
00321
00322 #ifndef S_ISFIFO
00323 # ifdef S_IFIFO
00324 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
00325 # else
00326 # define S_ISFIFO(m) 0
00327 # endif
00328 #endif
00329
00330
00331 #ifndef O_NOCTTY
00332 #define O_NOCTTY 0
00333 #endif
00334 #ifndef O_BINARY
00335 # define O_BINARY 0
00336 #endif
00337
00338
00339 #include "filenames.h"
00340
00341
00342 #include "libiberty.h"
00343 #include "safe-ctype.h"
00344
00345
00346
00347
00348
00349 #if !defined(HAVE_DESIGNATED_INITIALIZERS)
00350 #define HAVE_DESIGNATED_INITIALIZERS \
00351 ((!defined(__cplusplus) && (GCC_VERSION >= 2007)) \
00352 || (__STDC_VERSION__ >= 199901L))
00353 #endif
00354
00355
00356
00357
00358 #if (GCC_VERSION > 2000)
00359 #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
00360 #else
00361 #define ENUM_BITFIELD(TYPE) unsigned int
00362 #endif
00363
00364 #ifndef offsetof
00365 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
00366 #endif
00367
00368
00369
00370
00371 #if (GCC_VERSION < 3000)
00372 #define __builtin_expect(a, b) (a)
00373 #endif
00374
00375
00376
00377
00378
00379
00380 #undef bool
00381 #undef true
00382 #undef false
00383 #undef TRUE
00384 #undef FALSE
00385
00386 #ifndef __cplusplus
00387 #define bool unsigned char
00388 #endif
00389 #define true 1
00390 #define false 0
00391
00392
00393 #define BOOL_BITFIELD unsigned int
00394
00395
00396 #if (GCC_VERSION >= 3000)
00397 #undef calloc
00398 #undef strdup
00399 #undef malloc
00400 #undef realloc
00401 #pragma GCC poison calloc strdup
00402 #pragma GCC poison malloc realloc
00403
00404
00405 #undef ANSI_PROTOTYPES
00406 #undef PTR_CONST
00407 #undef LONG_DOUBLE
00408 #undef VPARAMS
00409 #undef VA_OPEN
00410 #undef VA_FIXEDARG
00411 #undef VA_CLOSE
00412 #undef VA_START
00413 #pragma GCC poison ANSI_PROTOTYPES PTR_CONST LONG_DOUBLE VPARAMS VA_OPEN \
00414 VA_FIXEDARG VA_CLOSE VA_START
00415
00416
00417
00418 #undef bcopy
00419 #undef bzero
00420 #undef bcmp
00421 #undef rindex
00422 #pragma GCC poison bcopy bzero bcmp rindex
00423
00424 #endif
00425 #endif