Home | History | Annotate | Line # | Download | only in compat
compat_defs.h revision 1.71
      1 /*	$NetBSD: compat_defs.h,v 1.71 2009/02/03 05:18:42 dbj Exp $	*/
      2 
      3 #ifndef	__NETBSD_COMPAT_DEFS_H__
      4 #define	__NETBSD_COMPAT_DEFS_H__
      5 
      6 
      7 /* Work around some complete brain damage. */
      8 /*
      9  * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the
     10  * program (not the OS) should do that.  Preload <features.h> to keep any
     11  * of this crap from being pulled in, and undefine _POSIX_SOURCE.
     12  */
     13 
     14 #if defined(__linux__) && HAVE_FEATURES_H
     15 #include <features.h>
     16 #define __USE_ISOC99 1
     17 #endif
     18 
     19 /* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard
     20    defs. Other platforms may need similiar defines. */
     21 #ifdef __NetBSD__
     22 #define	_ISOC99_SOURCE
     23 #define _POSIX_SOURCE	1
     24 #define _POSIX_C_SOURCE	200112L
     25 #define _XOPEN_SOURCE 600
     26 #else
     27 #undef _POSIX_SOURCE
     28 #undef _POSIX_C_SOURCE
     29 #endif
     30 
     31 /* System headers needed for (re)definitions below. */
     32 
     33 #include <sys/types.h>
     34 #include <sys/mman.h>
     35 #include <sys/param.h>
     36 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
     37 #include <sys/time.h>
     38 #include <sys/stat.h>
     39 #include <errno.h>
     40 #include <fcntl.h>
     41 #include <limits.h>
     42 #include <paths.h>
     43 #include <stdarg.h>
     44 #include <stdio.h>
     45 #include <stdlib.h>
     46 #include <string.h>
     47 
     48 #if HAVE_SYS_CDEFS_H
     49 #include <sys/cdefs.h>
     50 #endif
     51 #if HAVE_SYS_SYSLIMITS_H
     52 #include <sys/syslimits.h>
     53 #endif
     54 #if HAVE_SYS_SYSMACROS_H
     55 /* major(), minor() on SVR4 */
     56 #include <sys/sysmacros.h>
     57 #endif
     58 #if HAVE_INTTYPES_H
     59 #include <inttypes.h>
     60 #endif
     61 #if HAVE_STDDEF_H
     62 #include <stddef.h>
     63 #endif
     64 
     65 #ifdef _NETBSD_SOURCE
     66 #error _NETBSD_SOURCE is *not* to be defined.
     67 #endif
     68 
     69 /* Need this since we can't depend on NetBSD's version to be around */
     70 #ifdef __UNCONST
     71 #undef __UNCONST
     72 #endif
     73 #define __UNCONST(a)   ((void *)(unsigned long)(const void *)(a))
     74 
     75 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
     76 struct passwd;
     77 
     78 /* We don't include <grp.h> either */
     79 struct group;
     80 
     81 /* Assume an ANSI compiler for the host. */
     82 
     83 #undef __P
     84 #define __P(x) x
     85 
     86 #ifndef __BEGIN_DECLS
     87 #define __BEGIN_DECLS
     88 #endif
     89 #ifndef __END_DECLS
     90 #define __END_DECLS
     91 #endif
     92 
     93 /* Some things usually in BSD <sys/cdefs.h>. */
     94 
     95 #ifndef __CONCAT
     96 #define	__CONCAT(x,y)	x ## y
     97 #endif
     98 #if !defined(__attribute__) && !defined(__GNUC__)
     99 #define __attribute__(x)
    100 #endif
    101 #if !defined(__packed)
    102 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
    103 #define __packed	__attribute__((__packed__))
    104 #else
    105 #define	__packed	error: no __packed for this compiler
    106 #endif
    107 #endif /* !__packed */
    108 #ifndef __RENAME
    109 #define __RENAME(x)
    110 #endif
    111 #undef __aconst
    112 #define __aconst
    113 #undef __dead
    114 #define __dead
    115 #undef __restrict
    116 #define __restrict
    117 #undef __unused
    118 #define __unused
    119 
    120 /* Dirent support. */
    121 
    122 #if HAVE_DIRENT_H
    123 # if defined(__linux__) && defined(__USE_BSD)
    124 #  undef __USE_BSD
    125 #  include <dirent.h>
    126 #  define __USE_BSD 1
    127 #  undef d_fileno
    128 # else
    129 #  include <dirent.h>
    130 #  if defined(__DARWIN_UNIX03)
    131 #   undef d_fileno
    132 #  endif
    133 # endif
    134 # define NAMLEN(dirent) (strlen((dirent)->d_name))
    135 #else
    136 # define dirent direct
    137 # define NAMLEN(dirent) ((dirent)->d_namlen)
    138 # if HAVE_SYS_NDIR_H
    139 #  include <sys/ndir.h>
    140 # endif
    141 # if HAVE_SYS_DIR_H
    142 #  include <sys/dir.h>
    143 # endif
    144 # if HAVE_NDIR_H
    145 #  include <ndir.h>
    146 # endif
    147 #endif
    148 
    149 /* Type substitutes. */
    150 
    151 #if !HAVE_ID_T
    152 typedef unsigned int id_t;
    153 #endif
    154 
    155 #if !HAVE_SOCKLEN_T
    156 typedef int socklen_t;
    157 #endif
    158 
    159 #if !HAVE_U_LONG
    160 typedef unsigned long u_long;
    161 #endif
    162 
    163 #if !HAVE_U_CHAR
    164 typedef unsigned char u_char;
    165 #endif
    166 
    167 #if !HAVE_U_INT
    168 typedef unsigned int u_int;
    169 #endif
    170 
    171 #if !HAVE_U_SHORT
    172 typedef unsigned short u_short;
    173 #endif
    174 
    175 /* Prototypes for replacement functions. */
    176 
    177 #if !HAVE_ATOLL
    178 long long int atoll(const char *);
    179 #endif
    180 
    181 #if !HAVE_ASPRINTF
    182 int asprintf(char **, const char *, ...);
    183 #endif
    184 
    185 #if !HAVE_ASNPRINTF
    186 int asnprintf(char **, size_t, const char *, ...);
    187 #endif
    188 
    189 #if !HAVE_BASENAME
    190 char *basename(char *);
    191 #endif
    192 
    193 #if !HAVE_DECL_OPTIND
    194 int getopt(int, char *const *, const char *);
    195 extern char *optarg;
    196 extern int optind, opterr, optopt;
    197 #endif
    198 
    199 #if !HAVE_DIRNAME
    200 char *dirname(char *);
    201 #endif
    202 
    203 #if !HAVE_DIRFD
    204 #if HAVE_DIR_DD_FD
    205 #define dirfd(dirp) ((dirp)->dd_fd)
    206 #elif HAVE_DIR___DD_FD
    207 #define dirfd(dirp) ((dirp)->__dd_fd)
    208 #else
    209 /*XXX: Very hacky but no other way to bring this into scope w/o defining
    210   _NETBSD_SOURCE which we're avoiding. */
    211 #ifdef __NetBSD__
    212 struct _dirdesc {
    213         int     dd_fd;          /* file descriptor associated with directory */
    214 	long    dd_loc;         /* offset in current buffer */
    215 	long    dd_size;        /* amount of data returned by getdents */
    216 	char    *dd_buf;        /* data buffer */
    217 	int     dd_len;         /* size of data buffer */
    218 	off_t   dd_seek;        /* magic cookie returned by getdents */
    219 	long    dd_rewind;      /* magic cookie for rewinding */
    220 	int     dd_flags;       /* flags for readdir */
    221 	void    *dd_lock;       /* lock for concurrent access */
    222 };
    223 #define dirfd(dirp)     (((struct _dirdesc *)dirp)->dd_fd)
    224 #else
    225 #error cannot figure out how to turn a DIR * into a fd
    226 #endif
    227 #endif
    228 #endif
    229 
    230 #if !HAVE_ERR_H
    231 void err(int, const char *, ...);
    232 void errx(int, const char *, ...);
    233 void warn(const char *, ...);
    234 void warnx(const char *, ...);
    235 #endif
    236 
    237 #if !HAVE_ESETFUNC
    238 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
    239 size_t estrlcpy(char *, const char *, size_t);
    240 size_t estrlcat(char *, const char *, size_t);
    241 char *estrdup(const char *);
    242 char *estrndup(const char *, size_t);
    243 void *ecalloc(size_t, size_t);
    244 void *emalloc(size_t);
    245 void *erealloc(void *, size_t);
    246 FILE *efopen(const char *, const char *);
    247 int easprintf(char **, const char *, ...);
    248 int evasprintf(char **, const char *, va_list);
    249 #endif
    250 
    251 #if !HAVE_FGETLN || defined(__NetBSD__)
    252 char *fgetln(FILE *, size_t *);
    253 #endif
    254 
    255 #if !HAVE_FLOCK
    256 # define LOCK_SH		0x01
    257 # define LOCK_EX		0x02
    258 # define LOCK_NB		0x04
    259 # define LOCK_UN		0x08
    260 int flock(int, int);
    261 #endif
    262 
    263 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__)
    264 # define FPARSELN_UNESCESC	0x01
    265 # define FPARSELN_UNESCCONT	0x02
    266 # define FPARSELN_UNESCCOMM	0x04
    267 # define FPARSELN_UNESCREST	0x08
    268 # define FPARSELN_UNESCALL	0x0f
    269 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
    270 #endif
    271 
    272 #if !HAVE_ISSETUGID
    273 int issetugid(void);
    274 #endif
    275 
    276 #if !HAVE_ISBLANK && !defined(isblank)
    277 #define isblank(x) ((x) == ' ' || (x) == '\t')
    278 #endif
    279 
    280 #define __nbcompat_bswap16(x)	((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
    281 
    282 #define __nbcompat_bswap32(x)	((((x) << 24) & 0xff000000) | \
    283 				 (((x) <<  8) & 0x00ff0000) | \
    284 				 (((x) >>  8) & 0x0000ff00) | \
    285 				 (((x) >> 24) & 0x000000ff))
    286 
    287 #define __nbcompat_bswap64(x)	(((u_int64_t)bswap32((x)) << 32) | \
    288 				 ((u_int64_t)bswap32((x) >> 32)))
    289 
    290 #if ! HAVE_DECL_BSWAP16
    291 #ifdef bswap16
    292 #undef bswap16
    293 #endif
    294 #define bswap16(x)	__nbcompat_bswap16(x)
    295 #endif
    296 #if ! HAVE_DECL_BSWAP32
    297 #ifdef bswap32
    298 #undef bswap32
    299 #endif
    300 #define bswap32(x)	__nbcompat_bswap32(x)
    301 #endif
    302 #if ! HAVE_DECL_BSWAP64
    303 #ifdef bswap64
    304 #undef bswap64
    305 #endif
    306 #define bswap64(x)	__nbcompat_bswap64(x)
    307 #endif
    308 
    309 #if !HAVE_MKSTEMP
    310 int mkstemp(char *);
    311 #endif
    312 
    313 #if !HAVE_MKDTEMP
    314 char *mkdtemp(char *);
    315 #endif
    316 
    317 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
    318 /* This is a prototype for the internal function defined in
    319  * src/lib/lib/stdio/gettemp.c */
    320 int __nbcompat_gettemp(char *, int *, int);
    321 #endif
    322 
    323 #if !HAVE_PREAD
    324 ssize_t pread(int, void *, size_t, off_t);
    325 #endif
    326 
    327 #if !HAVE_HEAPSORT
    328 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
    329 #endif
    330 /* Make them use our version */
    331 #  define heapsort __nbcompat_heapsort
    332 
    333 char	       *flags_to_string(unsigned long, const char *);
    334 int		string_to_flags(char **, unsigned long *, unsigned long *);
    335 
    336 /*
    337  * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
    338  * supply an implementation of one without the others -- some parts are
    339  * libc internal and this varies from system to system.
    340  *
    341  * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
    342  * XXX host system has all of these functions, all of their interfaces
    343  * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
    344  */
    345 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
    346     !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
    347 /* Make them use our version */
    348 #  define user_from_uid __nbcompat_user_from_uid
    349 #  define uid_from_user __nbcompat_uid_from_user
    350 #  define pwcache_userdb __nbcompat_pwcache_userdb
    351 #  define group_from_gid __nbcompat_group_from_gid
    352 #  define gid_from_group __nbcompat_gid_from_group
    353 #  define pwcache_groupdb __nbcompat_pwcache_groupdb
    354 #endif
    355 
    356 #if !HAVE_DECL_UID_FROM_USER
    357 int uid_from_user(const char *, uid_t *);
    358 #endif
    359 #if !HAVE_DECL_USER_FROM_UID
    360 const char *user_from_uid(uid_t, int);
    361 #endif
    362 #if !HAVE_DECL_PWCACHE_USERDB
    363 int pwcache_userdb(int (*)(int), void (*)(void),
    364                 struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
    365 #endif
    366 #if !HAVE_DECL_GID_FROM_GROUP
    367 int gid_from_group(const char *, gid_t *);
    368 #endif
    369 #if !HAVE_DECL_GROUP_FROM_GID
    370 const char *group_from_gid(gid_t, int);
    371 #endif
    372 #if !HAVE_DECL_PWCACHE_GROUPDB
    373 int pwcache_groupdb(int (*)(int), void (*)(void),
    374                 struct group * (*)(const char *), struct group * (*)(gid_t));
    375 #endif
    376 
    377 #if !HAVE_DECL_STRNDUP
    378 char		*strndup(const char *, size_t);
    379 #endif
    380 #if !HAVE_DECL_LCHFLAGS
    381 int		lchflags(const char *, unsigned long);
    382 #endif
    383 #if !HAVE_DECL_LCHMOD
    384 int		lchmod(const char *, mode_t);
    385 #endif
    386 #if !HAVE_DECL_LCHOWN
    387 int		lchown(const char *, uid_t, gid_t);
    388 #endif
    389 
    390 #if !HAVE_PWRITE
    391 ssize_t pwrite(int, const void *, size_t, off_t);
    392 #endif
    393 
    394 #if !HAVE_RAISE_DEFAULT_SIGNAL
    395 int raise_default_signal(int);
    396 #endif
    397 
    398 #if !HAVE_SETENV
    399 int setenv(const char *, const char *, int);
    400 #endif
    401 
    402 #if !HAVE_DECL_SETGROUPENT
    403 int setgroupent(int);
    404 #endif
    405 
    406 #if !HAVE_DECL_SETPASSENT
    407 int setpassent(int);
    408 #endif
    409 
    410 #if !HAVE_SETPROGNAME || defined(__NetBSD__)
    411 const char *getprogname(void);
    412 void setprogname(const char *);
    413 #endif
    414 
    415 #if !HAVE_SNPRINTF
    416 int snprintf(char *, size_t, const char *, ...);
    417 #endif
    418 
    419 #if !HAVE_STRLCAT
    420 size_t strlcat(char *, const char *, size_t);
    421 #endif
    422 
    423 #if !HAVE_STRLCPY
    424 size_t strlcpy(char *, const char *, size_t);
    425 #endif
    426 
    427 #if !HAVE_STRMODE
    428 void strmode(mode_t, char *);
    429 #endif
    430 
    431 #if !HAVE_STRNDUP
    432 char *strndup(const char *, size_t);
    433 #endif
    434 
    435 #if !HAVE_STRSEP || defined(__NetBSD__)
    436 char *strsep(char **, const char *);
    437 #endif
    438 
    439 #if !HAVE_DECL_STRSUFTOLL
    440 long long strsuftoll(const char *, const char *, long long, long long);
    441 long long strsuftollx(const char *, const char *,
    442 			long long, long long, char *, size_t);
    443 #endif
    444 
    445 #if !HAVE_STRTOLL
    446 long long strtoll(const char *, char **, int);
    447 #endif
    448 
    449 #if !HAVE_USER_FROM_UID
    450 const char *user_from_uid(uid_t, int);
    451 #endif
    452 
    453 #if !HAVE_GROUP_FROM_GID
    454 const char *group_from_gid(gid_t, int);
    455 #endif
    456 
    457 #if !HAVE_VASPRINTF
    458 int vasprintf(char **, const char *, va_list);
    459 #endif
    460 
    461 #if !HAVE_VASNPRINTF
    462 int vasnprintf(char **, size_t, const char *, va_list);
    463 #endif
    464 
    465 #if !HAVE_VSNPRINTF
    466 int vsnprintf(char *, size_t, const char *, va_list);
    467 #endif
    468 
    469 /*
    470  * getmode() and setmode() are always defined, as these function names
    471  * exist but with very different meanings on other OS's.  The compat
    472  * versions here simply accept an octal mode number; the "u+x,g-w" type
    473  * of syntax is not accepted.
    474  */
    475 
    476 #define getmode __nbcompat_getmode
    477 #define setmode __nbcompat_setmode
    478 
    479 mode_t getmode(const void *, mode_t);
    480 void *setmode(const char *);
    481 
    482 /* Eliminate assertions embedded in binaries. */
    483 
    484 #undef _DIAGASSERT
    485 #define _DIAGASSERT(x)
    486 
    487 /* Various sources use this */
    488 #undef	__RCSID
    489 #define	__RCSID(x)
    490 #undef	__SCCSID
    491 #define	__SCCSID(x)
    492 #undef	__COPYRIGHT
    493 #define	__COPYRIGHT(x)
    494 #undef	__KERNEL_RCSID
    495 #define	__KERNEL_RCSID(x,y)
    496 
    497 /* Heimdal expects this one. */
    498 
    499 #undef RCSID
    500 #define RCSID(x)
    501 
    502 /* Some definitions not available on all systems. */
    503 
    504 /* <errno.h> */
    505 
    506 #ifndef EFTYPE
    507 #define EFTYPE EIO
    508 #endif
    509 
    510 /* <fcntl.h> */
    511 
    512 #ifndef O_EXLOCK
    513 #define O_EXLOCK 0
    514 #endif
    515 #ifndef O_SHLOCK
    516 #define O_SHLOCK 0
    517 #endif
    518 
    519 /* <inttypes.h> */
    520 
    521 #if USHRT_MAX == 0xffffU		/* short is a 16-bit type */
    522 #ifndef PRId16
    523 #define PRId16 "hd"
    524 #endif
    525 #ifndef PRIi16
    526 #define PRIi16 "hi"
    527 #endif
    528 #ifndef PRIo16
    529 #define PRIo16 "ho"
    530 #endif
    531 #ifndef PRIu16
    532 #define PRIu16 "hu"
    533 #endif
    534 #ifndef PRIx16
    535 #define PRIx16 "hx"
    536 #endif
    537 #ifndef PRIX16
    538 #define PRIX16 "hX"
    539 #endif
    540 #endif					/* short is a 16-bit type */
    541 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
    542 	defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
    543 #error "Don't know how to define PRI[diouxX]16"
    544 #endif
    545 
    546 #if UINT_MAX == 0xffffffffU		/* int is a 32-bit type */
    547 #ifndef PRId32
    548 #define PRId32 "d"
    549 #endif
    550 #ifndef PRIi32
    551 #define PRIi32 "i"
    552 #endif
    553 #ifndef PRIo32
    554 #define PRIo32 "o"
    555 #endif
    556 #ifndef PRIu32
    557 #define PRIu32 "u"
    558 #endif
    559 #ifndef PRIx32
    560 #define PRIx32 "x"
    561 #endif
    562 #ifndef PRIX32
    563 #define PRIX32 "X"
    564 #endif
    565 #endif					/* int is a 32-bit type */
    566 #if ULONG_MAX == 0xffffffffU		/* long is a 32-bit type */
    567 #ifndef PRId32
    568 #define PRId32 "ld"
    569 #endif
    570 #ifndef PRIi32
    571 #define PRIi32 "li"
    572 #endif
    573 #ifndef PRIo32
    574 #define PRIo32 "lo"
    575 #endif
    576 #ifndef PRIu32
    577 #define PRIu32 "lu"
    578 #endif
    579 #ifndef PRIx32
    580 #define PRIx32 "lx"
    581 #endif
    582 #ifndef PRIX32
    583 #define PRIX32 "lX"
    584 #endif
    585 #endif					/* long is a 32-bit type */
    586 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
    587 	defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
    588 #error "Don't know how to define PRI[diouxX]32"
    589 #endif
    590 
    591 #if ULONG_MAX == 0xffffffffffffffffU	/* long is a 64-bit type */
    592 #ifndef PRId64
    593 #define PRId64 "ld"
    594 #endif
    595 #ifndef PRIi64
    596 #define PRIi64 "li"
    597 #endif
    598 #ifndef PRIo64
    599 #define PRIo64 "lo"
    600 #endif
    601 #ifndef PRIu64
    602 #define PRIu64 "lu"
    603 #endif
    604 #ifndef PRIx64
    605 #define PRIx64 "lx"
    606 #endif
    607 #ifndef PRIX64
    608 #define PRIX64 "lX"
    609 #endif
    610 #endif					/* long is a 64-bit type */
    611 #if ULLONG_MAX == 0xffffffffffffffffU	/* long long is a 64-bit type */
    612 #ifndef PRId64
    613 #define PRId64 "lld"
    614 #endif
    615 #ifndef PRIi64
    616 #define PRIi64 "lli"
    617 #endif
    618 #ifndef PRIo64
    619 #define PRIo64 "llo"
    620 #endif
    621 #ifndef PRIu64
    622 #define PRIu64 "llu"
    623 #endif
    624 #ifndef PRIx64
    625 #define PRIx64 "llx"
    626 #endif
    627 #ifndef PRIX64
    628 #define PRIX64 "llX"
    629 #endif
    630 #endif					/* long long is a 64-bit type */
    631 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
    632 	defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
    633 #error "Don't know how to define PRI[diouxX]64"
    634 #endif
    635 
    636 /* <limits.h> */
    637 
    638 #ifndef UID_MAX
    639 #define UID_MAX 32767
    640 #endif
    641 #ifndef GID_MAX
    642 #define GID_MAX UID_MAX
    643 #endif
    644 
    645 #ifndef UQUAD_MAX
    646 #define UQUAD_MAX ((u_quad_t)-1)
    647 #endif
    648 #ifndef QUAD_MAX
    649 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
    650 #endif
    651 #ifndef QUAD_MIN
    652 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
    653 #endif
    654 #ifndef ULLONG_MAX
    655 #define ULLONG_MAX ((unsigned long long)-1)
    656 #endif
    657 #ifndef LLONG_MAX
    658 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
    659 #endif
    660 #ifndef LLONG_MIN
    661 #define LLONG_MIN ((long long)(~LLONG_MAX))
    662 #endif
    663 
    664 /* <paths.h> */
    665 
    666 /* The host's _PATH_BSHELL might be broken, so override it. */
    667 #undef _PATH_BSHELL
    668 #define _PATH_BSHELL PATH_BSHELL
    669 #ifndef _PATH_DEFPATH
    670 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
    671 #endif
    672 #ifndef _PATH_DEV
    673 #define _PATH_DEV "/dev/"
    674 #endif
    675 #ifndef _PATH_DEVNULL
    676 #define _PATH_DEVNULL _PATH_DEV "null"
    677 #endif
    678 #ifndef _PATH_TMP
    679 #define _PATH_TMP "/tmp/"
    680 #endif
    681 #ifndef _PATH_DEFTAPE
    682 #define _PATH_DEFTAPE "/dev/nrst0"
    683 #endif
    684 #ifndef _PATH_VI
    685 #define _PATH_VI "/usr/bin/vi"
    686 #endif
    687 
    688 /* <stdarg.h> */
    689 
    690 #ifndef _BSD_VA_LIST_
    691 #define _BSD_VA_LIST_ va_list
    692 #endif
    693 
    694 /* <stdint.h> */
    695 
    696 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
    697 #define SIZE_MAX SIZE_T_MAX
    698 #endif
    699 
    700 #ifndef UINT8_MAX
    701 #define UINT8_MAX 0xffU
    702 #endif
    703 
    704 #ifndef UINT16_MAX
    705 #define UINT16_MAX 0xffffU
    706 #endif
    707 
    708 #ifndef UINT32_MAX
    709 #define UINT32_MAX 0xffffffffU
    710 #endif
    711 
    712 /* <stdlib.h> */
    713 
    714 #ifndef __GNUC__
    715 # if HAVE_ALLOCA_H
    716 #  include <alloca.h>
    717 # else
    718 #  ifndef alloca /* predefined by HP cc +Olibcalls */
    719 char *alloca ();
    720 #  endif
    721 # endif
    722 #endif
    723 
    724 /* avoid prototype conflicts with host */
    725 #define cgetcap __nbcompat_cgetcap
    726 #define cgetclose __nbcompat_cgetclose
    727 #define cgetent __nbcompat_cgetent
    728 #define cgetfirst __nbcompat_cgetfirst
    729 #define cgetmatch __nbcompat_cgetmatch
    730 #define cgetnext __nbcompat_cgetnext
    731 #define cgetnum __nbcompat_cgetnum
    732 #define cgetset __nbcompat_cgetset
    733 #define cgetstr __nbcompat_cgetstr
    734 #define cgetustr __nbcompat_cgetustr
    735 
    736 char	*cgetcap(char *, const char *, int);
    737 int	 cgetclose(void);
    738 int	 cgetent(char **, const char * const *, const char *);
    739 int	 cgetfirst(char **, const char * const *);
    740 int	 cgetmatch(const char *, const char *);
    741 int	 cgetnext(char **, const char * const *);
    742 int	 cgetnum(char *, const char *, long *);
    743 int	 cgetset(const char *);
    744 int	 cgetstr(char *, const char *, char **);
    745 int	 cgetustr(char *, const char *, char **);
    746 
    747 /* <sys/endian.h> */
    748 
    749 #if WORDS_BIGENDIAN
    750 #if !HAVE_DECL_HTOBE16
    751 #define htobe16(x)	(x)
    752 #endif
    753 #if !HAVE_DECL_HTOBE32
    754 #define htobe32(x)	(x)
    755 #endif
    756 #if !HAVE_DECL_HTOBE64
    757 #define htobe64(x)	(x)
    758 #endif
    759 #if !HAVE_DECL_HTOLE16
    760 #define htole16(x)	bswap16((u_int16_t)(x))
    761 #endif
    762 #if !HAVE_DECL_HTOLE32
    763 #define htole32(x)	bswap32((u_int32_t)(x))
    764 #endif
    765 #if !HAVE_DECL_HTOLE64
    766 #define htole64(x)	bswap64((u_int64_t)(x))
    767 #endif
    768 #else
    769 #if !HAVE_DECL_HTOBE16
    770 #define htobe16(x)	bswap16((u_int16_t)(x))
    771 #endif
    772 #if !HAVE_DECL_HTOBE32
    773 #define htobe32(x)	bswap32((u_int32_t)(x))
    774 #endif
    775 #if !HAVE_DECL_HTOBE64
    776 #define htobe64(x)	bswap64((u_int64_t)(x))
    777 #endif
    778 #if !HAVE_DECL_HTOLE16
    779 #define htole16(x)	(x)
    780 #endif
    781 #if !HAVE_DECL_HTOLE32
    782 #define htole32(x)	(x)
    783 #endif
    784 #if !HAVE_DECL_HTOLE64
    785 #define htole64(x)	(x)
    786 #endif
    787 #endif
    788 #if !HAVE_DECL_BE16TOH
    789 #define be16toh(x)	htobe16(x)
    790 #endif
    791 #if !HAVE_DECL_BE32TOH
    792 #define be32toh(x)	htobe32(x)
    793 #endif
    794 #if !HAVE_DECL_BE64TOH
    795 #define be64toh(x)	htobe64(x)
    796 #endif
    797 #if !HAVE_DECL_LE16TOH
    798 #define le16toh(x)	htole16(x)
    799 #endif
    800 #if !HAVE_DECL_LE32TOH
    801 #define le32toh(x)	htole32(x)
    802 #endif
    803 #if !HAVE_DECL_LE64TOH
    804 #define le64toh(x)	htole64(x)
    805 #endif
    806 
    807 #define __GEN_ENDIAN_ENC(bits, endian) \
    808 static void \
    809 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
    810 { \
    811 	u = hto ## endian ## bits (u); \
    812 	memcpy(dst, &u, sizeof(u)); \
    813 }
    814 #if !HAVE_DECL_BE16ENC
    815 __GEN_ENDIAN_ENC(16, be)
    816 #endif
    817 #if !HAVE_DECL_BE32ENC
    818 __GEN_ENDIAN_ENC(32, be)
    819 #endif
    820 #if !HAVE_DECL_BE64ENC
    821 __GEN_ENDIAN_ENC(64, be)
    822 #endif
    823 #if !HAVE_DECL_LE16ENC
    824 __GEN_ENDIAN_ENC(16, le)
    825 #endif
    826 #if !HAVE_DECL_LE32ENC
    827 __GEN_ENDIAN_ENC(32, le)
    828 #endif
    829 #if !HAVE_DECL_LE64ENC
    830 __GEN_ENDIAN_ENC(64, le)
    831 #endif
    832 #undef __GEN_ENDIAN_ENC
    833 
    834 #define __GEN_ENDIAN_DEC(bits, endian) \
    835 static uint ## bits ## _t \
    836 endian ## bits ## dec(const void *buf) \
    837 { \
    838 	uint ## bits ## _t u; \
    839 	memcpy(&u, buf, sizeof(u)); \
    840 	return endian ## bits ## toh (u); \
    841 }
    842 #if !HAVE_DECL_BE16DEC
    843 __GEN_ENDIAN_DEC(16, be)
    844 #endif
    845 #if !HAVE_DECL_BE32DEC
    846 __GEN_ENDIAN_DEC(32, be)
    847 #endif
    848 #if !HAVE_DECL_BE64DEC
    849 __GEN_ENDIAN_DEC(64, be)
    850 #endif
    851 #if !HAVE_DECL_LE16DEC
    852 __GEN_ENDIAN_DEC(16, le)
    853 #endif
    854 #if !HAVE_DECL_LE32DEC
    855 __GEN_ENDIAN_DEC(32, le)
    856 #endif
    857 #if !HAVE_DECL_LE64DEC
    858 __GEN_ENDIAN_DEC(64, le)
    859 #endif
    860 #undef __GEN_ENDIAN_DEC
    861 
    862 /* <sys/mman.h> */
    863 
    864 #ifndef MAP_FILE
    865 #define MAP_FILE 0
    866 #endif
    867 
    868 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
    869 #ifndef MAP_ANON
    870 #ifdef MAP_ANONYMOUS
    871 #define MAP_ANON MAP_ANONYMOUS
    872 #endif
    873 #endif
    874 
    875 /* <sys/param.h> */
    876 
    877 #undef BIG_ENDIAN
    878 #undef LITTLE_ENDIAN
    879 #define BIG_ENDIAN 4321
    880 #define LITTLE_ENDIAN 1234
    881 
    882 #undef BYTE_ORDER
    883 #if WORDS_BIGENDIAN
    884 #define BYTE_ORDER BIG_ENDIAN
    885 #else
    886 #define BYTE_ORDER LITTLE_ENDIAN
    887 #endif
    888 
    889 #ifndef DEV_BSIZE
    890 #define DEV_BSIZE (1 << 9)
    891 #endif
    892 
    893 #undef MIN
    894 #undef MAX
    895 #define MIN(a,b) ((a) < (b) ? (a) : (b))
    896 #define MAX(a,b) ((a) > (b) ? (a) : (b))
    897 
    898 #ifndef MAXBSIZE
    899 #define MAXBSIZE (64 * 1024)
    900 #endif
    901 #ifndef MAXFRAG
    902 #define MAXFRAG 8
    903 #endif
    904 #ifndef MAXPHYS
    905 #define MAXPHYS (64 * 1024)
    906 #endif
    907 
    908 /* XXX needed by makefs; this should be done in a better way */
    909 #undef btodb
    910 #define btodb(x) ((x) << 9)
    911 
    912 #undef setbit
    913 #undef clrbit
    914 #undef isset
    915 #undef isclr
    916 #define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
    917 #define	clrbit(a,i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
    918 #define	isset(a,i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
    919 #define	isclr(a,i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
    920 
    921 #ifndef powerof2
    922 #define powerof2(x) ((((x)-1)&(x))==0)
    923 #endif
    924 
    925 #undef roundup
    926 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
    927 
    928 /* <sys/stat.h> */
    929 
    930 #ifndef ALLPERMS
    931 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
    932 #endif
    933 #ifndef DEFFILEMODE
    934 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
    935 #endif
    936 #ifndef S_ISTXT
    937 #ifdef S_ISVTX
    938 #define S_ISTXT S_ISVTX
    939 #else
    940 #define S_ISTXT 0
    941 #endif
    942 #endif
    943 
    944 /* Protected by _NETBSD_SOURCE otherwise. */
    945 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
    946 #define UF_SETTABLE     0x0000ffff
    947 #define UF_NODUMP       0x00000001
    948 #define UF_IMMUTABLE    0x00000002
    949 #define UF_APPEND       0x00000004
    950 #define UF_OPAQUE       0x00000008
    951 #define SF_SETTABLE     0xffff0000
    952 #define SF_ARCHIVED     0x00010000
    953 #define SF_IMMUTABLE    0x00020000
    954 #define SF_APPEND       0x00040000
    955 #endif
    956 
    957 /* <sys/syslimits.h> */
    958 
    959 #ifndef LINE_MAX
    960 #define LINE_MAX 2048
    961 #endif
    962 
    963 /* <sys/time.h> */
    964 
    965 #ifndef timercmp
    966 #define	timercmp(tvp, uvp, cmp)						\
    967 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
    968 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
    969 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
    970 #endif
    971 #ifndef timeradd
    972 #define	timeradd(tvp, uvp, vvp)						\
    973 	do {								\
    974 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
    975 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
    976 		if ((vvp)->tv_usec >= 1000000) {			\
    977 			(vvp)->tv_sec++;				\
    978 			(vvp)->tv_usec -= 1000000;			\
    979 		}							\
    980 	} while (/* CONSTCOND */ 0)
    981 #endif
    982 #ifndef timersub
    983 #define	timersub(tvp, uvp, vvp)						\
    984 	do {								\
    985 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
    986 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
    987 		if ((vvp)->tv_usec < 0) {				\
    988 			(vvp)->tv_sec--;				\
    989 			(vvp)->tv_usec += 1000000;			\
    990 		}							\
    991 	} while (/* CONSTCOND */ 0)
    992 #endif
    993 
    994 /* <sys/types.h> */
    995 
    996 #ifdef major
    997 #undef major
    998 #endif
    999 #define major(x)        ((int32_t)((((x) & 0x000fff00) >>  8)))
   1000 
   1001 #ifdef minor
   1002 #undef minor
   1003 #endif
   1004 #define minor(x)        ((int32_t)((((x) & 0xfff00000) >> 12) | \
   1005                                    (((x) & 0x000000ff) >>  0)))
   1006 #ifdef makedev
   1007 #undef makedev
   1008 #endif
   1009 #define makedev(x,y)    ((dev_t)((((x) <<  8) & 0x000fff00) | \
   1010 			(((y) << 12) & 0xfff00000) | \
   1011 			(((y) <<  0) & 0x000000ff)))
   1012 #ifndef NBBY
   1013 #define NBBY 8
   1014 #endif
   1015 
   1016 #if !HAVE_U_QUAD_T
   1017 /* #define, not typedef, as quad_t exists as a struct on some systems */
   1018 #define quad_t long long
   1019 #define u_quad_t unsigned long long
   1020 #define strtoq strtoll
   1021 #define strtouq strtoull
   1022 #endif
   1023 
   1024 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
   1025 #ifdef __NetBSD__
   1026 quad_t   strtoq __P((const char *, char **, int));
   1027 u_quad_t strtouq __P((const char *, char **, int));
   1028 #endif
   1029 
   1030 #endif	/* !__NETBSD_COMPAT_DEFS_H__ */
   1031