Home | History | Annotate | Line # | Download | only in compat
compat_defs.h revision 1.126
      1 /*	$NetBSD: compat_defs.h,v 1.126 2025/09/18 20:19:26 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 /*
    664  * getmode() and setmode() are always defined, as these function names
    665  * exist but with very different meanings on other OS's.  The compat
    666  * versions here simply accept an octal mode number; the "u+x,g-w" type
    667  * of syntax is not accepted.
    668  */
    669 
    670 #define getmode __nbcompat_getmode
    671 #define setmode __nbcompat_setmode
    672 
    673 mode_t getmode(const void *, mode_t);
    674 void *setmode(const char *);
    675 
    676 /* Eliminate assertions embedded in binaries. */
    677 
    678 #undef _DIAGASSERT
    679 #define _DIAGASSERT(x)
    680 
    681 /* Various sources use this */
    682 #undef	__RCSID
    683 #define	__RCSID(x) struct XXXNETBSD_RCSID
    684 #undef	__SCCSID
    685 #define	__SCCSID(x)
    686 #undef	__COPYRIGHT
    687 #define	__COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
    688 #undef	__KERNEL_RCSID
    689 #define	__KERNEL_RCSID(x,y)
    690 
    691 /* Heimdal expects this one. */
    692 
    693 #undef RCSID
    694 #define RCSID(x)
    695 
    696 /* Some definitions not available on all systems. */
    697 
    698 #ifndef __inline
    699 #define __inline inline
    700 #endif
    701 
    702 /* <errno.h> */
    703 
    704 #ifndef EFTYPE
    705 #define EFTYPE EIO
    706 #endif
    707 
    708 /* <fcntl.h> */
    709 
    710 #ifndef O_EXLOCK
    711 #define O_EXLOCK 0
    712 #endif
    713 #ifndef O_SHLOCK
    714 #define O_SHLOCK 0
    715 #endif
    716 #ifndef O_CLOEXEC
    717 #define O_CLOEXEC 0
    718 #endif
    719 
    720 /* <inttypes.h> */
    721 
    722 #if UCHAR_MAX == 0xffU			/* char is an 8-bit type */
    723 #ifndef PRId8
    724 #define PRId8 "hhd"
    725 #endif
    726 #ifndef PRIi8
    727 #define PRIi8 "hhi"
    728 #endif
    729 #ifndef PRIo8
    730 #define PRIo8 "hho"
    731 #endif
    732 #ifndef PRIu8
    733 #define PRIu8 "hhu"
    734 #endif
    735 #ifndef PRIx8
    736 #define PRIx8 "hhx"
    737 #endif
    738 #ifndef PRIX8
    739 #define PRIX8 "hhX"
    740 #endif
    741 #ifndef SCNd8
    742 #define SCNd8 "hhd"
    743 #endif
    744 #ifndef SCNi8
    745 #define SCNi8 "hhi"
    746 #endif
    747 #ifndef SCNo8
    748 #define SCNo8 "hho"
    749 #endif
    750 #ifndef SCNu8
    751 #define SCNu8 "hhu"
    752 #endif
    753 #ifndef SCNx8
    754 #define SCNx8 "hhx"
    755 #endif
    756 #ifndef SCNX8
    757 #define SCNX8 "hhX"
    758 #endif
    759 #endif					/* char is an 8-bit type */
    760 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
    761 	defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
    762 #error "Don't know how to define PRI[diouxX]8"
    763 #endif
    764 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
    765 	defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
    766 #error "Don't know how to define SCN[diouxX]8"
    767 #endif
    768 
    769 #if USHRT_MAX == 0xffffU		/* short is a 16-bit type */
    770 #ifndef PRId16
    771 #define PRId16 "hd"
    772 #endif
    773 #ifndef PRIi16
    774 #define PRIi16 "hi"
    775 #endif
    776 #ifndef PRIo16
    777 #define PRIo16 "ho"
    778 #endif
    779 #ifndef PRIu16
    780 #define PRIu16 "hu"
    781 #endif
    782 #ifndef PRIx16
    783 #define PRIx16 "hx"
    784 #endif
    785 #ifndef PRIX16
    786 #define PRIX16 "hX"
    787 #endif
    788 #ifndef SCNd16
    789 #define SCNd16 "hd"
    790 #endif
    791 #ifndef SCNi16
    792 #define SCNi16 "hi"
    793 #endif
    794 #ifndef SCNo16
    795 #define SCNo16 "ho"
    796 #endif
    797 #ifndef SCNu16
    798 #define SCNu16 "hu"
    799 #endif
    800 #ifndef SCNx16
    801 #define SCNx16 "hx"
    802 #endif
    803 #ifndef SCNX16
    804 #define SCNX16 "hX"
    805 #endif
    806 #endif					/* short is a 16-bit type */
    807 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
    808 	defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
    809 #error "Don't know how to define PRI[diouxX]16"
    810 #endif
    811 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
    812 	defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
    813 #error "Don't know how to define SCN[diouxX]16"
    814 #endif
    815 
    816 #if UINT_MAX == 0xffffffffU		/* int is a 32-bit type */
    817 #ifndef PRId32
    818 #define PRId32 "d"
    819 #endif
    820 #ifndef PRIi32
    821 #define PRIi32 "i"
    822 #endif
    823 #ifndef PRIo32
    824 #define PRIo32 "o"
    825 #endif
    826 #ifndef PRIu32
    827 #define PRIu32 "u"
    828 #endif
    829 #ifndef PRIx32
    830 #define PRIx32 "x"
    831 #endif
    832 #ifndef PRIX32
    833 #define PRIX32 "X"
    834 #endif
    835 #ifndef SCNd32
    836 #define SCNd32 "d"
    837 #endif
    838 #ifndef SCNi32
    839 #define SCNi32 "i"
    840 #endif
    841 #ifndef SCNo32
    842 #define SCNo32 "o"
    843 #endif
    844 #ifndef SCNu32
    845 #define SCNu32 "u"
    846 #endif
    847 #ifndef SCNx32
    848 #define SCNx32 "x"
    849 #endif
    850 #ifndef SCNX32
    851 #define SCNX32 "X"
    852 #endif
    853 #endif					/* int is a 32-bit type */
    854 #if ULONG_MAX == 0xffffffffU		/* long is a 32-bit type */
    855 #ifndef PRId32
    856 #define PRId32 "ld"
    857 #endif
    858 #ifndef PRIi32
    859 #define PRIi32 "li"
    860 #endif
    861 #ifndef PRIo32
    862 #define PRIo32 "lo"
    863 #endif
    864 #ifndef PRIu32
    865 #define PRIu32 "lu"
    866 #endif
    867 #ifndef PRIx32
    868 #define PRIx32 "lx"
    869 #endif
    870 #ifndef PRIX32
    871 #define PRIX32 "lX"
    872 #endif
    873 #ifndef SCNd32
    874 #define SCNd32 "ld"
    875 #endif
    876 #ifndef SCNi32
    877 #define SCNi32 "li"
    878 #endif
    879 #ifndef SCNo32
    880 #define SCNo32 "lo"
    881 #endif
    882 #ifndef SCNu32
    883 #define SCNu32 "lu"
    884 #endif
    885 #ifndef SCNx32
    886 #define SCNx32 "lx"
    887 #endif
    888 #ifndef SCNX32
    889 #define SCNX32 "lX"
    890 #endif
    891 #endif					/* long is a 32-bit type */
    892 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
    893 	defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
    894 #error "Don't know how to define PRI[diouxX]32"
    895 #endif
    896 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
    897 	defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
    898 #error "Don't know how to define SCN[diouxX]32"
    899 #endif
    900 
    901 #if ULONG_MAX == 0xffffffffffffffffU	/* long is a 64-bit type */
    902 #ifndef PRId64
    903 #define PRId64 "ld"
    904 #endif
    905 #ifndef PRIi64
    906 #define PRIi64 "li"
    907 #endif
    908 #ifndef PRIo64
    909 #define PRIo64 "lo"
    910 #endif
    911 #ifndef PRIu64
    912 #define PRIu64 "lu"
    913 #endif
    914 #ifndef PRIx64
    915 #define PRIx64 "lx"
    916 #endif
    917 #ifndef PRIX64
    918 #define PRIX64 "lX"
    919 #endif
    920 #ifndef SCNd64
    921 #define SCNd64 "ld"
    922 #endif
    923 #ifndef SCNi64
    924 #define SCNi64 "li"
    925 #endif
    926 #ifndef SCNo64
    927 #define SCNo64 "lo"
    928 #endif
    929 #ifndef SCNu64
    930 #define SCNu64 "lu"
    931 #endif
    932 #ifndef SCNx64
    933 #define SCNx64 "lx"
    934 #endif
    935 #ifndef SCNX64
    936 #define SCNX64 "lX"
    937 #endif
    938 #endif					/* long is a 64-bit type */
    939 #if ULLONG_MAX == 0xffffffffffffffffU	/* long long is a 64-bit type */
    940 #ifndef PRId64
    941 #define PRId64 "lld"
    942 #endif
    943 #ifndef PRIi64
    944 #define PRIi64 "lli"
    945 #endif
    946 #ifndef PRIo64
    947 #define PRIo64 "llo"
    948 #endif
    949 #ifndef PRIu64
    950 #define PRIu64 "llu"
    951 #endif
    952 #ifndef PRIx64
    953 #define PRIx64 "llx"
    954 #endif
    955 #ifndef PRIX64
    956 #define PRIX64 "llX"
    957 #endif
    958 #ifndef SCNd64
    959 #define SCNd64 "lld"
    960 #endif
    961 #ifndef SCNi64
    962 #define SCNi64 "lli"
    963 #endif
    964 #ifndef SCNo64
    965 #define SCNo64 "llo"
    966 #endif
    967 #ifndef SCNu64
    968 #define SCNu64 "llu"
    969 #endif
    970 #ifndef SCNx64
    971 #define SCNx64 "llx"
    972 #endif
    973 #ifndef SCNX64
    974 #define SCNX64 "llX"
    975 #endif
    976 #endif					/* long long is a 64-bit type */
    977 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
    978 	defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
    979 #error "Don't know how to define PRI[diouxX]64"
    980 #endif
    981 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
    982 	defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
    983 #error "Don't know how to define SCN[diouxX]64"
    984 #endif
    985 
    986 /* <limits.h> */
    987 
    988 #ifndef UID_MAX
    989 #define UID_MAX 32767
    990 #endif
    991 #ifndef GID_MAX
    992 #define GID_MAX UID_MAX
    993 #endif
    994 
    995 #ifndef UQUAD_MAX
    996 #define UQUAD_MAX ((u_quad_t)-1)
    997 #endif
    998 #ifndef QUAD_MAX
    999 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
   1000 #endif
   1001 #ifndef QUAD_MIN
   1002 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
   1003 #endif
   1004 #ifndef ULLONG_MAX
   1005 #define ULLONG_MAX ((unsigned long long)-1)
   1006 #endif
   1007 #ifndef LLONG_MAX
   1008 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
   1009 #endif
   1010 #ifndef LLONG_MIN
   1011 #define LLONG_MIN ((long long)(~LLONG_MAX))
   1012 #endif
   1013 
   1014 #ifndef MAXPATHLEN
   1015 #define MAXPATHLEN	4096
   1016 #endif
   1017 
   1018 #ifndef NAME_MAX
   1019 #ifdef _XOPEN_NAME_MAX
   1020 #define NAME_MAX _XOPEN_NAME_MAX
   1021 #else
   1022 #error "Both NAME_MAX and _XOPEN_NAME_MAX are not defined"
   1023 #endif
   1024 #endif
   1025 
   1026 #ifndef PATH_MAX
   1027 #define PATH_MAX	MAXPATHLEN
   1028 #endif
   1029 
   1030 /* <paths.h> */
   1031 
   1032 /* The host's _PATH_BSHELL might be broken, so override it. */
   1033 #undef _PATH_BSHELL
   1034 #define _PATH_BSHELL PATH_BSHELL
   1035 #ifndef _PATH_DEFPATH
   1036 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
   1037 #endif
   1038 #ifndef _PATH_DEV
   1039 #define _PATH_DEV "/dev/"
   1040 #endif
   1041 #ifndef _PATH_DEVNULL
   1042 #define _PATH_DEVNULL _PATH_DEV "null"
   1043 #endif
   1044 #ifndef _PATH_TMP
   1045 #define _PATH_TMP "/tmp/"
   1046 #endif
   1047 #ifndef _PATH_DEFTAPE
   1048 #define _PATH_DEFTAPE "/dev/nrst0"
   1049 #endif
   1050 #ifndef _PATH_VI
   1051 #define _PATH_VI "/usr/bin/vi"
   1052 #endif
   1053 
   1054 /* <stdint.h> */
   1055 
   1056 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
   1057 #define SIZE_MAX SIZE_T_MAX
   1058 #endif
   1059 
   1060 #ifndef UINT8_MAX
   1061 #define UINT8_MAX 0xffU
   1062 #endif
   1063 
   1064 #ifndef UINT16_MAX
   1065 #define UINT16_MAX 0xffffU
   1066 #endif
   1067 
   1068 #ifndef UINT32_MAX
   1069 #define UINT32_MAX 0xffffffffU
   1070 #endif
   1071 
   1072 /* <stdlib.h> */
   1073 
   1074 #ifndef __GNUC__
   1075 # if HAVE_ALLOCA_H
   1076 #  include <alloca.h>
   1077 # else
   1078 #  ifndef alloca /* predefined by HP cc +Olibcalls */
   1079 char *alloca ();
   1080 #  endif
   1081 # endif
   1082 #endif
   1083 
   1084 /* avoid prototype conflicts with host */
   1085 #define cgetcap __nbcompat_cgetcap
   1086 #define cgetclose __nbcompat_cgetclose
   1087 #define cgetent __nbcompat_cgetent
   1088 #define cgetfirst __nbcompat_cgetfirst
   1089 #define cgetmatch __nbcompat_cgetmatch
   1090 #define cgetnext __nbcompat_cgetnext
   1091 #define cgetnum __nbcompat_cgetnum
   1092 #define cgetset __nbcompat_cgetset
   1093 #define cgetstr __nbcompat_cgetstr
   1094 #define cgetustr __nbcompat_cgetustr
   1095 
   1096 char	*cgetcap(char *, const char *, int);
   1097 int	 cgetclose(void);
   1098 int	 cgetent(char **, const char * const *, const char *);
   1099 int	 cgetfirst(char **, const char * const *);
   1100 int	 cgetmatch(const char *, const char *);
   1101 int	 cgetnext(char **, const char * const *);
   1102 int	 cgetnum(char *, const char *, long *);
   1103 int	 cgetset(const char *);
   1104 int	 cgetstr(char *, const char *, char **);
   1105 int	 cgetustr(char *, const char *, char **);
   1106 
   1107 /* <sys/endian.h> */
   1108 
   1109 #if WORDS_BIGENDIAN
   1110 #if !HAVE_DECL_HTOBE16
   1111 #define htobe16(x)	(x)
   1112 #endif
   1113 #if !HAVE_DECL_HTOBE32
   1114 #define htobe32(x)	(x)
   1115 #endif
   1116 #if !HAVE_DECL_HTOBE64
   1117 #define htobe64(x)	(x)
   1118 #endif
   1119 #if !HAVE_DECL_HTOLE16
   1120 #define htole16(x)	bswap16((u_int16_t)(x))
   1121 #endif
   1122 #if !HAVE_DECL_HTOLE32
   1123 #define htole32(x)	bswap32((u_int32_t)(x))
   1124 #endif
   1125 #if !HAVE_DECL_HTOLE64
   1126 #define htole64(x)	bswap64((u_int64_t)(x))
   1127 #endif
   1128 #else
   1129 #if !HAVE_DECL_HTOBE16
   1130 #define htobe16(x)	bswap16((u_int16_t)(x))
   1131 #endif
   1132 #if !HAVE_DECL_HTOBE32
   1133 #define htobe32(x)	bswap32((u_int32_t)(x))
   1134 #endif
   1135 #if !HAVE_DECL_HTOBE64
   1136 #define htobe64(x)	bswap64((u_int64_t)(x))
   1137 #endif
   1138 #if !HAVE_DECL_HTOLE16
   1139 #define htole16(x)	(x)
   1140 #endif
   1141 #if !HAVE_DECL_HTOLE32
   1142 #define htole32(x)	(x)
   1143 #endif
   1144 #if !HAVE_DECL_HTOLE64
   1145 #define htole64(x)	(x)
   1146 #endif
   1147 #endif
   1148 #if !HAVE_DECL_BE16TOH
   1149 #define be16toh(x)	htobe16(x)
   1150 #endif
   1151 #if !HAVE_DECL_BE32TOH
   1152 #define be32toh(x)	htobe32(x)
   1153 #endif
   1154 #if !HAVE_DECL_BE64TOH
   1155 #define be64toh(x)	htobe64(x)
   1156 #endif
   1157 #if !HAVE_DECL_LE16TOH
   1158 #define le16toh(x)	htole16(x)
   1159 #endif
   1160 #if !HAVE_DECL_LE32TOH
   1161 #define le32toh(x)	htole32(x)
   1162 #endif
   1163 #if !HAVE_DECL_LE64TOH
   1164 #define le64toh(x)	htole64(x)
   1165 #endif
   1166 
   1167 #define __GEN_ENDIAN_ENC(bits, endian) \
   1168 static void \
   1169 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
   1170 { \
   1171 	u = hto ## endian ## bits (u); \
   1172 	memcpy(dst, &u, sizeof(u)); \
   1173 }
   1174 #if !HAVE_DECL_BE16ENC
   1175 __GEN_ENDIAN_ENC(16, be)
   1176 #endif
   1177 #if !HAVE_DECL_BE32ENC
   1178 __GEN_ENDIAN_ENC(32, be)
   1179 #endif
   1180 #if !HAVE_DECL_BE64ENC
   1181 __GEN_ENDIAN_ENC(64, be)
   1182 #endif
   1183 #if !HAVE_DECL_LE16ENC
   1184 __GEN_ENDIAN_ENC(16, le)
   1185 #endif
   1186 #if !HAVE_DECL_LE32ENC
   1187 __GEN_ENDIAN_ENC(32, le)
   1188 #endif
   1189 #if !HAVE_DECL_LE64ENC
   1190 __GEN_ENDIAN_ENC(64, le)
   1191 #endif
   1192 #undef __GEN_ENDIAN_ENC
   1193 
   1194 #define __GEN_ENDIAN_DEC(bits, endian) \
   1195 static uint ## bits ## _t \
   1196 endian ## bits ## dec(const void *buf) \
   1197 { \
   1198 	uint ## bits ## _t u; \
   1199 	memcpy(&u, buf, sizeof(u)); \
   1200 	return endian ## bits ## toh (u); \
   1201 }
   1202 #if !HAVE_DECL_BE16DEC
   1203 __GEN_ENDIAN_DEC(16, be)
   1204 #endif
   1205 #if !HAVE_DECL_BE32DEC
   1206 __GEN_ENDIAN_DEC(32, be)
   1207 #endif
   1208 #if !HAVE_DECL_BE64DEC
   1209 __GEN_ENDIAN_DEC(64, be)
   1210 #endif
   1211 #if !HAVE_DECL_LE16DEC
   1212 __GEN_ENDIAN_DEC(16, le)
   1213 #endif
   1214 #if !HAVE_DECL_LE32DEC
   1215 __GEN_ENDIAN_DEC(32, le)
   1216 #endif
   1217 #if !HAVE_DECL_LE64DEC
   1218 __GEN_ENDIAN_DEC(64, le)
   1219 #endif
   1220 #undef __GEN_ENDIAN_DEC
   1221 
   1222 /* <sys/mman.h> */
   1223 
   1224 #ifndef MAP_FILE
   1225 #define MAP_FILE 0
   1226 #endif
   1227 
   1228 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
   1229 #ifndef MAP_ANON
   1230 #ifdef MAP_ANONYMOUS
   1231 #define MAP_ANON MAP_ANONYMOUS
   1232 #endif
   1233 #endif
   1234 
   1235 /* <sys/param.h> */
   1236 
   1237 #undef BIG_ENDIAN
   1238 #undef LITTLE_ENDIAN
   1239 #undef PDP_ENDIAN
   1240 #define BIG_ENDIAN 4321
   1241 #define LITTLE_ENDIAN 1234
   1242 #define PDP_ENDIAN 3412
   1243 
   1244 #undef BYTE_ORDER
   1245 #if WORDS_BIGENDIAN
   1246 #define BYTE_ORDER BIG_ENDIAN
   1247 #else
   1248 #define BYTE_ORDER LITTLE_ENDIAN
   1249 #endif
   1250 
   1251 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
   1252 #undef DEV_BSIZE
   1253 #define DEV_BSIZE (1 << 9)
   1254 
   1255 #undef MIN
   1256 #undef MAX
   1257 #define MIN(a,b) ((a) < (b) ? (a) : (b))
   1258 #define MAX(a,b) ((a) > (b) ? (a) : (b))
   1259 
   1260 #ifndef MAXBSIZE
   1261 #define MAXBSIZE (64 * 1024)
   1262 #endif
   1263 #ifndef MAXFRAG
   1264 #define MAXFRAG 8
   1265 #endif
   1266 #ifndef MAXPHYS
   1267 #define MAXPHYS (64 * 1024)
   1268 #endif
   1269 #ifndef MAXHOSTNAMELEN
   1270 #define MAXHOSTNAMELEN	256
   1271 #endif
   1272 
   1273 /* XXX needed by makefs; this should be done in a better way */
   1274 #undef btodb
   1275 #define btodb(x) ((x) << 9)
   1276 
   1277 #undef setbit
   1278 #undef clrbit
   1279 #undef isset
   1280 #undef isclr
   1281 #define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
   1282 #define	clrbit(a,i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
   1283 #define	isset(a,i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
   1284 #define	isclr(a,i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
   1285 
   1286 #ifndef powerof2
   1287 #define powerof2(x) ((((x)-1)&(x))==0)
   1288 #endif
   1289 
   1290 #undef roundup
   1291 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
   1292 
   1293 #undef roundup2
   1294 #define roundup2(x, m)	((((x) - 1) | ((m) - 1)) + 1)
   1295 
   1296 /* <sys/stat.h> */
   1297 
   1298 #ifndef ALLPERMS
   1299 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
   1300 #endif
   1301 #ifndef DEFFILEMODE
   1302 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
   1303 #endif
   1304 #ifndef S_ISTXT
   1305 #ifdef S_ISVTX
   1306 #define S_ISTXT S_ISVTX
   1307 #else
   1308 #define S_ISTXT 0
   1309 #endif
   1310 #endif
   1311 
   1312 /* Protected by _NETBSD_SOURCE otherwise. */
   1313 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
   1314 #define UF_SETTABLE     0x0000ffff
   1315 #define UF_NODUMP       0x00000001
   1316 #define UF_IMMUTABLE    0x00000002
   1317 #define UF_APPEND       0x00000004
   1318 #define UF_OPAQUE       0x00000008
   1319 #define SF_SETTABLE     0xffff0000
   1320 #define SF_ARCHIVED     0x00010000
   1321 #define SF_IMMUTABLE    0x00020000
   1322 #define SF_APPEND       0x00040000
   1323 #endif
   1324 
   1325 /* <sys/syslimits.h> */
   1326 
   1327 #ifndef LINE_MAX
   1328 #define LINE_MAX 2048
   1329 #endif
   1330 
   1331 /* <sys/time.h> */
   1332 
   1333 #ifndef timercmp
   1334 #define	timercmp(tvp, uvp, cmp)						\
   1335 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
   1336 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
   1337 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
   1338 #endif
   1339 #ifndef timeradd
   1340 #define	timeradd(tvp, uvp, vvp)						\
   1341 	do {								\
   1342 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
   1343 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
   1344 		if ((vvp)->tv_usec >= 1000000) {			\
   1345 			(vvp)->tv_sec++;				\
   1346 			(vvp)->tv_usec -= 1000000;			\
   1347 		}							\
   1348 	} while (/* CONSTCOND */ 0)
   1349 #endif
   1350 #ifndef timersub
   1351 #define	timersub(tvp, uvp, vvp)						\
   1352 	do {								\
   1353 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
   1354 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
   1355 		if ((vvp)->tv_usec < 0) {				\
   1356 			(vvp)->tv_sec--;				\
   1357 			(vvp)->tv_usec += 1000000;			\
   1358 		}							\
   1359 	} while (/* CONSTCOND */ 0)
   1360 #endif
   1361 
   1362 /* <sys/types.h> */
   1363 
   1364 #ifdef major
   1365 #undef major
   1366 #endif
   1367 #define major(x)        ((int32_t)((((x) & 0x000fff00) >>  8)))
   1368 
   1369 #ifdef minor
   1370 #undef minor
   1371 #endif
   1372 #define minor(x)        ((int32_t)((((x) & 0xfff00000) >> 12) | \
   1373                                    (((x) & 0x000000ff) >>  0)))
   1374 #ifdef makedev
   1375 #undef makedev
   1376 #endif
   1377 #define makedev(x,y)    ((dev_t)((((x) <<  8) & 0x000fff00) | \
   1378 			(((y) << 12) & 0xfff00000) | \
   1379 			(((y) <<  0) & 0x000000ff)))
   1380 #ifndef NBBY
   1381 #define NBBY 8
   1382 #endif
   1383 
   1384 #if !HAVE_U_QUAD_T
   1385 /* #define, not typedef, as quad_t exists as a struct on some systems */
   1386 #define quad_t long long
   1387 #define u_quad_t unsigned long long
   1388 #define strtoq strtoll
   1389 #define strtouq strtoull
   1390 #endif
   1391 
   1392 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
   1393 #ifdef __NetBSD__
   1394 quad_t   strtoq(const char *, char **, int);
   1395 u_quad_t strtouq(const char *, char **, int);
   1396 #endif
   1397 
   1398 #endif	/* !__NETBSD_COMPAT_DEFS_H__ */
   1399