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