Home | History | Annotate | Line # | Download | only in compat
      1 /*	$NetBSD: compat_defs.h,v 1.127 2025/09/18 20:24:48 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_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_MKSTEMPS
    452 int mkstemps(char *, int);
    453 #endif
    454 
    455 #if !HAVE_DECL_MKDTEMP
    456 char *mkdtemp(char *);
    457 #endif
    458 
    459 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
    460 /* This is a prototype for the internal function defined in
    461  * src/lib/libc/stdio/gettemp.c */
    462 int __nbcompat_gettemp(char *, int *, int);
    463 #endif
    464 
    465 #if !HAVE_DECL_PREAD
    466 ssize_t pread(int, void *, size_t, off_t);
    467 #endif
    468 
    469 int __nbcompat_heapsort(void *, size_t, size_t,
    470     int (*)(const void *, const void *));
    471 int __nbcompat_heapsort_r(void *, size_t, size_t,
    472     int (*)(const void *, const void *, void *), void *);
    473 #define heapsort __nbcompat_heapsort
    474 #define heapsort_r __nbcompat_heapsort_r
    475 
    476 #if !HAVE_DECL_HEAPSORT
    477 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
    478 #endif
    479 
    480 char	       *flags_to_string(unsigned long, const char *);
    481 int		string_to_flags(char **, unsigned long *, unsigned long *);
    482 
    483 /*
    484  * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
    485  * supply an implementation of one without the others -- some parts are
    486  * libc internal and this varies from system to system.
    487  *
    488  * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
    489  * XXX host system has all of these functions, all of their interfaces
    490  * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
    491  */
    492 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
    493     !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
    494 /* Make them use our version */
    495 #  define user_from_uid __nbcompat_user_from_uid
    496 #  define uid_from_user __nbcompat_uid_from_user
    497 #  define pwcache_userdb __nbcompat_pwcache_userdb
    498 #  define group_from_gid __nbcompat_group_from_gid
    499 #  define gid_from_group __nbcompat_gid_from_group
    500 #  define pwcache_groupdb __nbcompat_pwcache_groupdb
    501 #endif
    502 
    503 #if !HAVE_DECL_UID_FROM_USER
    504 int uid_from_user(const char *, uid_t *);
    505 #endif
    506 
    507 #if !HAVE_DECL_USER_FROM_UID
    508 const char *user_from_uid(uid_t, int);
    509 #endif
    510 
    511 #if !HAVE_DECL_PWCACHE_USERDB
    512 int pwcache_userdb(int (*)(int), void (*)(void),
    513                 struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
    514 #endif
    515 
    516 #if !HAVE_DECL_GID_FROM_GROUP
    517 int gid_from_group(const char *, gid_t *);
    518 #endif
    519 
    520 #if !HAVE_DECL_GROUP_FROM_GID
    521 const char *group_from_gid(gid_t, int);
    522 #endif
    523 
    524 #if !HAVE_DECL_PWCACHE_GROUPDB
    525 int pwcache_groupdb(int (*)(int), void (*)(void),
    526     struct group * (*)(const char *), struct group * (*)(gid_t));
    527 #endif
    528 
    529 #if !HAVE_DECL_SHQUOTE
    530 size_t		shquote(const char *, char *, size_t);
    531 #endif
    532 #if !HAVE_DECL_STRLCAT
    533 size_t		strlcat(char *, const char *, size_t);
    534 #endif
    535 #if !HAVE_DECL_STRLCPY
    536 size_t		strlcpy(char *, const char *, size_t);
    537 #endif
    538 #if !HAVE_DECL_STRNDUP
    539 char		*strndup(const char *, size_t);
    540 #endif
    541 #if !HAVE_DECL_STRNLEN
    542 size_t		strnlen(const char *, size_t);
    543 #endif
    544 #if !HAVE_DECL_STRCASECMP
    545 int		strcasecmp(const char *, const char *);
    546 #endif
    547 #if !HAVE_DECL_STRNCASECMP
    548 int		strncasecmp(const char *, const char *, size_t);
    549 #endif
    550 #if !HAVE_DECL_STRCASESTR
    551 char		*strcasestr(const char *, const char *);
    552 #endif
    553 #if !HAVE_DECL_LCHFLAGS
    554 int		lchflags(const char *, unsigned long);
    555 #endif
    556 #if !HAVE_DECL_LCHMOD
    557 int		lchmod(const char *, mode_t);
    558 #endif
    559 #if !HAVE_DECL_LCHOWN
    560 int		lchown(const char *, uid_t, gid_t);
    561 #endif
    562 
    563 #if !HAVE_DECL_PWRITE
    564 ssize_t pwrite(int, const void *, size_t, off_t);
    565 #endif
    566 
    567 #if !HAVE_RAISE_DEFAULT_SIGNAL
    568 int raise_default_signal(int);
    569 #endif
    570 
    571 #if !HAVE_DECL_REALLOCARR
    572 int reallocarr(void *, size_t, size_t);
    573 #endif
    574 
    575 #if !HAVE_DECL_REALLOCARRAY
    576 void *reallocarray(void *, size_t, size_t);
    577 #endif
    578 
    579 #if !HAVE_DECL_SETENV
    580 int setenv(const char *, const char *, int);
    581 #endif
    582 
    583 #if !HAVE_DECL_SETGROUPENT
    584 int setgroupent(int);
    585 #endif
    586 
    587 #if !HAVE_DECL_SETPASSENT
    588 int setpassent(int);
    589 #endif
    590 
    591 #if !HAVE_DECL_GETPROGNAME
    592 const char *getprogname(void);
    593 #endif
    594 #if !HAVE_DECL_SETPROGNAME
    595 void setprogname(const char *);
    596 #endif
    597 
    598 #if !HAVE_SNPRINTB_M
    599 int snprintb(char *, size_t, const char *, uint64_t);
    600 int snprintb_m(char *, size_t, const char *, uint64_t, size_t);
    601 #endif
    602 
    603 #if !HAVE_DECL_SNPRINTF && !defined(snprintf)
    604 int snprintf(char *, size_t, const char *, ...);
    605 #endif
    606 
    607 #if !HAVE_DECL_STRMODE
    608 void strmode(mode_t, char *);
    609 #endif
    610 
    611 #if !HAVE_DECL_STRNDUP
    612 char *strndup(const char *, size_t);
    613 #endif
    614 
    615 #if !HAVE_DECL_STRSEP
    616 char *strsep(char **, const char *);
    617 #endif
    618 
    619 #if !HAVE_DECL_STRSUFTOLL
    620 long long strsuftoll(const char *, const char *, long long, long long);
    621 long long strsuftollx(const char *, const char *,
    622 			long long, long long, char *, size_t);
    623 #endif
    624 
    625 #if !HAVE_DECL_STRTOLL
    626 long long strtoll(const char *, char **, int);
    627 #endif
    628 
    629 #if !HAVE_DECL_STRTONUM
    630 long long strtonum(const char *, long long, long long, const char **);
    631 #endif
    632 
    633 #if !HAVE_DECL_STRTOI
    634 intmax_t strtoi(const char * __restrict, char ** __restrict, int,
    635     intmax_t, intmax_t, int *);
    636 #endif
    637 
    638 #if !HAVE_DECL_STRTOU
    639 uintmax_t strtou(const char * __restrict, char ** __restrict, int,
    640     uintmax_t, uintmax_t, int *);
    641 #endif
    642 
    643 #if !HAVE_DECL_USER_FROM_UID
    644 const char *user_from_uid(uid_t, int);
    645 #endif
    646 
    647 #if !HAVE_DECL_GROUP_FROM_GID
    648 const char *group_from_gid(gid_t, int);
    649 #endif
    650 
    651 #if !HAVE_DECL_VASPRINTF
    652 int vasprintf(char **, const char *, va_list);
    653 #endif
    654 
    655 #if !HAVE_DECL_VASNPRINTF
    656 int vasnprintf(char **, size_t, const char *, va_list);
    657 #endif
    658 
    659 #if !HAVE_DECL_VSNPRINTF && !defined(vsnprintf)
    660 int vsnprintf(char *, size_t, const char *, va_list);
    661 #endif
    662 
    663 #if !HAVE_DECL_VSYSLOG
    664 void vsyslog(int, const char *, va_list);
    665 #endif
    666 
    667 /*
    668  * getmode() and setmode() are always defined, as these function names
    669  * exist but with very different meanings on other OS's.  The compat
    670  * versions here simply accept an octal mode number; the "u+x,g-w" type
    671  * of syntax is not accepted.
    672  */
    673 
    674 #define getmode __nbcompat_getmode
    675 #define setmode __nbcompat_setmode
    676 
    677 mode_t getmode(const void *, mode_t);
    678 void *setmode(const char *);
    679 
    680 /* Eliminate assertions embedded in binaries. */
    681 
    682 #undef _DIAGASSERT
    683 #define _DIAGASSERT(x)
    684 
    685 /* Various sources use this */
    686 #undef	__RCSID
    687 #define	__RCSID(x) struct XXXNETBSD_RCSID
    688 #undef	__SCCSID
    689 #define	__SCCSID(x)
    690 #undef	__COPYRIGHT
    691 #define	__COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
    692 #undef	__KERNEL_RCSID
    693 #define	__KERNEL_RCSID(x,y)
    694 
    695 /* Heimdal expects this one. */
    696 
    697 #undef RCSID
    698 #define RCSID(x)
    699 
    700 /* Some definitions not available on all systems. */
    701 
    702 #ifndef __inline
    703 #define __inline inline
    704 #endif
    705 
    706 /* <errno.h> */
    707 
    708 #ifndef EFTYPE
    709 #define EFTYPE EIO
    710 #endif
    711 
    712 /* <fcntl.h> */
    713 
    714 #ifndef O_EXLOCK
    715 #define O_EXLOCK 0
    716 #endif
    717 #ifndef O_SHLOCK
    718 #define O_SHLOCK 0
    719 #endif
    720 #ifndef O_CLOEXEC
    721 #define O_CLOEXEC 0
    722 #endif
    723 
    724 /* <inttypes.h> */
    725 
    726 #if UCHAR_MAX == 0xffU			/* char is an 8-bit type */
    727 #ifndef PRId8
    728 #define PRId8 "hhd"
    729 #endif
    730 #ifndef PRIi8
    731 #define PRIi8 "hhi"
    732 #endif
    733 #ifndef PRIo8
    734 #define PRIo8 "hho"
    735 #endif
    736 #ifndef PRIu8
    737 #define PRIu8 "hhu"
    738 #endif
    739 #ifndef PRIx8
    740 #define PRIx8 "hhx"
    741 #endif
    742 #ifndef PRIX8
    743 #define PRIX8 "hhX"
    744 #endif
    745 #ifndef SCNd8
    746 #define SCNd8 "hhd"
    747 #endif
    748 #ifndef SCNi8
    749 #define SCNi8 "hhi"
    750 #endif
    751 #ifndef SCNo8
    752 #define SCNo8 "hho"
    753 #endif
    754 #ifndef SCNu8
    755 #define SCNu8 "hhu"
    756 #endif
    757 #ifndef SCNx8
    758 #define SCNx8 "hhx"
    759 #endif
    760 #ifndef SCNX8
    761 #define SCNX8 "hhX"
    762 #endif
    763 #endif					/* char is an 8-bit type */
    764 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
    765 	defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
    766 #error "Don't know how to define PRI[diouxX]8"
    767 #endif
    768 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
    769 	defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
    770 #error "Don't know how to define SCN[diouxX]8"
    771 #endif
    772 
    773 #if USHRT_MAX == 0xffffU		/* short is a 16-bit type */
    774 #ifndef PRId16
    775 #define PRId16 "hd"
    776 #endif
    777 #ifndef PRIi16
    778 #define PRIi16 "hi"
    779 #endif
    780 #ifndef PRIo16
    781 #define PRIo16 "ho"
    782 #endif
    783 #ifndef PRIu16
    784 #define PRIu16 "hu"
    785 #endif
    786 #ifndef PRIx16
    787 #define PRIx16 "hx"
    788 #endif
    789 #ifndef PRIX16
    790 #define PRIX16 "hX"
    791 #endif
    792 #ifndef SCNd16
    793 #define SCNd16 "hd"
    794 #endif
    795 #ifndef SCNi16
    796 #define SCNi16 "hi"
    797 #endif
    798 #ifndef SCNo16
    799 #define SCNo16 "ho"
    800 #endif
    801 #ifndef SCNu16
    802 #define SCNu16 "hu"
    803 #endif
    804 #ifndef SCNx16
    805 #define SCNx16 "hx"
    806 #endif
    807 #ifndef SCNX16
    808 #define SCNX16 "hX"
    809 #endif
    810 #endif					/* short is a 16-bit type */
    811 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
    812 	defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
    813 #error "Don't know how to define PRI[diouxX]16"
    814 #endif
    815 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
    816 	defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
    817 #error "Don't know how to define SCN[diouxX]16"
    818 #endif
    819 
    820 #if UINT_MAX == 0xffffffffU		/* int is a 32-bit type */
    821 #ifndef PRId32
    822 #define PRId32 "d"
    823 #endif
    824 #ifndef PRIi32
    825 #define PRIi32 "i"
    826 #endif
    827 #ifndef PRIo32
    828 #define PRIo32 "o"
    829 #endif
    830 #ifndef PRIu32
    831 #define PRIu32 "u"
    832 #endif
    833 #ifndef PRIx32
    834 #define PRIx32 "x"
    835 #endif
    836 #ifndef PRIX32
    837 #define PRIX32 "X"
    838 #endif
    839 #ifndef SCNd32
    840 #define SCNd32 "d"
    841 #endif
    842 #ifndef SCNi32
    843 #define SCNi32 "i"
    844 #endif
    845 #ifndef SCNo32
    846 #define SCNo32 "o"
    847 #endif
    848 #ifndef SCNu32
    849 #define SCNu32 "u"
    850 #endif
    851 #ifndef SCNx32
    852 #define SCNx32 "x"
    853 #endif
    854 #ifndef SCNX32
    855 #define SCNX32 "X"
    856 #endif
    857 #endif					/* int is a 32-bit type */
    858 #if ULONG_MAX == 0xffffffffU		/* long is a 32-bit type */
    859 #ifndef PRId32
    860 #define PRId32 "ld"
    861 #endif
    862 #ifndef PRIi32
    863 #define PRIi32 "li"
    864 #endif
    865 #ifndef PRIo32
    866 #define PRIo32 "lo"
    867 #endif
    868 #ifndef PRIu32
    869 #define PRIu32 "lu"
    870 #endif
    871 #ifndef PRIx32
    872 #define PRIx32 "lx"
    873 #endif
    874 #ifndef PRIX32
    875 #define PRIX32 "lX"
    876 #endif
    877 #ifndef SCNd32
    878 #define SCNd32 "ld"
    879 #endif
    880 #ifndef SCNi32
    881 #define SCNi32 "li"
    882 #endif
    883 #ifndef SCNo32
    884 #define SCNo32 "lo"
    885 #endif
    886 #ifndef SCNu32
    887 #define SCNu32 "lu"
    888 #endif
    889 #ifndef SCNx32
    890 #define SCNx32 "lx"
    891 #endif
    892 #ifndef SCNX32
    893 #define SCNX32 "lX"
    894 #endif
    895 #endif					/* long is a 32-bit type */
    896 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
    897 	defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
    898 #error "Don't know how to define PRI[diouxX]32"
    899 #endif
    900 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
    901 	defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
    902 #error "Don't know how to define SCN[diouxX]32"
    903 #endif
    904 
    905 #if ULONG_MAX == 0xffffffffffffffffU	/* long is a 64-bit type */
    906 #ifndef PRId64
    907 #define PRId64 "ld"
    908 #endif
    909 #ifndef PRIi64
    910 #define PRIi64 "li"
    911 #endif
    912 #ifndef PRIo64
    913 #define PRIo64 "lo"
    914 #endif
    915 #ifndef PRIu64
    916 #define PRIu64 "lu"
    917 #endif
    918 #ifndef PRIx64
    919 #define PRIx64 "lx"
    920 #endif
    921 #ifndef PRIX64
    922 #define PRIX64 "lX"
    923 #endif
    924 #ifndef SCNd64
    925 #define SCNd64 "ld"
    926 #endif
    927 #ifndef SCNi64
    928 #define SCNi64 "li"
    929 #endif
    930 #ifndef SCNo64
    931 #define SCNo64 "lo"
    932 #endif
    933 #ifndef SCNu64
    934 #define SCNu64 "lu"
    935 #endif
    936 #ifndef SCNx64
    937 #define SCNx64 "lx"
    938 #endif
    939 #ifndef SCNX64
    940 #define SCNX64 "lX"
    941 #endif
    942 #endif					/* long is a 64-bit type */
    943 #if ULLONG_MAX == 0xffffffffffffffffU	/* long long is a 64-bit type */
    944 #ifndef PRId64
    945 #define PRId64 "lld"
    946 #endif
    947 #ifndef PRIi64
    948 #define PRIi64 "lli"
    949 #endif
    950 #ifndef PRIo64
    951 #define PRIo64 "llo"
    952 #endif
    953 #ifndef PRIu64
    954 #define PRIu64 "llu"
    955 #endif
    956 #ifndef PRIx64
    957 #define PRIx64 "llx"
    958 #endif
    959 #ifndef PRIX64
    960 #define PRIX64 "llX"
    961 #endif
    962 #ifndef SCNd64
    963 #define SCNd64 "lld"
    964 #endif
    965 #ifndef SCNi64
    966 #define SCNi64 "lli"
    967 #endif
    968 #ifndef SCNo64
    969 #define SCNo64 "llo"
    970 #endif
    971 #ifndef SCNu64
    972 #define SCNu64 "llu"
    973 #endif
    974 #ifndef SCNx64
    975 #define SCNx64 "llx"
    976 #endif
    977 #ifndef SCNX64
    978 #define SCNX64 "llX"
    979 #endif
    980 #endif					/* long long is a 64-bit type */
    981 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
    982 	defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
    983 #error "Don't know how to define PRI[diouxX]64"
    984 #endif
    985 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
    986 	defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
    987 #error "Don't know how to define SCN[diouxX]64"
    988 #endif
    989 
    990 /* <limits.h> */
    991 
    992 #ifndef UID_MAX
    993 #define UID_MAX 32767
    994 #endif
    995 #ifndef GID_MAX
    996 #define GID_MAX UID_MAX
    997 #endif
    998 
    999 #ifndef UQUAD_MAX
   1000 #define UQUAD_MAX ((u_quad_t)-1)
   1001 #endif
   1002 #ifndef QUAD_MAX
   1003 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
   1004 #endif
   1005 #ifndef QUAD_MIN
   1006 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
   1007 #endif
   1008 #ifndef ULLONG_MAX
   1009 #define ULLONG_MAX ((unsigned long long)-1)
   1010 #endif
   1011 #ifndef LLONG_MAX
   1012 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
   1013 #endif
   1014 #ifndef LLONG_MIN
   1015 #define LLONG_MIN ((long long)(~LLONG_MAX))
   1016 #endif
   1017 
   1018 #ifndef MAXPATHLEN
   1019 #define MAXPATHLEN	4096
   1020 #endif
   1021 
   1022 #ifndef NAME_MAX
   1023 #ifdef _XOPEN_NAME_MAX
   1024 #define NAME_MAX _XOPEN_NAME_MAX
   1025 #else
   1026 #error "Both NAME_MAX and _XOPEN_NAME_MAX are not defined"
   1027 #endif
   1028 #endif
   1029 
   1030 #ifndef PATH_MAX
   1031 #define PATH_MAX	MAXPATHLEN
   1032 #endif
   1033 
   1034 /* <paths.h> */
   1035 
   1036 /* The host's _PATH_BSHELL might be broken, so override it. */
   1037 #undef _PATH_BSHELL
   1038 #define _PATH_BSHELL PATH_BSHELL
   1039 #ifndef _PATH_DEFPATH
   1040 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
   1041 #endif
   1042 #ifndef _PATH_DEV
   1043 #define _PATH_DEV "/dev/"
   1044 #endif
   1045 #ifndef _PATH_DEVNULL
   1046 #define _PATH_DEVNULL _PATH_DEV "null"
   1047 #endif
   1048 #ifndef _PATH_TMP
   1049 #define _PATH_TMP "/tmp/"
   1050 #endif
   1051 #ifndef _PATH_DEFTAPE
   1052 #define _PATH_DEFTAPE "/dev/nrst0"
   1053 #endif
   1054 #ifndef _PATH_VI
   1055 #define _PATH_VI "/usr/bin/vi"
   1056 #endif
   1057 
   1058 /* <stdint.h> */
   1059 
   1060 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
   1061 #define SIZE_MAX SIZE_T_MAX
   1062 #endif
   1063 
   1064 #ifndef UINT8_MAX
   1065 #define UINT8_MAX 0xffU
   1066 #endif
   1067 
   1068 #ifndef UINT16_MAX
   1069 #define UINT16_MAX 0xffffU
   1070 #endif
   1071 
   1072 #ifndef UINT32_MAX
   1073 #define UINT32_MAX 0xffffffffU
   1074 #endif
   1075 
   1076 /* <stdlib.h> */
   1077 
   1078 #ifndef __GNUC__
   1079 # if HAVE_ALLOCA_H
   1080 #  include <alloca.h>
   1081 # else
   1082 #  ifndef alloca /* predefined by HP cc +Olibcalls */
   1083 char *alloca ();
   1084 #  endif
   1085 # endif
   1086 #endif
   1087 
   1088 /* avoid prototype conflicts with host */
   1089 #define cgetcap __nbcompat_cgetcap
   1090 #define cgetclose __nbcompat_cgetclose
   1091 #define cgetent __nbcompat_cgetent
   1092 #define cgetfirst __nbcompat_cgetfirst
   1093 #define cgetmatch __nbcompat_cgetmatch
   1094 #define cgetnext __nbcompat_cgetnext
   1095 #define cgetnum __nbcompat_cgetnum
   1096 #define cgetset __nbcompat_cgetset
   1097 #define cgetstr __nbcompat_cgetstr
   1098 #define cgetustr __nbcompat_cgetustr
   1099 
   1100 char	*cgetcap(char *, const char *, int);
   1101 int	 cgetclose(void);
   1102 int	 cgetent(char **, const char * const *, const char *);
   1103 int	 cgetfirst(char **, const char * const *);
   1104 int	 cgetmatch(const char *, const char *);
   1105 int	 cgetnext(char **, const char * const *);
   1106 int	 cgetnum(char *, const char *, long *);
   1107 int	 cgetset(const char *);
   1108 int	 cgetstr(char *, const char *, char **);
   1109 int	 cgetustr(char *, const char *, char **);
   1110 
   1111 /* <sys/endian.h> */
   1112 
   1113 #if WORDS_BIGENDIAN
   1114 #if !HAVE_DECL_HTOBE16
   1115 #define htobe16(x)	(x)
   1116 #endif
   1117 #if !HAVE_DECL_HTOBE32
   1118 #define htobe32(x)	(x)
   1119 #endif
   1120 #if !HAVE_DECL_HTOBE64
   1121 #define htobe64(x)	(x)
   1122 #endif
   1123 #if !HAVE_DECL_HTOLE16
   1124 #define htole16(x)	bswap16((u_int16_t)(x))
   1125 #endif
   1126 #if !HAVE_DECL_HTOLE32
   1127 #define htole32(x)	bswap32((u_int32_t)(x))
   1128 #endif
   1129 #if !HAVE_DECL_HTOLE64
   1130 #define htole64(x)	bswap64((u_int64_t)(x))
   1131 #endif
   1132 #else
   1133 #if !HAVE_DECL_HTOBE16
   1134 #define htobe16(x)	bswap16((u_int16_t)(x))
   1135 #endif
   1136 #if !HAVE_DECL_HTOBE32
   1137 #define htobe32(x)	bswap32((u_int32_t)(x))
   1138 #endif
   1139 #if !HAVE_DECL_HTOBE64
   1140 #define htobe64(x)	bswap64((u_int64_t)(x))
   1141 #endif
   1142 #if !HAVE_DECL_HTOLE16
   1143 #define htole16(x)	(x)
   1144 #endif
   1145 #if !HAVE_DECL_HTOLE32
   1146 #define htole32(x)	(x)
   1147 #endif
   1148 #if !HAVE_DECL_HTOLE64
   1149 #define htole64(x)	(x)
   1150 #endif
   1151 #endif
   1152 #if !HAVE_DECL_BE16TOH
   1153 #define be16toh(x)	htobe16(x)
   1154 #endif
   1155 #if !HAVE_DECL_BE32TOH
   1156 #define be32toh(x)	htobe32(x)
   1157 #endif
   1158 #if !HAVE_DECL_BE64TOH
   1159 #define be64toh(x)	htobe64(x)
   1160 #endif
   1161 #if !HAVE_DECL_LE16TOH
   1162 #define le16toh(x)	htole16(x)
   1163 #endif
   1164 #if !HAVE_DECL_LE32TOH
   1165 #define le32toh(x)	htole32(x)
   1166 #endif
   1167 #if !HAVE_DECL_LE64TOH
   1168 #define le64toh(x)	htole64(x)
   1169 #endif
   1170 
   1171 #define __GEN_ENDIAN_ENC(bits, endian) \
   1172 static void \
   1173 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
   1174 { \
   1175 	u = hto ## endian ## bits (u); \
   1176 	memcpy(dst, &u, sizeof(u)); \
   1177 }
   1178 #if !HAVE_DECL_BE16ENC
   1179 __GEN_ENDIAN_ENC(16, be)
   1180 #endif
   1181 #if !HAVE_DECL_BE32ENC
   1182 __GEN_ENDIAN_ENC(32, be)
   1183 #endif
   1184 #if !HAVE_DECL_BE64ENC
   1185 __GEN_ENDIAN_ENC(64, be)
   1186 #endif
   1187 #if !HAVE_DECL_LE16ENC
   1188 __GEN_ENDIAN_ENC(16, le)
   1189 #endif
   1190 #if !HAVE_DECL_LE32ENC
   1191 __GEN_ENDIAN_ENC(32, le)
   1192 #endif
   1193 #if !HAVE_DECL_LE64ENC
   1194 __GEN_ENDIAN_ENC(64, le)
   1195 #endif
   1196 #undef __GEN_ENDIAN_ENC
   1197 
   1198 #define __GEN_ENDIAN_DEC(bits, endian) \
   1199 static uint ## bits ## _t \
   1200 endian ## bits ## dec(const void *buf) \
   1201 { \
   1202 	uint ## bits ## _t u; \
   1203 	memcpy(&u, buf, sizeof(u)); \
   1204 	return endian ## bits ## toh (u); \
   1205 }
   1206 #if !HAVE_DECL_BE16DEC
   1207 __GEN_ENDIAN_DEC(16, be)
   1208 #endif
   1209 #if !HAVE_DECL_BE32DEC
   1210 __GEN_ENDIAN_DEC(32, be)
   1211 #endif
   1212 #if !HAVE_DECL_BE64DEC
   1213 __GEN_ENDIAN_DEC(64, be)
   1214 #endif
   1215 #if !HAVE_DECL_LE16DEC
   1216 __GEN_ENDIAN_DEC(16, le)
   1217 #endif
   1218 #if !HAVE_DECL_LE32DEC
   1219 __GEN_ENDIAN_DEC(32, le)
   1220 #endif
   1221 #if !HAVE_DECL_LE64DEC
   1222 __GEN_ENDIAN_DEC(64, le)
   1223 #endif
   1224 #undef __GEN_ENDIAN_DEC
   1225 
   1226 /* <sys/mman.h> */
   1227 
   1228 #ifndef MAP_FILE
   1229 #define MAP_FILE 0
   1230 #endif
   1231 
   1232 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
   1233 #ifndef MAP_ANON
   1234 #ifdef MAP_ANONYMOUS
   1235 #define MAP_ANON MAP_ANONYMOUS
   1236 #endif
   1237 #endif
   1238 
   1239 /* <sys/param.h> */
   1240 
   1241 #undef BIG_ENDIAN
   1242 #undef LITTLE_ENDIAN
   1243 #undef PDP_ENDIAN
   1244 #define BIG_ENDIAN 4321
   1245 #define LITTLE_ENDIAN 1234
   1246 #define PDP_ENDIAN 3412
   1247 
   1248 #undef BYTE_ORDER
   1249 #if WORDS_BIGENDIAN
   1250 #define BYTE_ORDER BIG_ENDIAN
   1251 #else
   1252 #define BYTE_ORDER LITTLE_ENDIAN
   1253 #endif
   1254 
   1255 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
   1256 #undef DEV_BSIZE
   1257 #define DEV_BSIZE (1 << 9)
   1258 
   1259 #undef MIN
   1260 #undef MAX
   1261 #define MIN(a,b) ((a) < (b) ? (a) : (b))
   1262 #define MAX(a,b) ((a) > (b) ? (a) : (b))
   1263 
   1264 #ifndef MAXBSIZE
   1265 #define MAXBSIZE (64 * 1024)
   1266 #endif
   1267 #ifndef MAXFRAG
   1268 #define MAXFRAG 8
   1269 #endif
   1270 #ifndef MAXPHYS
   1271 #define MAXPHYS (64 * 1024)
   1272 #endif
   1273 #ifndef MAXHOSTNAMELEN
   1274 #define MAXHOSTNAMELEN	256
   1275 #endif
   1276 
   1277 /* XXX needed by makefs; this should be done in a better way */
   1278 #undef btodb
   1279 #define btodb(x) ((x) << 9)
   1280 
   1281 #undef setbit
   1282 #undef clrbit
   1283 #undef isset
   1284 #undef isclr
   1285 #define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
   1286 #define	clrbit(a,i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
   1287 #define	isset(a,i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
   1288 #define	isclr(a,i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
   1289 
   1290 #ifndef powerof2
   1291 #define powerof2(x) ((((x)-1)&(x))==0)
   1292 #endif
   1293 
   1294 #undef roundup
   1295 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
   1296 
   1297 #undef roundup2
   1298 #define roundup2(x, m)	((((x) - 1) | ((m) - 1)) + 1)
   1299 
   1300 /* <sys/stat.h> */
   1301 
   1302 #ifndef ALLPERMS
   1303 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
   1304 #endif
   1305 #ifndef DEFFILEMODE
   1306 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
   1307 #endif
   1308 #ifndef S_ISTXT
   1309 #ifdef S_ISVTX
   1310 #define S_ISTXT S_ISVTX
   1311 #else
   1312 #define S_ISTXT 0
   1313 #endif
   1314 #endif
   1315 
   1316 /* Protected by _NETBSD_SOURCE otherwise. */
   1317 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
   1318 #define UF_SETTABLE     0x0000ffff
   1319 #define UF_NODUMP       0x00000001
   1320 #define UF_IMMUTABLE    0x00000002
   1321 #define UF_APPEND       0x00000004
   1322 #define UF_OPAQUE       0x00000008
   1323 #define SF_SETTABLE     0xffff0000
   1324 #define SF_ARCHIVED     0x00010000
   1325 #define SF_IMMUTABLE    0x00020000
   1326 #define SF_APPEND       0x00040000
   1327 #endif
   1328 
   1329 /* <sys/syslimits.h> */
   1330 
   1331 #ifndef LINE_MAX
   1332 #define LINE_MAX 2048
   1333 #endif
   1334 
   1335 /* <sys/time.h> */
   1336 
   1337 #ifndef timercmp
   1338 #define	timercmp(tvp, uvp, cmp)						\
   1339 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
   1340 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
   1341 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
   1342 #endif
   1343 #ifndef timeradd
   1344 #define	timeradd(tvp, uvp, vvp)						\
   1345 	do {								\
   1346 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
   1347 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
   1348 		if ((vvp)->tv_usec >= 1000000) {			\
   1349 			(vvp)->tv_sec++;				\
   1350 			(vvp)->tv_usec -= 1000000;			\
   1351 		}							\
   1352 	} while (/* CONSTCOND */ 0)
   1353 #endif
   1354 #ifndef timersub
   1355 #define	timersub(tvp, uvp, vvp)						\
   1356 	do {								\
   1357 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
   1358 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
   1359 		if ((vvp)->tv_usec < 0) {				\
   1360 			(vvp)->tv_sec--;				\
   1361 			(vvp)->tv_usec += 1000000;			\
   1362 		}							\
   1363 	} while (/* CONSTCOND */ 0)
   1364 #endif
   1365 
   1366 /* <sys/types.h> */
   1367 
   1368 #ifdef major
   1369 #undef major
   1370 #endif
   1371 #define major(x)        ((int32_t)((((x) & 0x000fff00) >>  8)))
   1372 
   1373 #ifdef minor
   1374 #undef minor
   1375 #endif
   1376 #define minor(x)        ((int32_t)((((x) & 0xfff00000) >> 12) | \
   1377                                    (((x) & 0x000000ff) >>  0)))
   1378 #ifdef makedev
   1379 #undef makedev
   1380 #endif
   1381 #define makedev(x,y)    ((dev_t)((((x) <<  8) & 0x000fff00) | \
   1382 			(((y) << 12) & 0xfff00000) | \
   1383 			(((y) <<  0) & 0x000000ff)))
   1384 #ifndef NBBY
   1385 #define NBBY 8
   1386 #endif
   1387 
   1388 #if !HAVE_U_QUAD_T
   1389 /* #define, not typedef, as quad_t exists as a struct on some systems */
   1390 #define quad_t long long
   1391 #define u_quad_t unsigned long long
   1392 #define strtoq strtoll
   1393 #define strtouq strtoull
   1394 #endif
   1395 
   1396 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
   1397 #ifdef __NetBSD__
   1398 quad_t   strtoq(const char *, char **, int);
   1399 u_quad_t strtouq(const char *, char **, int);
   1400 #endif
   1401 
   1402 #endif	/* !__NETBSD_COMPAT_DEFS_H__ */
   1403