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