make vfs & filesystems use failable copying
[minix3.git] / tools / compat / compat_defs.h
blobfd76d0bab058a8afb83f859393b52a091e1e73d5
1 /* $NetBSD: compat_defs.h,v 1.93 2013/10/24 13:59:47 apb 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 #if HAVE_RPC_TYPES_H
66 #include <rpc/types.h>
67 #endif
69 #ifdef _NETBSD_SOURCE
70 #error _NETBSD_SOURCE is *not* to be defined.
71 #endif
73 /* Need this since we can't depend on NetBSD's version to be around */
74 #ifdef __UNCONST
75 #undef __UNCONST
76 #endif
77 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
79 #undef __predict_false
80 #define __predict_false(x) (x)
81 #undef __predict_true
82 #define __predict_true(x) (x)
84 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
85 struct passwd;
87 /* We don't include <grp.h> either */
88 struct group;
90 /* Assume an ANSI compiler for the host. */
92 #undef __P
93 #define __P(x) x
95 #ifndef __BEGIN_DECLS
96 #define __BEGIN_DECLS
97 #endif
98 #ifndef __END_DECLS
99 #define __END_DECLS
100 #endif
102 /* Some things usually in BSD <sys/cdefs.h>. */
104 #ifndef __CONCAT
105 #define __CONCAT(x,y) x ## y
106 #endif
107 #if !defined(__attribute__) && !defined(__GNUC__)
108 #define __attribute__(x)
109 #endif
110 #if !defined(__packed)
111 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
112 #define __packed __attribute__((__packed__))
113 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
114 #define __packed __attribute__((__packed__))
115 #else
116 #define __packed error: no __packed for this compiler
117 #endif
118 #endif /* !__packed */
119 #ifndef __RENAME
120 #define __RENAME(x)
121 #endif
122 #undef __aconst
123 #define __aconst
124 #undef __dead
125 #define __dead
126 #undef __printflike
127 #define __printflike(x,y)
128 #undef __format_arg
129 #define __format_arg(x)
130 #undef __restrict
131 #define __restrict
132 #undef __unused
133 #define __unused
134 #undef __arraycount
135 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
136 #undef __USE
137 #define __USE(a) ((void)(a))
139 /* Dirent support. */
141 #if HAVE_DIRENT_H
142 # if defined(__linux__) && defined(__USE_BSD)
143 # undef __USE_BSD
144 # include <dirent.h>
145 # define __USE_BSD 1
146 # undef d_fileno
147 # else
148 # include <dirent.h>
149 # if defined(__DARWIN_UNIX03)
150 # undef d_fileno
151 # endif
152 # endif
153 # define NAMLEN(dirent) (strlen((dirent)->d_name))
154 #else
155 # define dirent direct
156 # define NAMLEN(dirent) ((dirent)->d_namlen)
157 # if HAVE_SYS_NDIR_H
158 # include <sys/ndir.h>
159 # endif
160 # if HAVE_SYS_DIR_H
161 # include <sys/dir.h>
162 # endif
163 # if HAVE_NDIR_H
164 # include <ndir.h>
165 # endif
166 #endif
168 /* Type substitutes. */
170 #if !HAVE_ID_T
171 typedef unsigned int id_t;
172 #endif
174 #if !HAVE_SOCKLEN_T
176 * This is defined as int for compatibility with legacy systems (and not
177 * unsigned int), since universally it was int in most systems that did not
178 * define it.
180 typedef int socklen_t;
181 #endif
183 #if !HAVE_U_LONG
184 typedef unsigned long u_long;
185 #endif
187 #if !HAVE_U_CHAR
188 typedef unsigned char u_char;
189 #endif
191 #if !HAVE_U_INT
192 typedef unsigned int u_int;
193 #endif
195 #if !HAVE_U_SHORT
196 typedef unsigned short u_short;
197 #endif
199 /* Prototypes for replacement functions. */
201 #if !HAVE_ATOLL
202 long long int atoll(const char *);
203 #endif
205 #if !HAVE_ASPRINTF
206 int asprintf(char **, const char *, ...);
207 #endif
209 #if !HAVE_ASNPRINTF
210 int asnprintf(char **, size_t, const char *, ...);
211 #endif
213 #if !HAVE_BASENAME
214 char *basename(char *);
215 #endif
217 #if !HAVE_DECL_OPTIND
218 int getopt(int, char *const *, const char *);
219 extern char *optarg;
220 extern int optind, opterr, optopt;
221 #endif
223 #if !HAVE_DIRNAME
224 char *dirname(char *);
225 #endif
227 #if !HAVE_DIRFD
228 #if HAVE_DIR_DD_FD
229 #define dirfd(dirp) ((dirp)->dd_fd)
230 #elif HAVE_DIR___DD_FD
231 #define dirfd(dirp) ((dirp)->__dd_fd)
232 #else
233 /*XXX: Very hacky but no other way to bring this into scope w/o defining
234 _NETBSD_SOURCE which we're avoiding. */
235 #if defined(__NetBSD__) || defined(__minix)
236 struct _dirdesc {
237 int dd_fd; /* file descriptor associated with directory */
238 long dd_loc; /* offset in current buffer */
239 long dd_size; /* amount of data returned by getdents */
240 char *dd_buf; /* data buffer */
241 int dd_len; /* size of data buffer */
242 off_t dd_seek; /* magic cookie returned by getdents */
243 long dd_rewind; /* magic cookie for rewinding */
244 int dd_flags; /* flags for readdir */
245 void *dd_lock; /* lock for concurrent access */
247 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
248 #else
249 #error cannot figure out how to turn a DIR * into a fd
250 #endif
251 #endif
252 #endif
254 #if !HAVE_ERR_H
255 void err(int, const char *, ...);
256 void errx(int, const char *, ...);
257 void warn(const char *, ...);
258 void warnx(const char *, ...);
259 void vwarnx(const char *, va_list);
260 #endif
262 #if !HAVE_ESETFUNC
263 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
264 size_t estrlcpy(char *, const char *, size_t);
265 size_t estrlcat(char *, const char *, size_t);
266 char *estrdup(const char *);
267 char *estrndup(const char *, size_t);
268 void *ecalloc(size_t, size_t);
269 void *emalloc(size_t);
270 void *erealloc(void *, size_t);
271 FILE *efopen(const char *, const char *);
272 int easprintf(char **, const char *, ...);
273 int evasprintf(char **, const char *, va_list);
274 #endif
276 #if !HAVE_FGETLN || defined(__NetBSD__) || defined(__minix)
277 char *fgetln(FILE *, size_t *);
278 #endif
279 #if !HAVE_DPRINTF
280 int dprintf(int, const char *, ...);
281 #endif
283 #if !HAVE_FLOCK
284 # define LOCK_SH 0x01
285 # define LOCK_EX 0x02
286 # define LOCK_NB 0x04
287 # define LOCK_UN 0x08
288 int flock(int, int);
289 #endif
291 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) || defined(__minix)
292 # define FPARSELN_UNESCESC 0x01
293 # define FPARSELN_UNESCCONT 0x02
294 # define FPARSELN_UNESCCOMM 0x04
295 # define FPARSELN_UNESCREST 0x08
296 # define FPARSELN_UNESCALL 0x0f
297 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
298 #endif
300 #if !HAVE_GETLINE
301 ssize_t getdelim(char **, size_t *, int, FILE *);
302 ssize_t getline(char **, size_t *, FILE *);
303 #endif
305 #if !HAVE_ISSETUGID
306 int issetugid(void);
307 #endif
309 #if !HAVE_ISBLANK && !defined(isblank)
310 #define isblank(x) ((x) == ' ' || (x) == '\t')
311 #endif
313 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
315 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
316 (((x) << 8) & 0x00ff0000) | \
317 (((x) >> 8) & 0x0000ff00) | \
318 (((x) >> 24) & 0x000000ff))
320 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
321 ((u_int64_t)bswap32((x) >> 32)))
323 #if ! HAVE_DECL_BSWAP16
324 #ifdef bswap16
325 #undef bswap16
326 #endif
327 #define bswap16(x) __nbcompat_bswap16(x)
328 #endif
329 #if ! HAVE_DECL_BSWAP32
330 #ifdef bswap32
331 #undef bswap32
332 #endif
333 #define bswap32(x) __nbcompat_bswap32(x)
334 #endif
335 #if ! HAVE_DECL_BSWAP64
336 #ifdef bswap64
337 #undef bswap64
338 #endif
339 #define bswap64(x) __nbcompat_bswap64(x)
340 #endif
342 #if !HAVE_MKSTEMP
343 int mkstemp(char *);
344 #endif
346 #if !HAVE_MKDTEMP
347 char *mkdtemp(char *);
348 #endif
350 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
351 /* This is a prototype for the internal function defined in
352 * src/lib/lib/stdio/gettemp.c */
353 int __nbcompat_gettemp(char *, int *, int);
354 #endif
356 #if !HAVE_PREAD
357 ssize_t pread(int, void *, size_t, off_t);
358 #endif
360 #if !HAVE_HEAPSORT
361 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
362 #endif
363 /* Make them use our version */
364 # define heapsort __nbcompat_heapsort
366 char *flags_to_string(unsigned long, const char *);
367 int string_to_flags(char **, unsigned long *, unsigned long *);
370 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
371 * supply an implementation of one without the others -- some parts are
372 * libc internal and this varies from system to system.
374 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
375 * XXX host system has all of these functions, all of their interfaces
376 * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
378 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
379 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
380 /* Make them use our version */
381 # define user_from_uid __nbcompat_user_from_uid
382 # define uid_from_user __nbcompat_uid_from_user
383 # define pwcache_userdb __nbcompat_pwcache_userdb
384 # define group_from_gid __nbcompat_group_from_gid
385 # define gid_from_group __nbcompat_gid_from_group
386 # define pwcache_groupdb __nbcompat_pwcache_groupdb
387 #endif
389 #if !HAVE_DECL_UID_FROM_USER
390 int uid_from_user(const char *, uid_t *);
391 #endif
393 #if !HAVE_DECL_USER_FROM_UID
394 const char *user_from_uid(uid_t, int);
395 #endif
397 #if !HAVE_DECL_PWCACHE_USERDB
398 int pwcache_userdb(int (*)(int), void (*)(void),
399 struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
400 #endif
402 #if !HAVE_DECL_GID_FROM_GROUP
403 int gid_from_group(const char *, gid_t *);
404 #endif
406 #if !HAVE_DECL_GROUP_FROM_GID
407 const char *group_from_gid(gid_t, int);
408 #endif
410 #if !HAVE_DECL_PWCACHE_GROUPDB
411 int pwcache_groupdb(int (*)(int), void (*)(void),
412 struct group * (*)(const char *), struct group * (*)(gid_t));
413 #endif
415 #if !HAVE_DECL_STRNDUP
416 char *strndup(const char *, size_t);
417 #endif
418 #if !HAVE_DECL_LCHFLAGS
419 int lchflags(const char *, unsigned long);
420 #endif
421 #if !HAVE_DECL_LCHMOD
422 int lchmod(const char *, mode_t);
423 #endif
424 #if !HAVE_DECL_LCHOWN
425 int lchown(const char *, uid_t, gid_t);
426 #endif
428 #if !HAVE_PWRITE
429 ssize_t pwrite(int, const void *, size_t, off_t);
430 #endif
432 #if !HAVE_RAISE_DEFAULT_SIGNAL
433 int raise_default_signal(int);
434 #endif
436 #if !HAVE_SETENV
437 int setenv(const char *, const char *, int);
438 #endif
440 #if !HAVE_DECL_SETGROUPENT
441 int setgroupent(int);
442 #endif
444 #if !HAVE_DECL_SETPASSENT
445 int setpassent(int);
446 #endif
448 #if !HAVE_SETPROGNAME || defined(__NetBSD__) || defined(__minix)
449 const char *getprogname(void);
450 void setprogname(const char *);
451 #endif
453 #if !HAVE_SNPRINTB_M
454 int snprintb(char *, size_t, const char *, uint64_t);
455 int snprintb_m(char *, size_t, const char *, uint64_t, size_t);
456 #endif
458 #if !HAVE_SNPRINTF
459 int snprintf(char *, size_t, const char *, ...);
460 #endif
462 #if !HAVE_STRLCAT
463 size_t strlcat(char *, const char *, size_t);
464 #endif
466 #if !HAVE_STRLCPY
467 size_t strlcpy(char *, const char *, size_t);
468 #endif
470 #if !HAVE_STRMODE
471 void strmode(mode_t, char *);
472 #endif
474 #if !HAVE_STRNDUP
475 char *strndup(const char *, size_t);
476 #endif
478 #if !HAVE_STRSEP || defined(__NetBSD__) || defined(__minix)
479 char *strsep(char **, const char *);
480 #endif
482 #if !HAVE_DECL_STRSUFTOLL
483 long long strsuftoll(const char *, const char *, long long, long long);
484 long long strsuftollx(const char *, const char *,
485 long long, long long, char *, size_t);
486 #endif
488 #if !HAVE_STRTOLL
489 long long strtoll(const char *, char **, int);
490 #endif
492 #if !HAVE_USER_FROM_UID
493 const char *user_from_uid(uid_t, int);
494 #endif
496 #if !HAVE_GROUP_FROM_GID
497 const char *group_from_gid(gid_t, int);
498 #endif
500 #if !HAVE_VASPRINTF
501 int vasprintf(char **, const char *, va_list);
502 #endif
504 #if !HAVE_VASNPRINTF
505 int vasnprintf(char **, size_t, const char *, va_list);
506 #endif
508 #if !HAVE_VSNPRINTF
509 int vsnprintf(char *, size_t, const char *, va_list);
510 #endif
513 * getmode() and setmode() are always defined, as these function names
514 * exist but with very different meanings on other OS's. The compat
515 * versions here simply accept an octal mode number; the "u+x,g-w" type
516 * of syntax is not accepted.
519 #define getmode __nbcompat_getmode
520 #define setmode __nbcompat_setmode
522 mode_t getmode(const void *, mode_t);
523 void *setmode(const char *);
525 /* Eliminate assertions embedded in binaries. */
527 #undef _DIAGASSERT
528 #define _DIAGASSERT(x)
530 /* Various sources use this */
531 #undef __RCSID
532 #define __RCSID(x) struct XXXNETBSD_RCSID
533 #undef __SCCSID
534 #define __SCCSID(x)
535 #undef __COPYRIGHT
536 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
537 #undef __KERNEL_RCSID
538 #define __KERNEL_RCSID(x,y)
540 /* Heimdal expects this one. */
542 #undef RCSID
543 #define RCSID(x)
545 /* Some definitions not available on all systems. */
547 #ifndef __inline
548 #define __inline inline
549 #endif
551 /* <errno.h> */
553 #ifndef EFTYPE
554 #define EFTYPE EIO
555 #endif
557 /* <fcntl.h> */
559 #ifndef O_EXLOCK
560 #define O_EXLOCK 0
561 #endif
562 #ifndef O_SHLOCK
563 #define O_SHLOCK 0
564 #endif
566 /* <inttypes.h> */
568 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */
569 #ifndef PRId8
570 #define PRId8 "hhd"
571 #endif
572 #ifndef PRIi8
573 #define PRIi8 "hhi"
574 #endif
575 #ifndef PRIo8
576 #define PRIo8 "hho"
577 #endif
578 #ifndef PRIu8
579 #define PRIu8 "hhu"
580 #endif
581 #ifndef PRIx8
582 #define PRIx8 "hhx"
583 #endif
584 #ifndef PRIX8
585 #define PRIX8 "hhX"
586 #endif
587 #ifndef SCNd8
588 #define SCNd8 "hhd"
589 #endif
590 #ifndef SCNi8
591 #define SCNi8 "hhi"
592 #endif
593 #ifndef SCNo8
594 #define SCNo8 "hho"
595 #endif
596 #ifndef SCNu8
597 #define SCNu8 "hhu"
598 #endif
599 #ifndef SCNx8
600 #define SCNx8 "hhx"
601 #endif
602 #ifndef SCNX8
603 #define SCNX8 "hhX"
604 #endif
605 #endif /* char is an 8-bit type */
606 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
607 defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
608 #error "Don't know how to define PRI[diouxX]8"
609 #endif
610 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
611 defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
612 #error "Don't know how to define SCN[diouxX]8"
613 #endif
615 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */
616 #ifndef PRId16
617 #define PRId16 "hd"
618 #endif
619 #ifndef PRIi16
620 #define PRIi16 "hi"
621 #endif
622 #ifndef PRIo16
623 #define PRIo16 "ho"
624 #endif
625 #ifndef PRIu16
626 #define PRIu16 "hu"
627 #endif
628 #ifndef PRIx16
629 #define PRIx16 "hx"
630 #endif
631 #ifndef PRIX16
632 #define PRIX16 "hX"
633 #endif
634 #ifndef SCNd16
635 #define SCNd16 "hd"
636 #endif
637 #ifndef SCNi16
638 #define SCNi16 "hi"
639 #endif
640 #ifndef SCNo16
641 #define SCNo16 "ho"
642 #endif
643 #ifndef SCNu16
644 #define SCNu16 "hu"
645 #endif
646 #ifndef SCNx16
647 #define SCNx16 "hx"
648 #endif
649 #ifndef SCNX16
650 #define SCNX16 "hX"
651 #endif
652 #endif /* short is a 16-bit type */
653 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
654 defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
655 #error "Don't know how to define PRI[diouxX]16"
656 #endif
657 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
658 defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
659 #error "Don't know how to define SCN[diouxX]16"
660 #endif
662 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
663 #ifndef PRId32
664 #define PRId32 "d"
665 #endif
666 #ifndef PRIi32
667 #define PRIi32 "i"
668 #endif
669 #ifndef PRIo32
670 #define PRIo32 "o"
671 #endif
672 #ifndef PRIu32
673 #define PRIu32 "u"
674 #endif
675 #ifndef PRIx32
676 #define PRIx32 "x"
677 #endif
678 #ifndef PRIX32
679 #define PRIX32 "X"
680 #endif
681 #ifndef SCNd32
682 #define SCNd32 "d"
683 #endif
684 #ifndef SCNi32
685 #define SCNi32 "i"
686 #endif
687 #ifndef SCNo32
688 #define SCNo32 "o"
689 #endif
690 #ifndef SCNu32
691 #define SCNu32 "u"
692 #endif
693 #ifndef SCNx32
694 #define SCNx32 "x"
695 #endif
696 #ifndef SCNX32
697 #define SCNX32 "X"
698 #endif
699 #endif /* int is a 32-bit type */
700 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
701 #ifndef PRId32
702 #define PRId32 "ld"
703 #endif
704 #ifndef PRIi32
705 #define PRIi32 "li"
706 #endif
707 #ifndef PRIo32
708 #define PRIo32 "lo"
709 #endif
710 #ifndef PRIu32
711 #define PRIu32 "lu"
712 #endif
713 #ifndef PRIx32
714 #define PRIx32 "lx"
715 #endif
716 #ifndef PRIX32
717 #define PRIX32 "lX"
718 #endif
719 #ifndef SCNd32
720 #define SCNd32 "ld"
721 #endif
722 #ifndef SCNi32
723 #define SCNi32 "li"
724 #endif
725 #ifndef SCNo32
726 #define SCNo32 "lo"
727 #endif
728 #ifndef SCNu32
729 #define SCNu32 "lu"
730 #endif
731 #ifndef SCNx32
732 #define SCNx32 "lx"
733 #endif
734 #ifndef SCNX32
735 #define SCNX32 "lX"
736 #endif
737 #endif /* long is a 32-bit type */
738 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
739 defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
740 #error "Don't know how to define PRI[diouxX]32"
741 #endif
742 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
743 defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
744 #error "Don't know how to define SCN[diouxX]32"
745 #endif
747 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
748 #ifndef PRId64
749 #define PRId64 "ld"
750 #endif
751 #ifndef PRIi64
752 #define PRIi64 "li"
753 #endif
754 #ifndef PRIo64
755 #define PRIo64 "lo"
756 #endif
757 #ifndef PRIu64
758 #define PRIu64 "lu"
759 #endif
760 #ifndef PRIx64
761 #define PRIx64 "lx"
762 #endif
763 #ifndef PRIX64
764 #define PRIX64 "lX"
765 #endif
766 #ifndef SCNd64
767 #define SCNd64 "ld"
768 #endif
769 #ifndef SCNi64
770 #define SCNi64 "li"
771 #endif
772 #ifndef SCNo64
773 #define SCNo64 "lo"
774 #endif
775 #ifndef SCNu64
776 #define SCNu64 "lu"
777 #endif
778 #ifndef SCNx64
779 #define SCNx64 "lx"
780 #endif
781 #ifndef SCNX64
782 #define SCNX64 "lX"
783 #endif
784 #endif /* long is a 64-bit type */
785 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
786 #ifndef PRId64
787 #define PRId64 "lld"
788 #endif
789 #ifndef PRIi64
790 #define PRIi64 "lli"
791 #endif
792 #ifndef PRIo64
793 #define PRIo64 "llo"
794 #endif
795 #ifndef PRIu64
796 #define PRIu64 "llu"
797 #endif
798 #ifndef PRIx64
799 #define PRIx64 "llx"
800 #endif
801 #ifndef PRIX64
802 #define PRIX64 "llX"
803 #endif
804 #ifndef SCNd64
805 #define SCNd64 "lld"
806 #endif
807 #ifndef SCNi64
808 #define SCNi64 "lli"
809 #endif
810 #ifndef SCNo64
811 #define SCNo64 "llo"
812 #endif
813 #ifndef SCNu64
814 #define SCNu64 "llu"
815 #endif
816 #ifndef SCNx64
817 #define SCNx64 "llx"
818 #endif
819 #ifndef SCNX64
820 #define SCNX64 "llX"
821 #endif
822 #endif /* long long is a 64-bit type */
823 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
824 defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
825 #error "Don't know how to define PRI[diouxX]64"
826 #endif
827 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
828 defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
829 #error "Don't know how to define SCN[diouxX]64"
830 #endif
832 /* <limits.h> */
834 #ifndef UID_MAX
835 #define UID_MAX 32767
836 #endif
837 #ifndef GID_MAX
838 #define GID_MAX UID_MAX
839 #endif
841 #ifndef UQUAD_MAX
842 #define UQUAD_MAX ((u_quad_t)-1)
843 #endif
844 #ifndef QUAD_MAX
845 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
846 #endif
847 #ifndef QUAD_MIN
848 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
849 #endif
850 #ifndef ULLONG_MAX
851 #define ULLONG_MAX ((unsigned long long)-1)
852 #endif
853 #ifndef LLONG_MAX
854 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
855 #endif
856 #ifndef LLONG_MIN
857 #define LLONG_MIN ((long long)(~LLONG_MAX))
858 #endif
860 /* <paths.h> */
862 /* The host's _PATH_BSHELL might be broken, so override it. */
863 #undef _PATH_BSHELL
864 #define _PATH_BSHELL PATH_BSHELL
865 #ifndef _PATH_DEFPATH
866 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
867 #endif
868 #ifndef _PATH_DEV
869 #define _PATH_DEV "/dev/"
870 #endif
871 #ifndef _PATH_DEVNULL
872 #define _PATH_DEVNULL _PATH_DEV "null"
873 #endif
874 #ifndef _PATH_TMP
875 #define _PATH_TMP "/tmp/"
876 #endif
877 #ifndef _PATH_DEFTAPE
878 #define _PATH_DEFTAPE "/dev/nrst0"
879 #endif
880 #ifndef _PATH_VI
881 #define _PATH_VI "/usr/bin/vi"
882 #endif
884 /* <stdint.h> */
886 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
887 #define SIZE_MAX SIZE_T_MAX
888 #endif
890 #ifndef UINT8_MAX
891 #define UINT8_MAX 0xffU
892 #endif
894 #ifndef UINT16_MAX
895 #define UINT16_MAX 0xffffU
896 #endif
898 #ifndef UINT32_MAX
899 #define UINT32_MAX 0xffffffffU
900 #endif
902 /* <stdlib.h> */
904 #ifndef __GNUC__
905 # if HAVE_ALLOCA_H
906 # include <alloca.h>
907 # else
908 # ifndef alloca /* predefined by HP cc +Olibcalls */
909 char *alloca ();
910 # endif
911 # endif
912 #endif
914 /* avoid prototype conflicts with host */
915 #define cgetcap __nbcompat_cgetcap
916 #define cgetclose __nbcompat_cgetclose
917 #define cgetent __nbcompat_cgetent
918 #define cgetfirst __nbcompat_cgetfirst
919 #define cgetmatch __nbcompat_cgetmatch
920 #define cgetnext __nbcompat_cgetnext
921 #define cgetnum __nbcompat_cgetnum
922 #define cgetset __nbcompat_cgetset
923 #define cgetstr __nbcompat_cgetstr
924 #define cgetustr __nbcompat_cgetustr
926 char *cgetcap(char *, const char *, int);
927 int cgetclose(void);
928 int cgetent(char **, const char * const *, const char *);
929 int cgetfirst(char **, const char * const *);
930 int cgetmatch(const char *, const char *);
931 int cgetnext(char **, const char * const *);
932 int cgetnum(char *, const char *, long *);
933 int cgetset(const char *);
934 int cgetstr(char *, const char *, char **);
935 int cgetustr(char *, const char *, char **);
937 /* <sys/endian.h> */
939 #if WORDS_BIGENDIAN
940 #if !HAVE_DECL_HTOBE16
941 #define htobe16(x) (x)
942 #endif
943 #if !HAVE_DECL_HTOBE32
944 #define htobe32(x) (x)
945 #endif
946 #if !HAVE_DECL_HTOBE64
947 #define htobe64(x) (x)
948 #endif
949 #if !HAVE_DECL_HTOLE16
950 #define htole16(x) bswap16((u_int16_t)(x))
951 #endif
952 #if !HAVE_DECL_HTOLE32
953 #define htole32(x) bswap32((u_int32_t)(x))
954 #endif
955 #if !HAVE_DECL_HTOLE64
956 #define htole64(x) bswap64((u_int64_t)(x))
957 #endif
958 #else
959 #if !HAVE_DECL_HTOBE16
960 #define htobe16(x) bswap16((u_int16_t)(x))
961 #endif
962 #if !HAVE_DECL_HTOBE32
963 #define htobe32(x) bswap32((u_int32_t)(x))
964 #endif
965 #if !HAVE_DECL_HTOBE64
966 #define htobe64(x) bswap64((u_int64_t)(x))
967 #endif
968 #if !HAVE_DECL_HTOLE16
969 #define htole16(x) (x)
970 #endif
971 #if !HAVE_DECL_HTOLE32
972 #define htole32(x) (x)
973 #endif
974 #if !HAVE_DECL_HTOLE64
975 #define htole64(x) (x)
976 #endif
977 #endif
978 #if !HAVE_DECL_BE16TOH
979 #define be16toh(x) htobe16(x)
980 #endif
981 #if !HAVE_DECL_BE32TOH
982 #define be32toh(x) htobe32(x)
983 #endif
984 #if !HAVE_DECL_BE64TOH
985 #define be64toh(x) htobe64(x)
986 #endif
987 #if !HAVE_DECL_LE16TOH
988 #define le16toh(x) htole16(x)
989 #endif
990 #if !HAVE_DECL_LE32TOH
991 #define le32toh(x) htole32(x)
992 #endif
993 #if !HAVE_DECL_LE64TOH
994 #define le64toh(x) htole64(x)
995 #endif
997 #define __GEN_ENDIAN_ENC(bits, endian) \
998 static void \
999 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
1001 u = hto ## endian ## bits (u); \
1002 memcpy(dst, &u, sizeof(u)); \
1004 #if !HAVE_DECL_BE16ENC
1005 __GEN_ENDIAN_ENC(16, be)
1006 #endif
1007 #if !HAVE_DECL_BE32ENC
1008 __GEN_ENDIAN_ENC(32, be)
1009 #endif
1010 #if !HAVE_DECL_BE64ENC
1011 __GEN_ENDIAN_ENC(64, be)
1012 #endif
1013 #if !HAVE_DECL_LE16ENC
1014 __GEN_ENDIAN_ENC(16, le)
1015 #endif
1016 #if !HAVE_DECL_LE32ENC
1017 __GEN_ENDIAN_ENC(32, le)
1018 #endif
1019 #if !HAVE_DECL_LE64ENC
1020 __GEN_ENDIAN_ENC(64, le)
1021 #endif
1022 #undef __GEN_ENDIAN_ENC
1024 #define __GEN_ENDIAN_DEC(bits, endian) \
1025 static uint ## bits ## _t \
1026 endian ## bits ## dec(const void *buf) \
1028 uint ## bits ## _t u; \
1029 memcpy(&u, buf, sizeof(u)); \
1030 return endian ## bits ## toh (u); \
1032 #if !HAVE_DECL_BE16DEC
1033 __GEN_ENDIAN_DEC(16, be)
1034 #endif
1035 #if !HAVE_DECL_BE32DEC
1036 __GEN_ENDIAN_DEC(32, be)
1037 #endif
1038 #if !HAVE_DECL_BE64DEC
1039 __GEN_ENDIAN_DEC(64, be)
1040 #endif
1041 #if !HAVE_DECL_LE16DEC
1042 __GEN_ENDIAN_DEC(16, le)
1043 #endif
1044 #if !HAVE_DECL_LE32DEC
1045 __GEN_ENDIAN_DEC(32, le)
1046 #endif
1047 #if !HAVE_DECL_LE64DEC
1048 __GEN_ENDIAN_DEC(64, le)
1049 #endif
1050 #undef __GEN_ENDIAN_DEC
1052 /* <sys/mman.h> */
1054 #ifndef MAP_FILE
1055 #define MAP_FILE 0
1056 #endif
1058 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
1059 #ifndef MAP_ANON
1060 #ifdef MAP_ANONYMOUS
1061 #define MAP_ANON MAP_ANONYMOUS
1062 #endif
1063 #endif
1065 /* <sys/param.h> */
1067 #undef BIG_ENDIAN
1068 #undef LITTLE_ENDIAN
1069 #undef PDP_ENDIAN
1070 #define BIG_ENDIAN 4321
1071 #define LITTLE_ENDIAN 1234
1072 #define PDP_ENDIAN 3412
1074 #undef BYTE_ORDER
1075 #if WORDS_BIGENDIAN
1076 #define BYTE_ORDER BIG_ENDIAN
1077 #else
1078 #define BYTE_ORDER LITTLE_ENDIAN
1079 #endif
1081 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
1082 #undef DEV_BSIZE
1083 #define DEV_BSIZE (1 << 9)
1085 #undef MIN
1086 #undef MAX
1087 #define MIN(a,b) ((a) < (b) ? (a) : (b))
1088 #define MAX(a,b) ((a) > (b) ? (a) : (b))
1090 #ifndef MAXBSIZE
1091 #define MAXBSIZE (64 * 1024)
1092 #endif
1093 #ifndef MAXFRAG
1094 #define MAXFRAG 8
1095 #endif
1096 #ifndef MAXPHYS
1097 #define MAXPHYS (64 * 1024)
1098 #endif
1100 /* XXX needed by makefs; this should be done in a better way */
1101 #undef btodb
1102 #define btodb(x) ((x) << 9)
1104 #undef setbit
1105 #undef clrbit
1106 #undef isset
1107 #undef isclr
1108 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1109 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1110 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1111 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1113 #ifndef powerof2
1114 #define powerof2(x) ((((x)-1)&(x))==0)
1115 #endif
1117 #undef roundup
1118 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1120 /* <sys/stat.h> */
1122 #ifndef ALLPERMS
1123 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
1124 #endif
1125 #ifndef DEFFILEMODE
1126 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
1127 #endif
1128 #ifndef S_ISTXT
1129 #ifdef S_ISVTX
1130 #define S_ISTXT S_ISVTX
1131 #else
1132 #define S_ISTXT 0
1133 #endif
1134 #endif
1136 /* Protected by _NETBSD_SOURCE otherwise. */
1137 #if HAVE_STRUCT_STAT_ST_FLAGS && (defined(__NetBSD__) || defined(__minix))
1138 #define UF_SETTABLE 0x0000ffff
1139 #define UF_NODUMP 0x00000001
1140 #define UF_IMMUTABLE 0x00000002
1141 #define UF_APPEND 0x00000004
1142 #define UF_OPAQUE 0x00000008
1143 #define SF_SETTABLE 0xffff0000
1144 #define SF_ARCHIVED 0x00010000
1145 #define SF_IMMUTABLE 0x00020000
1146 #define SF_APPEND 0x00040000
1147 #endif
1149 /* <sys/syslimits.h> */
1151 #ifndef LINE_MAX
1152 #define LINE_MAX 2048
1153 #endif
1155 /* <sys/time.h> */
1157 #ifndef timercmp
1158 #define timercmp(tvp, uvp, cmp) \
1159 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
1160 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1161 ((tvp)->tv_sec cmp (uvp)->tv_sec))
1162 #endif
1163 #ifndef timeradd
1164 #define timeradd(tvp, uvp, vvp) \
1165 do { \
1166 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
1167 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
1168 if ((vvp)->tv_usec >= 1000000) { \
1169 (vvp)->tv_sec++; \
1170 (vvp)->tv_usec -= 1000000; \
1172 } while (/* CONSTCOND */ 0)
1173 #endif
1174 #ifndef timersub
1175 #define timersub(tvp, uvp, vvp) \
1176 do { \
1177 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
1178 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
1179 if ((vvp)->tv_usec < 0) { \
1180 (vvp)->tv_sec--; \
1181 (vvp)->tv_usec += 1000000; \
1183 } while (/* CONSTCOND */ 0)
1184 #endif
1186 /* <sys/types.h> */
1188 #ifdef major
1189 #undef major
1190 #endif
1191 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
1193 #ifdef minor
1194 #undef minor
1195 #endif
1196 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
1197 (((x) & 0x000000ff) >> 0)))
1198 #ifdef makedev
1199 #undef makedev
1200 #endif
1201 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
1202 (((y) << 12) & 0xfff00000) | \
1203 (((y) << 0) & 0x000000ff)))
1204 #ifndef NBBY
1205 #define NBBY 8
1206 #endif
1208 #if !HAVE_U_QUAD_T
1209 /* #define, not typedef, as quad_t exists as a struct on some systems */
1210 #define quad_t long long
1211 #define u_quad_t unsigned long long
1212 #define strtoq strtoll
1213 #define strtouq strtoull
1214 #endif
1216 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
1217 #if defined(__NetBSD__) || defined(__minix)
1218 quad_t strtoq(const char *, char **, int);
1219 u_quad_t strtouq(const char *, char **, int);
1220 #endif
1222 #endif /* !__NETBSD_COMPAT_DEFS_H__ */