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