arm: protect state after signal handler
[minix.git] / tools / compat / compat_defs.h
blob4d4843ab305873072262e00994d4f031216e1028
1 /* $NetBSD: compat_defs.h,v 1.86 2012/06/04 10:18:01 joerg Exp $ */
3 #ifndef __NETBSD_COMPAT_DEFS_H__
4 #define __NETBSD_COMPAT_DEFS_H__
7 /* Work around some complete brain damage. */
8 /*
9 * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the
10 * program (not the OS) should do that. Preload <features.h> to keep any
11 * of this crap from being pulled in, and undefine _POSIX_SOURCE.
14 #if defined(__linux__) && HAVE_FEATURES_H
15 #include <features.h>
16 #define __USE_ISOC99 1
17 #endif
19 /* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard
20 defs. Other platforms may need similiar defines. */
21 #if defined(__NetBSD__) || defined(__minix)
22 #define _ISOC99_SOURCE
23 #define _POSIX_SOURCE 1
24 #define _POSIX_C_SOURCE 200112L
25 #define _XOPEN_SOURCE 600
26 #else
27 #undef _POSIX_SOURCE
28 #undef _POSIX_C_SOURCE
29 #endif
31 /* System headers needed for (re)definitions below. */
33 #include <sys/types.h>
34 #include <sys/mman.h>
35 #include <sys/param.h>
36 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
37 #include <sys/time.h>
38 #include <sys/stat.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <limits.h>
42 #include <paths.h>
43 #include <stdarg.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
48 #if HAVE_SYS_CDEFS_H
49 #include <sys/cdefs.h>
50 #endif
51 #if HAVE_SYS_SYSLIMITS_H
52 #include <sys/syslimits.h>
53 #endif
54 #if HAVE_SYS_SYSMACROS_H
55 /* major(), minor() on SVR4 */
56 #include <sys/sysmacros.h>
57 #endif
58 #if HAVE_INTTYPES_H
59 #include <inttypes.h>
60 #endif
61 #if HAVE_STDDEF_H
62 #include <stddef.h>
63 #endif
65 #ifdef _NETBSD_SOURCE
66 #error _NETBSD_SOURCE is *not* to be defined.
67 #endif
69 /* Need this since we can't depend on NetBSD's version to be around */
70 #ifdef __UNCONST
71 #undef __UNCONST
72 #endif
73 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
75 #undef __predict_false
76 #define __predict_false(x) (x)
77 #undef __predict_true
78 #define __predict_true(x) (x)
80 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
81 struct passwd;
83 /* We don't include <grp.h> either */
84 struct group;
86 /* Assume an ANSI compiler for the host. */
88 #undef __P
89 #define __P(x) x
91 #ifndef __BEGIN_DECLS
92 #define __BEGIN_DECLS
93 #endif
94 #ifndef __END_DECLS
95 #define __END_DECLS
96 #endif
98 /* Some things usually in BSD <sys/cdefs.h>. */
100 #ifndef __CONCAT
101 #define __CONCAT(x,y) x ## y
102 #endif
103 #if !defined(__attribute__) && !defined(__GNUC__)
104 #define __attribute__(x)
105 #endif
106 #if !defined(__packed)
107 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
108 #define __packed __attribute__((__packed__))
109 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
110 #define __packed __attribute__((__packed__))
111 #else
112 #define __packed error: no __packed for this compiler
113 #endif
114 #endif /* !__packed */
115 #ifndef __RENAME
116 #define __RENAME(x)
117 #endif
118 #undef __aconst
119 #define __aconst
120 #undef __dead
121 #define __dead
122 #undef __printflike
123 #define __printflike(x,y)
124 #undef __restrict
125 #define __restrict
126 #undef __unused
127 #define __unused
128 #undef __arraycount
129 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
131 /* Dirent support. */
133 #if HAVE_DIRENT_H
134 # if defined(__linux__) && defined(__USE_BSD)
135 # undef __USE_BSD
136 # include <dirent.h>
137 # define __USE_BSD 1
138 # undef d_fileno
139 # else
140 # include <dirent.h>
141 # if defined(__DARWIN_UNIX03)
142 # undef d_fileno
143 # endif
144 # endif
145 # define NAMLEN(dirent) (strlen((dirent)->d_name))
146 #else
147 # define dirent direct
148 # define NAMLEN(dirent) ((dirent)->d_namlen)
149 # if HAVE_SYS_NDIR_H
150 # include <sys/ndir.h>
151 # endif
152 # if HAVE_SYS_DIR_H
153 # include <sys/dir.h>
154 # endif
155 # if HAVE_NDIR_H
156 # include <ndir.h>
157 # endif
158 #endif
160 /* Type substitutes. */
162 #if !HAVE_ID_T
163 typedef unsigned int id_t;
164 #endif
166 #if !HAVE_SOCKLEN_T
167 typedef int socklen_t;
168 #endif
170 #if !HAVE_U_LONG
171 typedef unsigned long u_long;
172 #endif
174 #if !HAVE_U_CHAR
175 typedef unsigned char u_char;
176 #endif
178 #if !HAVE_U_INT
179 typedef unsigned int u_int;
180 #endif
182 #if !HAVE_U_SHORT
183 typedef unsigned short u_short;
184 #endif
186 /* Prototypes for replacement functions. */
188 #if !HAVE_ATOLL
189 long long int atoll(const char *);
190 #endif
192 #if !HAVE_ASPRINTF
193 int asprintf(char **, const char *, ...);
194 #endif
196 #if !HAVE_ASNPRINTF
197 int asnprintf(char **, size_t, const char *, ...);
198 #endif
200 #if !HAVE_BASENAME
201 char *basename(char *);
202 #endif
204 #if !HAVE_DECL_OPTIND
205 int getopt(int, char *const *, const char *);
206 extern char *optarg;
207 extern int optind, opterr, optopt;
208 #endif
210 #if !HAVE_DIRNAME
211 char *dirname(char *);
212 #endif
214 #if !HAVE_DIRFD
215 #if HAVE_DIR_DD_FD
216 #define dirfd(dirp) ((dirp)->dd_fd)
217 #elif HAVE_DIR___DD_FD
218 #define dirfd(dirp) ((dirp)->__dd_fd)
219 #else
220 /*XXX: Very hacky but no other way to bring this into scope w/o defining
221 _NETBSD_SOURCE which we're avoiding. */
222 #if defined(__NetBSD__) || defined(__minix)
223 struct _dirdesc {
224 int dd_fd; /* file descriptor associated with directory */
225 long dd_loc; /* offset in current buffer */
226 long dd_size; /* amount of data returned by getdents */
227 char *dd_buf; /* data buffer */
228 int dd_len; /* size of data buffer */
229 off_t dd_seek; /* magic cookie returned by getdents */
230 long dd_rewind; /* magic cookie for rewinding */
231 int dd_flags; /* flags for readdir */
232 void *dd_lock; /* lock for concurrent access */
234 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
235 #else
236 #error cannot figure out how to turn a DIR * into a fd
237 #endif
238 #endif
239 #endif
241 #if !HAVE_ERR_H
242 void err(int, const char *, ...);
243 void errx(int, const char *, ...);
244 void warn(const char *, ...);
245 void warnx(const char *, ...);
246 void vwarnx(const char *, va_list);
247 #endif
249 #if !HAVE_ESETFUNC
250 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
251 size_t estrlcpy(char *, const char *, size_t);
252 size_t estrlcat(char *, const char *, size_t);
253 char *estrdup(const char *);
254 char *estrndup(const char *, size_t);
255 void *ecalloc(size_t, size_t);
256 void *emalloc(size_t);
257 void *erealloc(void *, size_t);
258 FILE *efopen(const char *, const char *);
259 int easprintf(char **, const char *, ...);
260 int evasprintf(char **, const char *, va_list);
261 #endif
263 #if !HAVE_FGETLN || defined(__NetBSD__) || defined(__minix)
264 char *fgetln(FILE *, size_t *);
265 #endif
267 #if !HAVE_FLOCK
268 # define LOCK_SH 0x01
269 # define LOCK_EX 0x02
270 # define LOCK_NB 0x04
271 # define LOCK_UN 0x08
272 int flock(int, int);
273 #endif
275 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) || defined(__minix)
276 # define FPARSELN_UNESCESC 0x01
277 # define FPARSELN_UNESCCONT 0x02
278 # define FPARSELN_UNESCCOMM 0x04
279 # define FPARSELN_UNESCREST 0x08
280 # define FPARSELN_UNESCALL 0x0f
281 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
282 #endif
284 #if !HAVE_GETLINE
285 ssize_t getdelim(char **, size_t *, int, FILE *);
286 ssize_t getline(char **, size_t *, FILE *);
287 #endif
289 #if !HAVE_ISSETUGID
290 int issetugid(void);
291 #endif
293 #if !HAVE_ISBLANK && !defined(isblank)
294 #define isblank(x) ((x) == ' ' || (x) == '\t')
295 #endif
297 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
299 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
300 (((x) << 8) & 0x00ff0000) | \
301 (((x) >> 8) & 0x0000ff00) | \
302 (((x) >> 24) & 0x000000ff))
304 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
305 ((u_int64_t)bswap32((x) >> 32)))
307 #if ! HAVE_DECL_BSWAP16
308 #ifdef bswap16
309 #undef bswap16
310 #endif
311 #define bswap16(x) __nbcompat_bswap16(x)
312 #endif
313 #if ! HAVE_DECL_BSWAP32
314 #ifdef bswap32
315 #undef bswap32
316 #endif
317 #define bswap32(x) __nbcompat_bswap32(x)
318 #endif
319 #if ! HAVE_DECL_BSWAP64
320 #ifdef bswap64
321 #undef bswap64
322 #endif
323 #define bswap64(x) __nbcompat_bswap64(x)
324 #endif
326 #if !HAVE_MKSTEMP
327 int mkstemp(char *);
328 #endif
330 #if !HAVE_MKDTEMP
331 char *mkdtemp(char *);
332 #endif
334 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
335 /* This is a prototype for the internal function defined in
336 * src/lib/lib/stdio/gettemp.c */
337 int __nbcompat_gettemp(char *, int *, int);
338 #endif
340 #if !HAVE_PREAD
341 ssize_t pread(int, void *, size_t, off_t);
342 #endif
344 #if !HAVE_HEAPSORT
345 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
346 #endif
347 /* Make them use our version */
348 # define heapsort __nbcompat_heapsort
350 char *flags_to_string(unsigned long, const char *);
351 int string_to_flags(char **, unsigned long *, unsigned long *);
354 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
355 * supply an implementation of one without the others -- some parts are
356 * libc internal and this varies from system to system.
358 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
359 * XXX host system has all of these functions, all of their interfaces
360 * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
362 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
363 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
364 /* Make them use our version */
365 # define user_from_uid __nbcompat_user_from_uid
366 # define uid_from_user __nbcompat_uid_from_user
367 # define pwcache_userdb __nbcompat_pwcache_userdb
368 # define group_from_gid __nbcompat_group_from_gid
369 # define gid_from_group __nbcompat_gid_from_group
370 # define pwcache_groupdb __nbcompat_pwcache_groupdb
371 #endif
373 #if !HAVE_DECL_UID_FROM_USER
374 int uid_from_user(const char *, uid_t *);
375 #endif
377 #if !HAVE_DECL_USER_FROM_UID
378 const char *user_from_uid(uid_t, int);
379 #endif
381 #if !HAVE_DECL_PWCACHE_USERDB
382 int pwcache_userdb(int (*)(int), void (*)(void),
383 struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
384 #endif
386 #if !HAVE_DECL_GID_FROM_GROUP
387 int gid_from_group(const char *, gid_t *);
388 #endif
390 #if !HAVE_DECL_GROUP_FROM_GID
391 const char *group_from_gid(gid_t, int);
392 #endif
394 #if !HAVE_DECL_PWCACHE_GROUPDB
395 int pwcache_groupdb(int (*)(int), void (*)(void),
396 struct group * (*)(const char *), struct group * (*)(gid_t));
397 #endif
399 #if !HAVE_DECL_STRNDUP
400 char *strndup(const char *, size_t);
401 #endif
402 #if !HAVE_DECL_LCHFLAGS
403 int lchflags(const char *, unsigned long);
404 #endif
405 #if !HAVE_DECL_LCHMOD
406 int lchmod(const char *, mode_t);
407 #endif
408 #if !HAVE_DECL_LCHOWN
409 int lchown(const char *, uid_t, gid_t);
410 #endif
412 #if !HAVE_PWRITE
413 ssize_t pwrite(int, const void *, size_t, off_t);
414 #endif
416 #if !HAVE_RAISE_DEFAULT_SIGNAL
417 int raise_default_signal(int);
418 #endif
420 #if !HAVE_SETENV
421 int setenv(const char *, const char *, int);
422 #endif
424 #if !HAVE_DECL_SETGROUPENT
425 int setgroupent(int);
426 #endif
428 #if !HAVE_DECL_SETPASSENT
429 int setpassent(int);
430 #endif
432 #if !HAVE_SETPROGNAME || defined(__NetBSD__) || defined(__minix)
433 const char *getprogname(void);
434 void setprogname(const char *);
435 #endif
437 #if !HAVE_SNPRINTF
438 int snprintf(char *, size_t, const char *, ...);
439 #endif
441 #if !HAVE_STRLCAT
442 size_t strlcat(char *, const char *, size_t);
443 #endif
445 #if !HAVE_STRLCPY
446 size_t strlcpy(char *, const char *, size_t);
447 #endif
449 #if !HAVE_STRMODE
450 void strmode(mode_t, char *);
451 #endif
453 #if !HAVE_STRNDUP
454 char *strndup(const char *, size_t);
455 #endif
457 #if !HAVE_STRSEP || defined(__NetBSD__) || defined(__minix)
458 char *strsep(char **, const char *);
459 #endif
461 #if !HAVE_DECL_STRSUFTOLL
462 long long strsuftoll(const char *, const char *, long long, long long);
463 long long strsuftollx(const char *, const char *,
464 long long, long long, char *, size_t);
465 #endif
467 #if !HAVE_STRTOLL
468 long long strtoll(const char *, char **, int);
469 #endif
471 #if !HAVE_USER_FROM_UID
472 const char *user_from_uid(uid_t, int);
473 #endif
475 #if !HAVE_GROUP_FROM_GID
476 const char *group_from_gid(gid_t, int);
477 #endif
479 #if !HAVE_VASPRINTF
480 int vasprintf(char **, const char *, va_list);
481 #endif
483 #if !HAVE_VASNPRINTF
484 int vasnprintf(char **, size_t, const char *, va_list);
485 #endif
487 #if !HAVE_VSNPRINTF
488 int vsnprintf(char *, size_t, const char *, va_list);
489 #endif
492 * getmode() and setmode() are always defined, as these function names
493 * exist but with very different meanings on other OS's. The compat
494 * versions here simply accept an octal mode number; the "u+x,g-w" type
495 * of syntax is not accepted.
498 #define getmode __nbcompat_getmode
499 #define setmode __nbcompat_setmode
501 mode_t getmode(const void *, mode_t);
502 void *setmode(const char *);
504 /* Eliminate assertions embedded in binaries. */
506 #undef _DIAGASSERT
507 #define _DIAGASSERT(x)
509 /* Various sources use this */
510 #undef __RCSID
511 #define __RCSID(x) struct XXXNETBSD_RCSID
512 #undef __SCCSID
513 #define __SCCSID(x)
514 #undef __COPYRIGHT
515 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
516 #undef __KERNEL_RCSID
517 #define __KERNEL_RCSID(x,y)
519 /* Heimdal expects this one. */
521 #undef RCSID
522 #define RCSID(x)
524 /* Some definitions not available on all systems. */
526 #ifndef __inline
527 #define __inline inline
528 #endif
530 /* <errno.h> */
532 #ifndef EFTYPE
533 #define EFTYPE EIO
534 #endif
536 /* <fcntl.h> */
538 #ifndef O_EXLOCK
539 #define O_EXLOCK 0
540 #endif
541 #ifndef O_SHLOCK
542 #define O_SHLOCK 0
543 #endif
545 /* <inttypes.h> */
547 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */
548 #ifndef PRId8
549 #define PRId8 "hhd"
550 #endif
551 #ifndef PRIi8
552 #define PRIi8 "hhi"
553 #endif
554 #ifndef PRIo8
555 #define PRIo8 "hho"
556 #endif
557 #ifndef PRIu8
558 #define PRIu8 "hhu"
559 #endif
560 #ifndef PRIx8
561 #define PRIx8 "hhx"
562 #endif
563 #ifndef PRIX8
564 #define PRIX8 "hhX"
565 #endif
566 #ifndef SCNd8
567 #define SCNd8 "hhd"
568 #endif
569 #ifndef SCNi8
570 #define SCNi8 "hhi"
571 #endif
572 #ifndef SCNo8
573 #define SCNo8 "hho"
574 #endif
575 #ifndef SCNu8
576 #define SCNu8 "hhu"
577 #endif
578 #ifndef SCNx8
579 #define SCNx8 "hhx"
580 #endif
581 #ifndef SCNX8
582 #define SCNX8 "hhX"
583 #endif
584 #endif /* char is an 8-bit type */
585 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
586 defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
587 #error "Don't know how to define PRI[diouxX]8"
588 #endif
589 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
590 defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
591 #error "Don't know how to define SCN[diouxX]8"
592 #endif
594 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */
595 #ifndef PRId16
596 #define PRId16 "hd"
597 #endif
598 #ifndef PRIi16
599 #define PRIi16 "hi"
600 #endif
601 #ifndef PRIo16
602 #define PRIo16 "ho"
603 #endif
604 #ifndef PRIu16
605 #define PRIu16 "hu"
606 #endif
607 #ifndef PRIx16
608 #define PRIx16 "hx"
609 #endif
610 #ifndef PRIX16
611 #define PRIX16 "hX"
612 #endif
613 #ifndef SCNd16
614 #define SCNd16 "hd"
615 #endif
616 #ifndef SCNi16
617 #define SCNi16 "hi"
618 #endif
619 #ifndef SCNo16
620 #define SCNo16 "ho"
621 #endif
622 #ifndef SCNu16
623 #define SCNu16 "hu"
624 #endif
625 #ifndef SCNx16
626 #define SCNx16 "hx"
627 #endif
628 #ifndef SCNX16
629 #define SCNX16 "hX"
630 #endif
631 #endif /* short is a 16-bit type */
632 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
633 defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
634 #error "Don't know how to define PRI[diouxX]16"
635 #endif
636 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
637 defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
638 #error "Don't know how to define SCN[diouxX]16"
639 #endif
641 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
642 #ifndef PRId32
643 #define PRId32 "d"
644 #endif
645 #ifndef PRIi32
646 #define PRIi32 "i"
647 #endif
648 #ifndef PRIo32
649 #define PRIo32 "o"
650 #endif
651 #ifndef PRIu32
652 #define PRIu32 "u"
653 #endif
654 #ifndef PRIx32
655 #define PRIx32 "x"
656 #endif
657 #ifndef PRIX32
658 #define PRIX32 "X"
659 #endif
660 #ifndef SCNd32
661 #define SCNd32 "d"
662 #endif
663 #ifndef SCNi32
664 #define SCNi32 "i"
665 #endif
666 #ifndef SCNo32
667 #define SCNo32 "o"
668 #endif
669 #ifndef SCNu32
670 #define SCNu32 "u"
671 #endif
672 #ifndef SCNx32
673 #define SCNx32 "x"
674 #endif
675 #ifndef SCNX32
676 #define SCNX32 "X"
677 #endif
678 #endif /* int is a 32-bit type */
679 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
680 #ifndef PRId32
681 #define PRId32 "ld"
682 #endif
683 #ifndef PRIi32
684 #define PRIi32 "li"
685 #endif
686 #ifndef PRIo32
687 #define PRIo32 "lo"
688 #endif
689 #ifndef PRIu32
690 #define PRIu32 "lu"
691 #endif
692 #ifndef PRIx32
693 #define PRIx32 "lx"
694 #endif
695 #ifndef PRIX32
696 #define PRIX32 "lX"
697 #endif
698 #ifndef SCNd32
699 #define SCNd32 "ld"
700 #endif
701 #ifndef SCNi32
702 #define SCNi32 "li"
703 #endif
704 #ifndef SCNo32
705 #define SCNo32 "lo"
706 #endif
707 #ifndef SCNu32
708 #define SCNu32 "lu"
709 #endif
710 #ifndef SCNx32
711 #define SCNx32 "lx"
712 #endif
713 #ifndef SCNX32
714 #define SCNX32 "lX"
715 #endif
716 #endif /* long is a 32-bit type */
717 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
718 defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
719 #error "Don't know how to define PRI[diouxX]32"
720 #endif
721 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
722 defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
723 #error "Don't know how to define SCN[diouxX]32"
724 #endif
726 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
727 #ifndef PRId64
728 #define PRId64 "ld"
729 #endif
730 #ifndef PRIi64
731 #define PRIi64 "li"
732 #endif
733 #ifndef PRIo64
734 #define PRIo64 "lo"
735 #endif
736 #ifndef PRIu64
737 #define PRIu64 "lu"
738 #endif
739 #ifndef PRIx64
740 #define PRIx64 "lx"
741 #endif
742 #ifndef PRIX64
743 #define PRIX64 "lX"
744 #endif
745 #ifndef SCNd64
746 #define SCNd64 "ld"
747 #endif
748 #ifndef SCNi64
749 #define SCNi64 "li"
750 #endif
751 #ifndef SCNo64
752 #define SCNo64 "lo"
753 #endif
754 #ifndef SCNu64
755 #define SCNu64 "lu"
756 #endif
757 #ifndef SCNx64
758 #define SCNx64 "lx"
759 #endif
760 #ifndef SCNX64
761 #define SCNX64 "lX"
762 #endif
763 #endif /* long is a 64-bit type */
764 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
765 #ifndef PRId64
766 #define PRId64 "lld"
767 #endif
768 #ifndef PRIi64
769 #define PRIi64 "lli"
770 #endif
771 #ifndef PRIo64
772 #define PRIo64 "llo"
773 #endif
774 #ifndef PRIu64
775 #define PRIu64 "llu"
776 #endif
777 #ifndef PRIx64
778 #define PRIx64 "llx"
779 #endif
780 #ifndef PRIX64
781 #define PRIX64 "llX"
782 #endif
783 #ifndef SCNd64
784 #define SCNd64 "lld"
785 #endif
786 #ifndef SCNi64
787 #define SCNi64 "lli"
788 #endif
789 #ifndef SCNo64
790 #define SCNo64 "llo"
791 #endif
792 #ifndef SCNu64
793 #define SCNu64 "llu"
794 #endif
795 #ifndef SCNx64
796 #define SCNx64 "llx"
797 #endif
798 #ifndef SCNX64
799 #define SCNX64 "llX"
800 #endif
801 #endif /* long long is a 64-bit type */
802 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
803 defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
804 #error "Don't know how to define PRI[diouxX]64"
805 #endif
806 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
807 defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
808 #error "Don't know how to define SCN[diouxX]64"
809 #endif
811 /* <limits.h> */
813 #ifndef UID_MAX
814 #define UID_MAX 32767
815 #endif
816 #ifndef GID_MAX
817 #define GID_MAX UID_MAX
818 #endif
820 #ifndef UQUAD_MAX
821 #define UQUAD_MAX ((u_quad_t)-1)
822 #endif
823 #ifndef QUAD_MAX
824 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
825 #endif
826 #ifndef QUAD_MIN
827 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
828 #endif
829 #ifndef ULLONG_MAX
830 #define ULLONG_MAX ((unsigned long long)-1)
831 #endif
832 #ifndef LLONG_MAX
833 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
834 #endif
835 #ifndef LLONG_MIN
836 #define LLONG_MIN ((long long)(~LLONG_MAX))
837 #endif
839 /* <paths.h> */
841 /* The host's _PATH_BSHELL might be broken, so override it. */
842 #undef _PATH_BSHELL
843 #define _PATH_BSHELL PATH_BSHELL
844 #ifndef _PATH_DEFPATH
845 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
846 #endif
847 #ifndef _PATH_DEV
848 #define _PATH_DEV "/dev/"
849 #endif
850 #ifndef _PATH_DEVNULL
851 #define _PATH_DEVNULL _PATH_DEV "null"
852 #endif
853 #ifndef _PATH_TMP
854 #define _PATH_TMP "/tmp/"
855 #endif
856 #ifndef _PATH_DEFTAPE
857 #define _PATH_DEFTAPE "/dev/nrst0"
858 #endif
859 #ifndef _PATH_VI
860 #define _PATH_VI "/usr/bin/vi"
861 #endif
863 /* <stdint.h> */
865 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
866 #define SIZE_MAX SIZE_T_MAX
867 #endif
869 #ifndef UINT8_MAX
870 #define UINT8_MAX 0xffU
871 #endif
873 #ifndef UINT16_MAX
874 #define UINT16_MAX 0xffffU
875 #endif
877 #ifndef UINT32_MAX
878 #define UINT32_MAX 0xffffffffU
879 #endif
881 /* <stdlib.h> */
883 #ifndef __GNUC__
884 # if HAVE_ALLOCA_H
885 # include <alloca.h>
886 # else
887 # ifndef alloca /* predefined by HP cc +Olibcalls */
888 char *alloca ();
889 # endif
890 # endif
891 #endif
893 /* avoid prototype conflicts with host */
894 #define cgetcap __nbcompat_cgetcap
895 #define cgetclose __nbcompat_cgetclose
896 #define cgetent __nbcompat_cgetent
897 #define cgetfirst __nbcompat_cgetfirst
898 #define cgetmatch __nbcompat_cgetmatch
899 #define cgetnext __nbcompat_cgetnext
900 #define cgetnum __nbcompat_cgetnum
901 #define cgetset __nbcompat_cgetset
902 #define cgetstr __nbcompat_cgetstr
903 #define cgetustr __nbcompat_cgetustr
905 char *cgetcap(char *, const char *, int);
906 int cgetclose(void);
907 int cgetent(char **, const char * const *, const char *);
908 int cgetfirst(char **, const char * const *);
909 int cgetmatch(const char *, const char *);
910 int cgetnext(char **, const char * const *);
911 int cgetnum(char *, const char *, long *);
912 int cgetset(const char *);
913 int cgetstr(char *, const char *, char **);
914 int cgetustr(char *, const char *, char **);
916 /* <sys/endian.h> */
918 #if WORDS_BIGENDIAN
919 #if !HAVE_DECL_HTOBE16
920 #define htobe16(x) (x)
921 #endif
922 #if !HAVE_DECL_HTOBE32
923 #define htobe32(x) (x)
924 #endif
925 #if !HAVE_DECL_HTOBE64
926 #define htobe64(x) (x)
927 #endif
928 #if !HAVE_DECL_HTOLE16
929 #define htole16(x) bswap16((u_int16_t)(x))
930 #endif
931 #if !HAVE_DECL_HTOLE32
932 #define htole32(x) bswap32((u_int32_t)(x))
933 #endif
934 #if !HAVE_DECL_HTOLE64
935 #define htole64(x) bswap64((u_int64_t)(x))
936 #endif
937 #else
938 #if !HAVE_DECL_HTOBE16
939 #define htobe16(x) bswap16((u_int16_t)(x))
940 #endif
941 #if !HAVE_DECL_HTOBE32
942 #define htobe32(x) bswap32((u_int32_t)(x))
943 #endif
944 #if !HAVE_DECL_HTOBE64
945 #define htobe64(x) bswap64((u_int64_t)(x))
946 #endif
947 #if !HAVE_DECL_HTOLE16
948 #define htole16(x) (x)
949 #endif
950 #if !HAVE_DECL_HTOLE32
951 #define htole32(x) (x)
952 #endif
953 #if !HAVE_DECL_HTOLE64
954 #define htole64(x) (x)
955 #endif
956 #endif
957 #if !HAVE_DECL_BE16TOH
958 #define be16toh(x) htobe16(x)
959 #endif
960 #if !HAVE_DECL_BE32TOH
961 #define be32toh(x) htobe32(x)
962 #endif
963 #if !HAVE_DECL_BE64TOH
964 #define be64toh(x) htobe64(x)
965 #endif
966 #if !HAVE_DECL_LE16TOH
967 #define le16toh(x) htole16(x)
968 #endif
969 #if !HAVE_DECL_LE32TOH
970 #define le32toh(x) htole32(x)
971 #endif
972 #if !HAVE_DECL_LE64TOH
973 #define le64toh(x) htole64(x)
974 #endif
976 #define __GEN_ENDIAN_ENC(bits, endian) \
977 static void \
978 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
980 u = hto ## endian ## bits (u); \
981 memcpy(dst, &u, sizeof(u)); \
983 #if !HAVE_DECL_BE16ENC
984 __GEN_ENDIAN_ENC(16, be)
985 #endif
986 #if !HAVE_DECL_BE32ENC
987 __GEN_ENDIAN_ENC(32, be)
988 #endif
989 #if !HAVE_DECL_BE64ENC
990 __GEN_ENDIAN_ENC(64, be)
991 #endif
992 #if !HAVE_DECL_LE16ENC
993 __GEN_ENDIAN_ENC(16, le)
994 #endif
995 #if !HAVE_DECL_LE32ENC
996 __GEN_ENDIAN_ENC(32, le)
997 #endif
998 #if !HAVE_DECL_LE64ENC
999 __GEN_ENDIAN_ENC(64, le)
1000 #endif
1001 #undef __GEN_ENDIAN_ENC
1003 #define __GEN_ENDIAN_DEC(bits, endian) \
1004 static uint ## bits ## _t \
1005 endian ## bits ## dec(const void *buf) \
1007 uint ## bits ## _t u; \
1008 memcpy(&u, buf, sizeof(u)); \
1009 return endian ## bits ## toh (u); \
1011 #if !HAVE_DECL_BE16DEC
1012 __GEN_ENDIAN_DEC(16, be)
1013 #endif
1014 #if !HAVE_DECL_BE32DEC
1015 __GEN_ENDIAN_DEC(32, be)
1016 #endif
1017 #if !HAVE_DECL_BE64DEC
1018 __GEN_ENDIAN_DEC(64, be)
1019 #endif
1020 #if !HAVE_DECL_LE16DEC
1021 __GEN_ENDIAN_DEC(16, le)
1022 #endif
1023 #if !HAVE_DECL_LE32DEC
1024 __GEN_ENDIAN_DEC(32, le)
1025 #endif
1026 #if !HAVE_DECL_LE64DEC
1027 __GEN_ENDIAN_DEC(64, le)
1028 #endif
1029 #undef __GEN_ENDIAN_DEC
1031 /* <sys/mman.h> */
1033 #ifndef MAP_FILE
1034 #define MAP_FILE 0
1035 #endif
1037 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
1038 #ifndef MAP_ANON
1039 #ifdef MAP_ANONYMOUS
1040 #define MAP_ANON MAP_ANONYMOUS
1041 #endif
1042 #endif
1044 /* <sys/param.h> */
1046 #undef BIG_ENDIAN
1047 #undef LITTLE_ENDIAN
1048 #undef PDP_ENDIAN
1049 #define BIG_ENDIAN 4321
1050 #define LITTLE_ENDIAN 1234
1051 #define PDP_ENDIAN 3412
1053 #undef BYTE_ORDER
1054 #if WORDS_BIGENDIAN
1055 #define BYTE_ORDER BIG_ENDIAN
1056 #else
1057 #define BYTE_ORDER LITTLE_ENDIAN
1058 #endif
1060 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
1061 #undef DEV_BSIZE
1062 #define DEV_BSIZE (1 << 9)
1064 #undef MIN
1065 #undef MAX
1066 #define MIN(a,b) ((a) < (b) ? (a) : (b))
1067 #define MAX(a,b) ((a) > (b) ? (a) : (b))
1069 #ifndef MAXBSIZE
1070 #define MAXBSIZE (64 * 1024)
1071 #endif
1072 #ifndef MAXFRAG
1073 #define MAXFRAG 8
1074 #endif
1075 #ifndef MAXPHYS
1076 #define MAXPHYS (64 * 1024)
1077 #endif
1079 /* XXX needed by makefs; this should be done in a better way */
1080 #undef btodb
1081 #define btodb(x) ((x) << 9)
1083 #undef setbit
1084 #undef clrbit
1085 #undef isset
1086 #undef isclr
1087 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1088 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1089 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1090 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1092 #ifndef powerof2
1093 #define powerof2(x) ((((x)-1)&(x))==0)
1094 #endif
1096 #undef roundup
1097 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1099 /* <sys/stat.h> */
1101 #ifndef ALLPERMS
1102 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
1103 #endif
1104 #ifndef DEFFILEMODE
1105 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
1106 #endif
1107 #ifndef S_ISTXT
1108 #ifdef S_ISVTX
1109 #define S_ISTXT S_ISVTX
1110 #else
1111 #define S_ISTXT 0
1112 #endif
1113 #endif
1115 /* Protected by _NETBSD_SOURCE otherwise. */
1116 #if HAVE_STRUCT_STAT_ST_FLAGS && (defined(__NetBSD__) || defined(__minix))
1117 #define UF_SETTABLE 0x0000ffff
1118 #define UF_NODUMP 0x00000001
1119 #define UF_IMMUTABLE 0x00000002
1120 #define UF_APPEND 0x00000004
1121 #define UF_OPAQUE 0x00000008
1122 #define SF_SETTABLE 0xffff0000
1123 #define SF_ARCHIVED 0x00010000
1124 #define SF_IMMUTABLE 0x00020000
1125 #define SF_APPEND 0x00040000
1126 #endif
1128 /* <sys/syslimits.h> */
1130 #ifndef LINE_MAX
1131 #define LINE_MAX 2048
1132 #endif
1134 /* <sys/time.h> */
1136 #ifndef timercmp
1137 #define timercmp(tvp, uvp, cmp) \
1138 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
1139 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1140 ((tvp)->tv_sec cmp (uvp)->tv_sec))
1141 #endif
1142 #ifndef timeradd
1143 #define timeradd(tvp, uvp, vvp) \
1144 do { \
1145 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
1146 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
1147 if ((vvp)->tv_usec >= 1000000) { \
1148 (vvp)->tv_sec++; \
1149 (vvp)->tv_usec -= 1000000; \
1151 } while (/* CONSTCOND */ 0)
1152 #endif
1153 #ifndef timersub
1154 #define timersub(tvp, uvp, vvp) \
1155 do { \
1156 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
1157 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
1158 if ((vvp)->tv_usec < 0) { \
1159 (vvp)->tv_sec--; \
1160 (vvp)->tv_usec += 1000000; \
1162 } while (/* CONSTCOND */ 0)
1163 #endif
1165 /* <sys/types.h> */
1167 #ifdef major
1168 #undef major
1169 #endif
1170 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
1172 #ifdef minor
1173 #undef minor
1174 #endif
1175 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
1176 (((x) & 0x000000ff) >> 0)))
1177 #ifdef makedev
1178 #undef makedev
1179 #endif
1180 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
1181 (((y) << 12) & 0xfff00000) | \
1182 (((y) << 0) & 0x000000ff)))
1183 #ifndef NBBY
1184 #define NBBY 8
1185 #endif
1187 #if !HAVE_U_QUAD_T
1188 /* #define, not typedef, as quad_t exists as a struct on some systems */
1189 #define quad_t long long
1190 #define u_quad_t unsigned long long
1191 #define strtoq strtoll
1192 #define strtouq strtoull
1193 #endif
1195 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
1196 #if defined(__NetBSD__) || defined(__minix)
1197 quad_t strtoq(const char *, char **, int);
1198 u_quad_t strtouq(const char *, char **, int);
1199 #endif
1201 #endif /* !__NETBSD_COMPAT_DEFS_H__ */