1 | /* Header for GNU gettext libiberty |
---|
2 | Copyright (C) 1995-1997, 2000, 2001 Free Software Foundation, Inc. |
---|
3 | |
---|
4 | This program 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 2, or (at your option) |
---|
7 | any later version. |
---|
8 | |
---|
9 | This program 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 this program; if not, write to the Free Software Foundation, |
---|
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
---|
17 | |
---|
18 | #ifndef _SYSTEM_H |
---|
19 | #define _SYSTEM_H 1 |
---|
20 | |
---|
21 | #ifndef PARAMS |
---|
22 | # if defined (__GNUC__) || __STDC__ |
---|
23 | # define PARAMS(args) args |
---|
24 | # else |
---|
25 | # define PARAMS(args) () |
---|
26 | # endif |
---|
27 | #endif |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | #include <sys/types.h> |
---|
31 | |
---|
32 | #if defined STDC_HEADERS |
---|
33 | # include <stdlib.h> |
---|
34 | #else |
---|
35 | # ifdef HAVE_MALLOC_H |
---|
36 | # include <malloc.h> |
---|
37 | # endif |
---|
38 | unsigned long strtoul (); |
---|
39 | #endif |
---|
40 | |
---|
41 | /* Wrapper functions with error checking for standard functions. */ |
---|
42 | extern char *xgetcwd PARAMS ((void)); |
---|
43 | extern void *xmalloc PARAMS ((size_t __n)); |
---|
44 | extern void *xrealloc PARAMS ((void *__p, size_t __n)); |
---|
45 | extern char *xstrdup PARAMS ((const char *__string)); |
---|
46 | extern char *stpcpy PARAMS ((char *__dst, const char *__src)); |
---|
47 | extern char *stpncpy PARAMS ((char *__dst, const char *__src, size_t __n)); |
---|
48 | extern size_t parse_printf_format PARAMS ((const char *__fmt, size_t __n, |
---|
49 | int *__argtypes)); |
---|
50 | extern int asprintf PARAMS ((char **, const char *, ...)); |
---|
51 | extern int strcasecmp PARAMS ((const char *__s1, const char *__s2)); |
---|
52 | extern int strncasecmp PARAMS ((const char *__s1, const char *__s2, |
---|
53 | size_t __n)); |
---|
54 | extern char *strstr PARAMS ((const char *__str, const char *__sub)); |
---|
55 | |
---|
56 | #include <string.h> |
---|
57 | #if !STDC_HEADERS && HAVE_MEMORY_H |
---|
58 | # include <memory.h> |
---|
59 | #endif |
---|
60 | #if !HAVE_MEMCPY |
---|
61 | # ifndef memcpy |
---|
62 | # define memcpy(D, S, N) bcopy ((S), (D), (N)) |
---|
63 | # endif |
---|
64 | #endif |
---|
65 | #if !HAVE_STRCHR |
---|
66 | # ifndef strchr |
---|
67 | # define strchr index |
---|
68 | # endif |
---|
69 | #endif |
---|
70 | |
---|
71 | #ifdef __GNUC__ |
---|
72 | # ifndef alloca |
---|
73 | # define alloca __builtin_alloca |
---|
74 | # endif |
---|
75 | #else |
---|
76 | # if HAVE_ALLOCA_H |
---|
77 | # include <alloca.h> |
---|
78 | # else |
---|
79 | # ifdef _AIX |
---|
80 | #pragma alloca |
---|
81 | # else |
---|
82 | # ifdef __hpux /* This section must match that of bison generated files. */ |
---|
83 | # ifdef __cplusplus |
---|
84 | extern "C" void *alloca (unsigned int); |
---|
85 | # else /* not __cplusplus */ |
---|
86 | void *alloca (); |
---|
87 | # endif /* not __cplusplus */ |
---|
88 | # else /* not __hpux */ |
---|
89 | # ifndef alloca |
---|
90 | char *alloca (); |
---|
91 | # endif |
---|
92 | # endif /* __hpux */ |
---|
93 | # endif |
---|
94 | # endif |
---|
95 | #endif |
---|
96 | |
---|
97 | /* Before we define the following symbols we get the <limits.h> file if |
---|
98 | available since otherwise we get redefinitions on some systems. */ |
---|
99 | #if HAVE_LIMITS_H |
---|
100 | # include <limits.h> |
---|
101 | #endif |
---|
102 | |
---|
103 | #ifndef MAX |
---|
104 | # if __STDC__ && defined __GNUC__ && __GNUC__ >= 2 |
---|
105 | # define MAX(a,b) (__extension__ \ |
---|
106 | ({__typeof__ (a) _a = (a); \ |
---|
107 | __typeof__ (b) _b = (b); \ |
---|
108 | _a > _b ? _a : _b; \ |
---|
109 | })) |
---|
110 | # else |
---|
111 | # define MAX(a,b) ((a) > (b) ? (a) : (b)) |
---|
112 | # endif |
---|
113 | #endif |
---|
114 | |
---|
115 | /* Some systems do not define EXIT_*, even with STDC_HEADERS. */ |
---|
116 | #ifndef EXIT_SUCCESS |
---|
117 | # define EXIT_SUCCESS 0 |
---|
118 | #endif |
---|
119 | #ifndef EXIT_FAILURE |
---|
120 | # define EXIT_FAILURE 1 |
---|
121 | #endif |
---|
122 | |
---|
123 | |
---|
124 | /* Pathname support. |
---|
125 | ISSLASH(C) tests whether C is a directory separator character. |
---|
126 | IS_ABSOLUTE_PATH(P) tests whether P is an absolute path. If it is not, |
---|
127 | it may be concatenated to a directory pathname. |
---|
128 | IS_PATH_WITH_DIR(P) tests whether P contains a directory specification. |
---|
129 | */ |
---|
130 | #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__ |
---|
131 | /* Win32, OS/2, DOS */ |
---|
132 | # define ISSLASH(C) ((C) == '/' || (C) == '\\') |
---|
133 | # define HAS_DEVICE(P) \ |
---|
134 | ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \ |
---|
135 | && (P)[1] == ':') |
---|
136 | # define IS_ABSOLUTE_PATH(P) (ISSLASH ((P)[0]) || HAS_DEVICE (P)) |
---|
137 | # define IS_PATH_WITH_DIR(P) \ |
---|
138 | (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P)) |
---|
139 | # define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0) |
---|
140 | #else |
---|
141 | /* Unix */ |
---|
142 | # define ISSLASH(C) ((C) == '/') |
---|
143 | # define IS_ABSOLUTE_PATH(P) ISSLASH ((P)[0]) |
---|
144 | # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL) |
---|
145 | # define FILESYSTEM_PREFIX_LEN(P) 0 |
---|
146 | #endif |
---|
147 | |
---|
148 | /* Concatenate a directory pathname, a relative pathname and an optional |
---|
149 | suffix. Return a freshly allocated pathname. */ |
---|
150 | extern char *concatenated_pathname PARAMS ((const char *directory, |
---|
151 | const char *filename, |
---|
152 | const char *suffix)); |
---|
153 | |
---|
154 | /* When not using the GNU libc we use the basename implementation we |
---|
155 | provide here. */ |
---|
156 | #ifndef __GNU_LIBRARY__ |
---|
157 | extern char *gnu_basename PARAMS ((const char *)); |
---|
158 | # define basename(Arg) gnu_basename (Arg) |
---|
159 | #endif |
---|
160 | |
---|
161 | |
---|
162 | #include <fcntl.h> |
---|
163 | /* For systems that distinguish between text and binary I/O. |
---|
164 | O_BINARY is usually declared in <fcntl.h>. */ |
---|
165 | #if !defined O_BINARY && defined _O_BINARY |
---|
166 | /* For MSC-compatible compilers. */ |
---|
167 | # define O_BINARY _O_BINARY |
---|
168 | # define O_TEXT _O_TEXT |
---|
169 | #endif |
---|
170 | #ifdef __BEOS__ |
---|
171 | /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ |
---|
172 | # undef O_BINARY |
---|
173 | # undef O_TEXT |
---|
174 | #endif |
---|
175 | #if O_BINARY |
---|
176 | # if !(defined(__EMX__) || defined(__DJGPP__)) |
---|
177 | # define setmode _setmode |
---|
178 | # define fileno _fileno |
---|
179 | # endif |
---|
180 | # ifdef __DJGPP__ |
---|
181 | # include <io.h> /* declares setmode() */ |
---|
182 | # include <unistd.h> /* declares isatty() */ |
---|
183 | # /* Avoid putting stdin/stdout in binary mode if it is connected to the |
---|
184 | # console, because that would make it impossible for the user to |
---|
185 | # interrupt the program through Ctrl-C or Ctrl-Break. */ |
---|
186 | # define SET_BINARY(fd) (!isatty(fd) ? (setmode(fd,O_BINARY), 0) : 0) |
---|
187 | # else |
---|
188 | # define SET_BINARY(fd) setmode(fd,O_BINARY) |
---|
189 | # endif |
---|
190 | #else |
---|
191 | # define SET_BINARY(fd) /* nothing */ |
---|
192 | #endif |
---|
193 | |
---|
194 | #endif |
---|