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