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