compat_defs.h revision 1.60 1 1.60 apb /* $NetBSD: compat_defs.h,v 1.60 2007/08/07 08:22:04 apb Exp $ */
2 1.1 thorpej
3 1.1 thorpej #ifndef __NETBSD_COMPAT_DEFS_H__
4 1.1 thorpej #define __NETBSD_COMPAT_DEFS_H__
5 1.1 thorpej
6 1.4 tv /* Work around some complete brain damage. */
7 1.4 tv
8 1.4 tv /*
9 1.4 tv * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the
10 1.4 tv * program (not the OS) should do that. Preload <features.h> to keep any
11 1.4 tv * of this crap from being pulled in, and undefine _POSIX_SOURCE.
12 1.4 tv */
13 1.4 tv
14 1.4 tv #if defined(__linux__) && HAVE_FEATURES_H
15 1.4 tv #include <features.h>
16 1.4 tv #endif
17 1.4 tv
18 1.39 jmc /* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard
19 1.39 jmc defs. Other platforms may need similiar defines. */
20 1.39 jmc #ifdef __NetBSD__
21 1.43 tron #define _ISOC99_SOURCE
22 1.39 jmc #define _POSIX_SOURCE 1
23 1.39 jmc #define _POSIX_C_SOURCE 200112L
24 1.39 jmc #define _XOPEN_SOURCE 600
25 1.39 jmc #else
26 1.4 tv #undef _POSIX_SOURCE
27 1.4 tv #undef _POSIX_C_SOURCE
28 1.39 jmc #endif
29 1.4 tv
30 1.1 thorpej /* System headers needed for (re)definitions below. */
31 1.1 thorpej
32 1.1 thorpej #include <sys/types.h>
33 1.3 tv #include <sys/mman.h>
34 1.3 tv #include <sys/param.h>
35 1.39 jmc /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
36 1.39 jmc #include <sys/time.h>
37 1.3 tv #include <sys/stat.h>
38 1.1 thorpej #include <errno.h>
39 1.1 thorpej #include <fcntl.h>
40 1.2 lukem #include <grp.h>
41 1.1 thorpej #include <limits.h>
42 1.1 thorpej #include <paths.h>
43 1.3 tv #include <stdarg.h>
44 1.1 thorpej #include <stdio.h>
45 1.3 tv #include <stdlib.h>
46 1.1 thorpej #include <string.h>
47 1.1 thorpej
48 1.3 tv #if HAVE_SYS_CDEFS_H
49 1.3 tv #include <sys/cdefs.h>
50 1.3 tv #endif
51 1.6 tv #if HAVE_SYS_SYSLIMITS_H
52 1.6 tv #include <sys/syslimits.h>
53 1.6 tv #endif
54 1.3 tv #if HAVE_SYS_SYSMACROS_H
55 1.3 tv /* major(), minor() on SVR4 */
56 1.3 tv #include <sys/sysmacros.h>
57 1.3 tv #endif
58 1.1 thorpej #if HAVE_INTTYPES_H
59 1.1 thorpej #include <inttypes.h>
60 1.1 thorpej #endif
61 1.1 thorpej #if HAVE_STDDEF_H
62 1.1 thorpej #include <stddef.h>
63 1.1 thorpej #endif
64 1.3 tv
65 1.42 jmc #ifdef _NETBSD_SOURCE
66 1.42 jmc #error _NETBSD_SOURCE is *not* to be defined.
67 1.42 jmc #endif
68 1.42 jmc
69 1.45 jmc /* Need this since we can't depend on NetBSD's version to be around */
70 1.45 jmc #ifdef __UNCONST
71 1.45 jmc #undef __UNCONST
72 1.45 jmc #endif
73 1.45 jmc #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
74 1.45 jmc
75 1.3 tv /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
76 1.3 tv struct passwd;
77 1.3 tv
78 1.3 tv /* Assume an ANSI compiler for the host. */
79 1.3 tv
80 1.3 tv #undef __P
81 1.3 tv #define __P(x) x
82 1.3 tv
83 1.3 tv #ifndef __BEGIN_DECLS
84 1.3 tv #define __BEGIN_DECLS
85 1.3 tv #endif
86 1.3 tv #ifndef __END_DECLS
87 1.3 tv #define __END_DECLS
88 1.3 tv #endif
89 1.3 tv
90 1.4 tv /* Some things usually in BSD <sys/cdefs.h>. */
91 1.3 tv
92 1.12 bjh21 #ifndef __CONCAT
93 1.12 bjh21 #define __CONCAT(x,y) x ## y
94 1.12 bjh21 #endif
95 1.1 thorpej #if !defined(__attribute__) && !defined(__GNUC__)
96 1.1 thorpej #define __attribute__(x)
97 1.1 thorpej #endif
98 1.34 matt #if !defined(__packed)
99 1.34 matt #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
100 1.34 matt #define __packed __attribute__((__packed__))
101 1.34 matt #else
102 1.34 matt #define __packed error: no __packed for this compiler
103 1.34 matt #endif
104 1.34 matt #endif /* !__packed */
105 1.3 tv #ifndef __RENAME
106 1.3 tv #define __RENAME(x)
107 1.3 tv #endif
108 1.3 tv #undef __aconst
109 1.3 tv #define __aconst
110 1.3 tv #undef __dead
111 1.3 tv #define __dead
112 1.17 bjh21 #undef __restrict
113 1.17 bjh21 #define __restrict
114 1.57 christos #undef __unused
115 1.57 christos #define __unused
116 1.3 tv
117 1.3 tv /* Dirent support. */
118 1.3 tv
119 1.3 tv #if HAVE_DIRENT_H
120 1.48 tron # if defined(__linux__) && defined(__USE_BSD)
121 1.48 tron # undef __USE_BSD
122 1.48 tron # include <dirent.h>
123 1.48 tron # define __USE_BSD 1
124 1.48 tron # undef d_fileno
125 1.48 tron # else
126 1.48 tron # include <dirent.h>
127 1.52 dyoung # if defined(__DARWIN_UNIX03)
128 1.52 dyoung # undef d_fileno
129 1.52 dyoung # endif
130 1.48 tron # endif
131 1.3 tv # define NAMLEN(dirent) (strlen((dirent)->d_name))
132 1.3 tv #else
133 1.3 tv # define dirent direct
134 1.3 tv # define NAMLEN(dirent) ((dirent)->d_namlen)
135 1.3 tv # if HAVE_SYS_NDIR_H
136 1.3 tv # include <sys/ndir.h>
137 1.3 tv # endif
138 1.3 tv # if HAVE_SYS_DIR_H
139 1.3 tv # include <sys/dir.h>
140 1.3 tv # endif
141 1.3 tv # if HAVE_NDIR_H
142 1.3 tv # include <ndir.h>
143 1.3 tv # endif
144 1.3 tv #endif
145 1.3 tv
146 1.1 thorpej /* Type substitutes. */
147 1.1 thorpej
148 1.1 thorpej #if !HAVE_ID_T
149 1.58 ginsbach typedef unsigned int id_t;
150 1.26 thorpej #endif
151 1.26 thorpej
152 1.26 thorpej #if !HAVE_SOCKLEN_T
153 1.26 thorpej typedef int socklen_t;
154 1.28 fredb #endif
155 1.28 fredb
156 1.28 fredb #if !HAVE_U_LONG
157 1.28 fredb typedef unsigned long u_long;
158 1.1 thorpej #endif
159 1.1 thorpej
160 1.39 jmc #if !HAVE_U_CHAR
161 1.39 jmc typedef unsigned char u_char;
162 1.39 jmc #endif
163 1.39 jmc
164 1.39 jmc #if !HAVE_U_INT
165 1.39 jmc typedef unsigned int u_int;
166 1.39 jmc #endif
167 1.39 jmc
168 1.39 jmc #if !HAVE_U_SHORT
169 1.39 jmc typedef unsigned short u_short;
170 1.39 jmc #endif
171 1.39 jmc
172 1.1 thorpej /* Prototypes for replacement functions. */
173 1.27 uwe
174 1.27 uwe #if !HAVE_ATOLL
175 1.27 uwe long long int atoll(const char *);
176 1.27 uwe #endif
177 1.1 thorpej
178 1.3 tv #if !HAVE_ASPRINTF
179 1.3 tv int asprintf(char **, const char *, ...);
180 1.3 tv #endif
181 1.3 tv
182 1.3 tv #if !HAVE_ASNPRINTF
183 1.3 tv int asnprintf(char **, size_t, const char *, ...);
184 1.3 tv #endif
185 1.3 tv
186 1.1 thorpej #if !HAVE_BASENAME
187 1.1 thorpej char *basename(char *);
188 1.1 thorpej #endif
189 1.1 thorpej
190 1.4 tv #if !HAVE_DECL_OPTIND
191 1.4 tv int getopt(int, char *const *, const char *);
192 1.4 tv extern char *optarg;
193 1.4 tv extern int optind, opterr, optopt;
194 1.4 tv #endif
195 1.4 tv
196 1.1 thorpej #if !HAVE_DIRNAME
197 1.1 thorpej char *dirname(char *);
198 1.1 thorpej #endif
199 1.1 thorpej
200 1.3 tv #if !HAVE_DIRFD
201 1.3 tv #if HAVE_DIR_DD_FD
202 1.3 tv #define dirfd(dirp) ((dirp)->dd_fd)
203 1.53 thorpej #elif HAVE_DIR___DD_FD
204 1.53 thorpej #define dirfd(dirp) ((dirp)->__dd_fd)
205 1.3 tv #else
206 1.39 jmc /*XXX: Very hacky but no other way to bring this into scope w/o defining
207 1.39 jmc _NETBSD_SOURCE which we're avoiding. */
208 1.39 jmc #ifdef __NetBSD__
209 1.39 jmc struct _dirdesc {
210 1.39 jmc int dd_fd; /* file descriptor associated with directory */
211 1.39 jmc long dd_loc; /* offset in current buffer */
212 1.39 jmc long dd_size; /* amount of data returned by getdents */
213 1.39 jmc char *dd_buf; /* data buffer */
214 1.39 jmc int dd_len; /* size of data buffer */
215 1.39 jmc off_t dd_seek; /* magic cookie returned by getdents */
216 1.39 jmc long dd_rewind; /* magic cookie for rewinding */
217 1.39 jmc int dd_flags; /* flags for readdir */
218 1.39 jmc void *dd_lock; /* lock for concurrent access */
219 1.39 jmc };
220 1.39 jmc #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
221 1.39 jmc #else
222 1.3 tv #error cannot figure out how to turn a DIR * into a fd
223 1.3 tv #endif
224 1.3 tv #endif
225 1.39 jmc #endif
226 1.3 tv
227 1.1 thorpej #if !HAVE_ERR_H
228 1.3 tv void err(int, const char *, ...);
229 1.3 tv void errx(int, const char *, ...);
230 1.1 thorpej void warn(const char *, ...);
231 1.1 thorpej void warnx(const char *, ...);
232 1.1 thorpej #endif
233 1.1 thorpej
234 1.56 christos #if !HAVE_ESETFUNC
235 1.56 christos void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
236 1.56 christos size_t estrlcpy(char *, const char *, size_t);
237 1.56 christos size_t estrlcat(char *, const char *, size_t);
238 1.56 christos char *estrdup(const char *);
239 1.59 nakayama char *estrndup(const char *, size_t);
240 1.56 christos void *ecalloc(size_t, size_t);
241 1.56 christos void *emalloc(size_t);
242 1.56 christos void *erealloc(void *, size_t);
243 1.56 christos FILE *efopen(const char *, const char *);
244 1.56 christos int easprintf(char **, const char *, ...);
245 1.56 christos int evasprintf(char **, const char *, va_list);
246 1.56 christos #endif
247 1.56 christos
248 1.39 jmc #if !HAVE_FGETLN || defined(__NetBSD__)
249 1.1 thorpej char *fgetln(FILE *, size_t *);
250 1.1 thorpej #endif
251 1.1 thorpej
252 1.1 thorpej #if !HAVE_FLOCK
253 1.1 thorpej # define LOCK_SH 0x01
254 1.1 thorpej # define LOCK_EX 0x02
255 1.1 thorpej # define LOCK_NB 0x04
256 1.1 thorpej # define LOCK_UN 0x08
257 1.1 thorpej int flock(int, int);
258 1.1 thorpej #endif
259 1.1 thorpej
260 1.39 jmc #if !HAVE_FPARSELN || defined(__NetBSD__)
261 1.1 thorpej # define FPARSELN_UNESCESC 0x01
262 1.1 thorpej # define FPARSELN_UNESCCONT 0x02
263 1.1 thorpej # define FPARSELN_UNESCCOMM 0x04
264 1.1 thorpej # define FPARSELN_UNESCREST 0x08
265 1.1 thorpej # define FPARSELN_UNESCALL 0x0f
266 1.1 thorpej char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
267 1.10 bjh21 #endif
268 1.10 bjh21
269 1.10 bjh21 #if !HAVE_ISSETUGID
270 1.10 bjh21 int issetugid(void);
271 1.1 thorpej #endif
272 1.1 thorpej
273 1.3 tv #if !HAVE_ISBLANK && !defined(isblank)
274 1.3 tv #define isblank(x) ((x) == ' ' || (x) == '\t')
275 1.21 lukem #endif
276 1.21 lukem
277 1.21 lukem #if !HAVE_LCHFLAGS
278 1.21 lukem int lchflags(const char *, u_long);
279 1.21 lukem #endif
280 1.21 lukem
281 1.21 lukem #if !HAVE_LCHMOD
282 1.21 lukem int lchmod(const char *, mode_t);
283 1.21 lukem #endif
284 1.21 lukem
285 1.21 lukem #if !HAVE_LCHOWN
286 1.21 lukem int lchown(const char *, uid_t, gid_t);
287 1.1 thorpej #endif
288 1.1 thorpej
289 1.39 jmc #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
290 1.39 jmc
291 1.39 jmc #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
292 1.39 jmc (((x) << 8) & 0x00ff0000) | \
293 1.39 jmc (((x) >> 8) & 0x0000ff00) | \
294 1.39 jmc (((x) >> 24) & 0x000000ff))
295 1.4 tv
296 1.39 jmc #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
297 1.39 jmc ((u_int64_t)bswap32((x) >> 32)))
298 1.4 tv
299 1.50 wiz #if ! HAVE_DECL_BSWAP16
300 1.39 jmc #ifdef bswap16
301 1.39 jmc #undef bswap16
302 1.39 jmc #endif
303 1.39 jmc #define bswap16(x) __nbcompat_bswap16(x)
304 1.39 jmc #endif
305 1.50 wiz #if ! HAVE_DECL_BSWAP32
306 1.39 jmc #ifdef bswap32
307 1.39 jmc #undef bswap32
308 1.39 jmc #endif
309 1.39 jmc #define bswap32(x) __nbcompat_bswap32(x)
310 1.39 jmc #endif
311 1.50 wiz #if ! HAVE_DECL_BSWAP64
312 1.39 jmc #ifdef bswap64
313 1.39 jmc #undef bswap64
314 1.39 jmc #endif
315 1.39 jmc #define bswap64(x) __nbcompat_bswap64(x)
316 1.18 thorpej #endif
317 1.18 thorpej
318 1.18 thorpej #if !HAVE_MKSTEMP
319 1.18 thorpej int mkstemp(char *);
320 1.18 thorpej #endif
321 1.18 thorpej
322 1.18 thorpej #if !HAVE_MKDTEMP
323 1.18 thorpej char *mkdtemp(char *);
324 1.18 thorpej #endif
325 1.18 thorpej
326 1.18 thorpej #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
327 1.18 thorpej /* This is a prototype for the internal function. */
328 1.18 thorpej int gettemp(char *, int *, int);
329 1.4 tv #endif
330 1.4 tv
331 1.1 thorpej #if !HAVE_PREAD
332 1.1 thorpej ssize_t pread(int, void *, size_t, off_t);
333 1.2 lukem #endif
334 1.2 lukem
335 1.44 jmc #if !HAVE_HEAPSORT
336 1.44 jmc int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
337 1.44 jmc #endif
338 1.44 jmc /* Make them use our version */
339 1.44 jmc # define heapsort __nbcompat_heapsort
340 1.44 jmc
341 1.2 lukem #if !HAVE_PWCACHE_USERDB
342 1.2 lukem int uid_from_user(const char *, uid_t *);
343 1.2 lukem int pwcache_userdb(int (*)(int), void (*)(void),
344 1.2 lukem struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
345 1.2 lukem int gid_from_group(const char *, gid_t *);
346 1.2 lukem int pwcache_groupdb(int (*)(int), void (*)(void),
347 1.2 lukem struct group * (*)(const char *), struct group * (*)(gid_t));
348 1.39 jmc #endif
349 1.35 sjg /* Make them use our version */
350 1.35 sjg # define user_from_uid __nbcompat_user_from_uid
351 1.37 thorpej /* Make them use our version */
352 1.35 sjg # define group_from_gid __nbcompat_group_from_gid
353 1.1 thorpej
354 1.1 thorpej #if !HAVE_PWRITE
355 1.1 thorpej ssize_t pwrite(int, const void *, size_t, off_t);
356 1.1 thorpej #endif
357 1.1 thorpej
358 1.3 tv #if !HAVE_SETENV
359 1.3 tv int setenv(const char *, const char *, int);
360 1.3 tv #endif
361 1.3 tv
362 1.6 tv #if !HAVE_DECL_SETGROUPENT
363 1.3 tv int setgroupent(int);
364 1.3 tv #endif
365 1.3 tv
366 1.6 tv #if !HAVE_DECL_SETPASSENT
367 1.3 tv int setpassent(int);
368 1.3 tv #endif
369 1.3 tv
370 1.39 jmc #if !HAVE_SETPROGNAME || defined(__NetBSD__)
371 1.3 tv const char *getprogname(void);
372 1.3 tv void setprogname(const char *);
373 1.3 tv #endif
374 1.3 tv
375 1.3 tv #if !HAVE_SNPRINTF
376 1.3 tv int snprintf(char *, size_t, const char *, ...);
377 1.3 tv #endif
378 1.3 tv
379 1.3 tv #if !HAVE_STRLCAT
380 1.3 tv size_t strlcat(char *, const char *, size_t);
381 1.3 tv #endif
382 1.3 tv
383 1.3 tv #if !HAVE_STRLCPY
384 1.3 tv size_t strlcpy(char *, const char *, size_t);
385 1.3 tv #endif
386 1.3 tv
387 1.55 apb #if !HAVE_STRMODE
388 1.55 apb void strmode(mode_t, char *);
389 1.55 apb #endif
390 1.55 apb
391 1.59 nakayama #if !HAVE_STRNDUP
392 1.59 nakayama char *strndup(const char *, size_t);
393 1.59 nakayama #endif
394 1.59 nakayama
395 1.39 jmc #if !HAVE_STRSEP || defined(__NetBSD__)
396 1.3 tv char *strsep(char **, const char *);
397 1.23 lukem #endif
398 1.23 lukem
399 1.51 wiz #if !HAVE_DECL_STRSUFTOLL
400 1.23 lukem long long strsuftoll(const char *, const char *, long long, long long);
401 1.23 lukem long long strsuftollx(const char *, const char *,
402 1.23 lukem long long, long long, char *, size_t);
403 1.16 pooka #endif
404 1.16 pooka
405 1.20 lukem #if !HAVE_STRTOLL
406 1.20 lukem long long strtoll(const char *, char **, int);
407 1.20 lukem #endif
408 1.20 lukem
409 1.16 pooka #if !HAVE_USER_FROM_UID
410 1.16 pooka const char *user_from_uid(uid_t, int);
411 1.38 thorpej #endif
412 1.38 thorpej
413 1.38 thorpej #if !HAVE_GROUP_FROM_GID
414 1.16 pooka const char *group_from_gid(gid_t, int);
415 1.3 tv #endif
416 1.3 tv
417 1.3 tv #if !HAVE_VASPRINTF
418 1.3 tv int vasprintf(char **, const char *, va_list);
419 1.3 tv #endif
420 1.3 tv
421 1.3 tv #if !HAVE_VASNPRINTF
422 1.3 tv int vasnprintf(char **, size_t, const char *, va_list);
423 1.3 tv #endif
424 1.3 tv
425 1.3 tv #if !HAVE_VSNPRINTF
426 1.3 tv int vsnprintf(char *, size_t, const char *, va_list);
427 1.3 tv #endif
428 1.3 tv
429 1.1 thorpej /*
430 1.1 thorpej * getmode() and setmode() are always defined, as these function names
431 1.1 thorpej * exist but with very different meanings on other OS's. The compat
432 1.1 thorpej * versions here simply accept an octal mode number; the "u+x,g-w" type
433 1.1 thorpej * of syntax is not accepted.
434 1.1 thorpej */
435 1.1 thorpej
436 1.1 thorpej #define getmode __nbcompat_getmode
437 1.1 thorpej #define setmode __nbcompat_setmode
438 1.1 thorpej
439 1.1 thorpej mode_t getmode(const void *, mode_t);
440 1.1 thorpej void *setmode(const char *);
441 1.1 thorpej
442 1.3 tv /* Eliminate assertions embedded in binaries. */
443 1.1 thorpej
444 1.1 thorpej #undef _DIAGASSERT
445 1.3 tv #define _DIAGASSERT(x)
446 1.4 tv
447 1.31 lukem /* Various sources use this */
448 1.31 lukem #undef __RCSID
449 1.31 lukem #define __RCSID(x)
450 1.31 lukem #undef __SCCSID
451 1.31 lukem #define __SCCSID(x)
452 1.31 lukem #undef __COPYRIGHT
453 1.31 lukem #define __COPYRIGHT(x)
454 1.31 lukem #undef __KERNEL_RCSID
455 1.31 lukem #define __KERNEL_RCSID(x,y)
456 1.31 lukem
457 1.4 tv /* Heimdal expects this one. */
458 1.4 tv
459 1.3 tv #undef RCSID
460 1.3 tv #define RCSID(x)
461 1.1 thorpej
462 1.3 tv /* Some definitions not available on all systems. */
463 1.1 thorpej
464 1.4 tv /* <errno.h> */
465 1.4 tv
466 1.4 tv #ifndef EFTYPE
467 1.4 tv #define EFTYPE EIO
468 1.4 tv #endif
469 1.4 tv
470 1.4 tv /* <fcntl.h> */
471 1.4 tv
472 1.4 tv #ifndef O_EXLOCK
473 1.4 tv #define O_EXLOCK 0
474 1.4 tv #endif
475 1.4 tv #ifndef O_SHLOCK
476 1.4 tv #define O_SHLOCK 0
477 1.4 tv #endif
478 1.4 tv
479 1.8 bjh21 /* <limits.h> */
480 1.4 tv
481 1.4 tv #ifndef UID_MAX
482 1.4 tv #define UID_MAX 32767
483 1.4 tv #endif
484 1.4 tv #ifndef GID_MAX
485 1.4 tv #define GID_MAX UID_MAX
486 1.4 tv #endif
487 1.4 tv
488 1.4 tv #ifndef UQUAD_MAX
489 1.4 tv #define UQUAD_MAX ((u_quad_t)-1)
490 1.4 tv #endif
491 1.4 tv #ifndef QUAD_MAX
492 1.4 tv #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
493 1.4 tv #endif
494 1.4 tv #ifndef QUAD_MIN
495 1.4 tv #define QUAD_MIN ((quad_t)(~QUAD_MAX))
496 1.4 tv #endif
497 1.4 tv #ifndef ULLONG_MAX
498 1.4 tv #define ULLONG_MAX ((unsigned long long)-1)
499 1.4 tv #endif
500 1.4 tv #ifndef LLONG_MAX
501 1.4 tv #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
502 1.4 tv #endif
503 1.4 tv #ifndef LLONG_MIN
504 1.4 tv #define LLONG_MIN ((long long)(~LLONG_MAX))
505 1.3 tv #endif
506 1.1 thorpej
507 1.4 tv /* <paths.h> */
508 1.4 tv
509 1.54 apb /* The host's _PATH_BSHELL might be broken, so override it. */
510 1.54 apb #undef _PATH_BSHELL
511 1.15 bjh21 #define _PATH_BSHELL PATH_BSHELL
512 1.1 thorpej #ifndef _PATH_DEFPATH
513 1.1 thorpej #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
514 1.1 thorpej #endif
515 1.1 thorpej #ifndef _PATH_DEV
516 1.1 thorpej #define _PATH_DEV "/dev/"
517 1.1 thorpej #endif
518 1.1 thorpej #ifndef _PATH_DEVNULL
519 1.1 thorpej #define _PATH_DEVNULL _PATH_DEV "null"
520 1.1 thorpej #endif
521 1.1 thorpej #ifndef _PATH_TMP
522 1.1 thorpej #define _PATH_TMP "/tmp/"
523 1.22 christos #endif
524 1.22 christos #ifndef _PATH_DEFTAPE
525 1.22 christos #define _PATH_DEFTAPE "/dev/nrst0"
526 1.1 thorpej #endif
527 1.46 tron #ifndef _PATH_VI
528 1.46 tron #define _PATH_VI "/usr/bin/vi"
529 1.46 tron #endif
530 1.1 thorpej
531 1.4 tv /* <stdarg.h> */
532 1.3 tv
533 1.4 tv #ifndef _BSD_VA_LIST_
534 1.4 tv #define _BSD_VA_LIST_ va_list
535 1.9 bjh21 #endif
536 1.9 bjh21
537 1.13 bjh21 /* <stdint.h> */
538 1.30 uwe
539 1.30 uwe #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
540 1.30 uwe #define SIZE_MAX SIZE_T_MAX
541 1.30 uwe #endif
542 1.13 bjh21
543 1.47 uwe #ifndef UINT8_MAX
544 1.47 uwe #define UINT8_MAX 0xffU
545 1.47 uwe #endif
546 1.47 uwe
547 1.47 uwe #ifndef UINT16_MAX
548 1.47 uwe #define UINT16_MAX 0xffffU
549 1.47 uwe #endif
550 1.47 uwe
551 1.13 bjh21 #ifndef UINT32_MAX
552 1.13 bjh21 #define UINT32_MAX 0xffffffffU
553 1.14 bjh21 #endif
554 1.14 bjh21
555 1.14 bjh21 /* <stdlib.h> */
556 1.14 bjh21
557 1.14 bjh21 #ifndef __GNUC__
558 1.14 bjh21 # if HAVE_ALLOCA_H
559 1.14 bjh21 # include <alloca.h>
560 1.14 bjh21 # else
561 1.14 bjh21 # ifndef alloca /* predefined by HP cc +Olibcalls */
562 1.14 bjh21 char *alloca ();
563 1.14 bjh21 # endif
564 1.14 bjh21 # endif
565 1.13 bjh21 #endif
566 1.25 uwe
567 1.25 uwe /* avoid prototype conflicts with host */
568 1.25 uwe #define cgetcap __nbcompat_cgetcap
569 1.25 uwe #define cgetclose __nbcompat_cgetclose
570 1.25 uwe #define cgetent __nbcompat_cgetent
571 1.25 uwe #define cgetfirst __nbcompat_cgetfirst
572 1.25 uwe #define cgetmatch __nbcompat_cgetmatch
573 1.25 uwe #define cgetnext __nbcompat_cgetnext
574 1.25 uwe #define cgetnum __nbcompat_cgetnum
575 1.25 uwe #define cgetset __nbcompat_cgetset
576 1.25 uwe #define cgetstr __nbcompat_cgetstr
577 1.25 uwe #define cgetustr __nbcompat_cgetustr
578 1.25 uwe
579 1.25 uwe char *cgetcap(char *, const char *, int);
580 1.25 uwe int cgetclose(void);
581 1.33 christos int cgetent(char **, const char * const *, const char *);
582 1.33 christos int cgetfirst(char **, const char * const *);
583 1.25 uwe int cgetmatch(const char *, const char *);
584 1.33 christos int cgetnext(char **, const char * const *);
585 1.25 uwe int cgetnum(char *, const char *, long *);
586 1.25 uwe int cgetset(const char *);
587 1.25 uwe int cgetstr(char *, const char *, char **);
588 1.25 uwe int cgetustr(char *, const char *, char **);
589 1.13 bjh21
590 1.9 bjh21 /* <sys/endian.h> */
591 1.9 bjh21
592 1.9 bjh21 #if WORDS_BIGENDIAN
593 1.49 dogcow #if !HAVE_DECL_HTOBE16
594 1.9 bjh21 #define htobe16(x) (x)
595 1.39 jmc #endif
596 1.49 dogcow #if !HAVE_DECL_HTOBE32
597 1.9 bjh21 #define htobe32(x) (x)
598 1.39 jmc #endif
599 1.49 dogcow #if !HAVE_DECL_HTOBE64
600 1.9 bjh21 #define htobe64(x) (x)
601 1.39 jmc #endif
602 1.49 dogcow #if !HAVE_DECL_HTOLE16
603 1.9 bjh21 #define htole16(x) bswap16((u_int16_t)(x))
604 1.39 jmc #endif
605 1.49 dogcow #if !HAVE_DECL_HTOLE32
606 1.9 bjh21 #define htole32(x) bswap32((u_int32_t)(x))
607 1.39 jmc #endif
608 1.49 dogcow #if !HAVE_DECL_HTOLE64
609 1.9 bjh21 #define htole64(x) bswap64((u_int64_t)(x))
610 1.39 jmc #endif
611 1.9 bjh21 #else
612 1.49 dogcow #if !HAVE_DECL_HTOBE16
613 1.9 bjh21 #define htobe16(x) bswap16((u_int16_t)(x))
614 1.39 jmc #endif
615 1.49 dogcow #if !HAVE_DECL_HTOBE32
616 1.9 bjh21 #define htobe32(x) bswap32((u_int32_t)(x))
617 1.39 jmc #endif
618 1.49 dogcow #if !HAVE_DECL_HTOBE64
619 1.9 bjh21 #define htobe64(x) bswap64((u_int64_t)(x))
620 1.39 jmc #endif
621 1.49 dogcow #if !HAVE_DECL_HTOLE16
622 1.9 bjh21 #define htole16(x) (x)
623 1.39 jmc #endif
624 1.49 dogcow #if !HAVE_DECL_HTOLE32
625 1.9 bjh21 #define htole32(x) (x)
626 1.39 jmc #endif
627 1.49 dogcow #if !HAVE_DECL_HTOLE64
628 1.9 bjh21 #define htole64(x) (x)
629 1.9 bjh21 #endif
630 1.39 jmc #endif
631 1.49 dogcow #if !HAVE_DECL_BE16TOH
632 1.9 bjh21 #define be16toh(x) htobe16(x)
633 1.39 jmc #endif
634 1.49 dogcow #if !HAVE_DECL_BE32TOH
635 1.9 bjh21 #define be32toh(x) htobe32(x)
636 1.39 jmc #endif
637 1.49 dogcow #if !HAVE_DECL_BE64TOH
638 1.9 bjh21 #define be64toh(x) htobe64(x)
639 1.39 jmc #endif
640 1.49 dogcow #if !HAVE_DECL_LE16TOH
641 1.9 bjh21 #define le16toh(x) htole16(x)
642 1.39 jmc #endif
643 1.49 dogcow #if !HAVE_DECL_LE32TOH
644 1.9 bjh21 #define le32toh(x) htole32(x)
645 1.39 jmc #endif
646 1.49 dogcow #if !HAVE_DECL_LE64TOH
647 1.9 bjh21 #define le64toh(x) htole64(x)
648 1.1 thorpej #endif
649 1.1 thorpej
650 1.60 apb #define __GEN_ENDIAN_ENC(bits, endian) \
651 1.60 apb static void \
652 1.60 apb endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
653 1.60 apb { \
654 1.60 apb u = hto ## endian ## bits (u); \
655 1.60 apb memcpy(dst, &u, sizeof(u)); \
656 1.60 apb }
657 1.60 apb #if !HAVE_DECL_BE16ENC
658 1.60 apb __GEN_ENDIAN_ENC(16, be)
659 1.60 apb #endif
660 1.60 apb #if !HAVE_DECL_BE32ENC
661 1.60 apb __GEN_ENDIAN_ENC(32, be)
662 1.60 apb #endif
663 1.60 apb #if !HAVE_DECL_BE64ENC
664 1.60 apb __GEN_ENDIAN_ENC(64, be)
665 1.60 apb #endif
666 1.60 apb #if !HAVE_DECL_LE16ENC
667 1.60 apb __GEN_ENDIAN_ENC(16, le)
668 1.60 apb #endif
669 1.60 apb #if !HAVE_DECL_LE32ENC
670 1.60 apb __GEN_ENDIAN_ENC(32, le)
671 1.60 apb #endif
672 1.60 apb #if !HAVE_DECL_LE64ENC
673 1.60 apb __GEN_ENDIAN_ENC(64, le)
674 1.60 apb #endif
675 1.60 apb #undef __GEN_ENDIAN_ENC
676 1.60 apb
677 1.60 apb #define __GEN_ENDIAN_DEC(bits, endian) \
678 1.60 apb static uint ## bits ## _t \
679 1.60 apb endian ## bits ## dec(const void *buf) \
680 1.60 apb { \
681 1.60 apb uint ## bits ## _t u; \
682 1.60 apb memcpy(&u, buf, sizeof(u)); \
683 1.60 apb return endian ## bits ## toh (u); \
684 1.60 apb }
685 1.60 apb #if !HAVE_DECL_BE16DEC
686 1.60 apb __GEN_ENDIAN_DEC(16, be)
687 1.60 apb #endif
688 1.60 apb #if !HAVE_DECL_BE32DEC
689 1.60 apb __GEN_ENDIAN_DEC(32, be)
690 1.60 apb #endif
691 1.60 apb #if !HAVE_DECL_BE64DEC
692 1.60 apb __GEN_ENDIAN_DEC(64, be)
693 1.60 apb #endif
694 1.60 apb #if !HAVE_DECL_LE16DEC
695 1.60 apb __GEN_ENDIAN_DEC(16, le)
696 1.60 apb #endif
697 1.60 apb #if !HAVE_DECL_LE32DEC
698 1.60 apb __GEN_ENDIAN_DEC(32, le)
699 1.60 apb #endif
700 1.60 apb #if !HAVE_DECL_LE64DEC
701 1.60 apb __GEN_ENDIAN_DEC(64, le)
702 1.60 apb #endif
703 1.60 apb #undef __GEN_ENDIAN_DEC
704 1.60 apb
705 1.4 tv /* <sys/mman.h> */
706 1.3 tv
707 1.3 tv #ifndef MAP_FILE
708 1.3 tv #define MAP_FILE 0
709 1.19 lukem #endif
710 1.19 lukem
711 1.19 lukem /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
712 1.19 lukem #ifndef MAP_ANON
713 1.19 lukem #ifdef MAP_ANONYMOUS
714 1.19 lukem #define MAP_ANON MAP_ANONYMOUS
715 1.19 lukem #endif
716 1.3 tv #endif
717 1.3 tv
718 1.4 tv /* <sys/param.h> */
719 1.4 tv
720 1.4 tv #undef BIG_ENDIAN
721 1.4 tv #undef LITTLE_ENDIAN
722 1.4 tv #define BIG_ENDIAN 4321
723 1.4 tv #define LITTLE_ENDIAN 1234
724 1.4 tv
725 1.4 tv #undef BYTE_ORDER
726 1.4 tv #if WORDS_BIGENDIAN
727 1.4 tv #define BYTE_ORDER BIG_ENDIAN
728 1.4 tv #else
729 1.4 tv #define BYTE_ORDER LITTLE_ENDIAN
730 1.4 tv #endif
731 1.4 tv
732 1.7 tv #ifndef DEV_BSIZE
733 1.7 tv #define DEV_BSIZE (1 << 9)
734 1.7 tv #endif
735 1.7 tv
736 1.4 tv #undef MIN
737 1.4 tv #undef MAX
738 1.4 tv #define MIN(a,b) ((a) < (b) ? (a) : (b))
739 1.4 tv #define MAX(a,b) ((a) > (b) ? (a) : (b))
740 1.4 tv
741 1.1 thorpej #ifndef MAXBSIZE
742 1.1 thorpej #define MAXBSIZE (64 * 1024)
743 1.1 thorpej #endif
744 1.4 tv #ifndef MAXFRAG
745 1.4 tv #define MAXFRAG 8
746 1.1 thorpej #endif
747 1.4 tv #ifndef MAXPHYS
748 1.4 tv #define MAXPHYS (64 * 1024)
749 1.3 tv #endif
750 1.4 tv
751 1.6 tv /* XXX needed by makefs; this should be done in a better way */
752 1.6 tv #undef btodb
753 1.6 tv #define btodb(x) ((x) << 9)
754 1.6 tv
755 1.6 tv #undef setbit
756 1.6 tv #undef clrbit
757 1.6 tv #undef isset
758 1.6 tv #undef isclr
759 1.6 tv #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
760 1.6 tv #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
761 1.6 tv #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
762 1.6 tv #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
763 1.6 tv
764 1.4 tv #ifndef powerof2
765 1.4 tv #define powerof2(x) ((((x)-1)&(x))==0)
766 1.3 tv #endif
767 1.7 tv
768 1.7 tv #undef roundup
769 1.7 tv #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
770 1.3 tv
771 1.4 tv /* <sys/stat.h> */
772 1.4 tv
773 1.4 tv #ifndef ALLPERMS
774 1.4 tv #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
775 1.4 tv #endif
776 1.4 tv #ifndef DEFFILEMODE
777 1.4 tv #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
778 1.4 tv #endif
779 1.3 tv #ifndef S_ISTXT
780 1.3 tv #ifdef S_ISVTX
781 1.3 tv #define S_ISTXT S_ISVTX
782 1.3 tv #else
783 1.3 tv #define S_ISTXT 0
784 1.3 tv #endif
785 1.6 tv #endif
786 1.6 tv
787 1.39 jmc /* Protected by _NETBSD_SOURCE otherwise. */
788 1.39 jmc #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
789 1.39 jmc #define UF_SETTABLE 0x0000ffff
790 1.39 jmc #define UF_NODUMP 0x00000001
791 1.39 jmc #define UF_IMMUTABLE 0x00000002
792 1.39 jmc #define UF_APPEND 0x00000004
793 1.39 jmc #define UF_OPAQUE 0x00000008
794 1.39 jmc #define SF_SETTABLE 0xffff0000
795 1.39 jmc #define SF_ARCHIVED 0x00010000
796 1.39 jmc #define SF_IMMUTABLE 0x00020000
797 1.39 jmc #define SF_APPEND 0x00040000
798 1.39 jmc #endif
799 1.39 jmc
800 1.6 tv /* <sys/syslimits.h> */
801 1.6 tv
802 1.6 tv #ifndef LINE_MAX
803 1.6 tv #define LINE_MAX 2048
804 1.4 tv #endif
805 1.4 tv
806 1.4 tv /* <sys/time.h> */
807 1.4 tv
808 1.4 tv #ifndef timercmp
809 1.4 tv #define timercmp(tvp, uvp, cmp) \
810 1.4 tv (((tvp)->tv_sec == (uvp)->tv_sec) ? \
811 1.4 tv ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
812 1.4 tv ((tvp)->tv_sec cmp (uvp)->tv_sec))
813 1.4 tv #endif
814 1.4 tv #ifndef timeradd
815 1.4 tv #define timeradd(tvp, uvp, vvp) \
816 1.4 tv do { \
817 1.4 tv (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
818 1.4 tv (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
819 1.4 tv if ((vvp)->tv_usec >= 1000000) { \
820 1.4 tv (vvp)->tv_sec++; \
821 1.4 tv (vvp)->tv_usec -= 1000000; \
822 1.4 tv } \
823 1.4 tv } while (/* CONSTCOND */ 0)
824 1.4 tv #endif
825 1.4 tv #ifndef timersub
826 1.4 tv #define timersub(tvp, uvp, vvp) \
827 1.4 tv do { \
828 1.4 tv (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
829 1.4 tv (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
830 1.4 tv if ((vvp)->tv_usec < 0) { \
831 1.4 tv (vvp)->tv_sec--; \
832 1.4 tv (vvp)->tv_usec += 1000000; \
833 1.4 tv } \
834 1.4 tv } while (/* CONSTCOND */ 0)
835 1.4 tv #endif
836 1.4 tv
837 1.4 tv /* <sys/types.h> */
838 1.4 tv
839 1.39 jmc #ifdef major
840 1.39 jmc #undef major
841 1.39 jmc #endif
842 1.39 jmc #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
843 1.39 jmc
844 1.39 jmc #ifdef minor
845 1.39 jmc #undef minor
846 1.39 jmc #endif
847 1.39 jmc #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
848 1.39 jmc (((x) & 0x000000ff) >> 0)))
849 1.39 jmc #ifdef makedev
850 1.39 jmc #undef makedev
851 1.39 jmc #endif
852 1.39 jmc #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
853 1.39 jmc (((y) << 12) & 0xfff00000) | \
854 1.39 jmc (((y) << 0) & 0x000000ff)))
855 1.39 jmc #ifndef NBBY
856 1.39 jmc #define NBBY 8
857 1.39 jmc #endif
858 1.39 jmc
859 1.4 tv #if !HAVE_U_QUAD_T
860 1.4 tv /* #define, not typedef, as quad_t exists as a struct on some systems */
861 1.4 tv #define quad_t long long
862 1.4 tv #define u_quad_t unsigned long long
863 1.20 lukem #define strtoq strtoll
864 1.4 tv #define strtouq strtoull
865 1.1 thorpej #endif
866 1.1 thorpej
867 1.40 jmc /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
868 1.40 jmc #ifdef __NetBSD__
869 1.40 jmc quad_t strtoq __P((const char *, char **, int));
870 1.40 jmc u_quad_t strtouq __P((const char *, char **, int));
871 1.40 jmc #endif
872 1.40 jmc
873 1.1 thorpej #endif /* !__NETBSD_COMPAT_DEFS_H__ */
874