Home | History | Annotate | Line # | Download | only in compat
compat_defs.h revision 1.40
      1 /*	$NetBSD: compat_defs.h,v 1.40 2004/06/21 22:13:32 jmc Exp $	*/
      2 
      3 #ifndef	__NETBSD_COMPAT_DEFS_H__
      4 #define	__NETBSD_COMPAT_DEFS_H__
      5 
      6 /* Work around some complete brain damage. */
      7 
      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 #endif
     17 
     18 /* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard
     19    defs. Other platforms may need similiar defines. */
     20 #ifdef __NetBSD__
     21 #define _POSIX_SOURCE	1
     22 #define _POSIX_C_SOURCE	200112L
     23 #define _XOPEN_SOURCE 600
     24 #else
     25 #undef _POSIX_SOURCE
     26 #undef _POSIX_C_SOURCE
     27 #endif
     28 
     29 /* System headers needed for (re)definitions below. */
     30 
     31 #include <sys/types.h>
     32 #include <sys/mman.h>
     33 #include <sys/param.h>
     34 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
     35 #include <sys/time.h>
     36 #include <sys/stat.h>
     37 #include <errno.h>
     38 #include <fcntl.h>
     39 #include <grp.h>
     40 #include <limits.h>
     41 #include <paths.h>
     42 #include <stdarg.h>
     43 #include <stdio.h>
     44 #include <stdlib.h>
     45 #include <string.h>
     46 
     47 #if HAVE_SYS_CDEFS_H
     48 #include <sys/cdefs.h>
     49 #endif
     50 #if HAVE_SYS_SYSLIMITS_H
     51 #include <sys/syslimits.h>
     52 #endif
     53 #if HAVE_SYS_SYSMACROS_H
     54 /* major(), minor() on SVR4 */
     55 #include <sys/sysmacros.h>
     56 #endif
     57 #if HAVE_INTTYPES_H
     58 #include <inttypes.h>
     59 #endif
     60 #if HAVE_STDDEF_H
     61 #include <stddef.h>
     62 #endif
     63 
     64 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
     65 struct passwd;
     66 
     67 /* Assume an ANSI compiler for the host. */
     68 
     69 #undef __P
     70 #define __P(x) x
     71 
     72 #ifndef __BEGIN_DECLS
     73 #define __BEGIN_DECLS
     74 #endif
     75 #ifndef __END_DECLS
     76 #define __END_DECLS
     77 #endif
     78 
     79 /* Some things usually in BSD <sys/cdefs.h>. */
     80 
     81 #ifndef __CONCAT
     82 #define	__CONCAT(x,y)	x ## y
     83 #endif
     84 #if !defined(__attribute__) && !defined(__GNUC__)
     85 #define __attribute__(x)
     86 #endif
     87 #if !defined(__packed)
     88 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
     89 #define __packed	__attribute__((__packed__))
     90 #else
     91 #define	__packed	error: no __packed for this compiler
     92 #endif
     93 #endif /* !__packed */
     94 #ifndef __RENAME
     95 #define __RENAME(x)
     96 #endif
     97 #undef __aconst
     98 #define __aconst
     99 #undef __dead
    100 #define __dead
    101 #undef __restrict
    102 #define __restrict
    103 
    104 /* Dirent support. */
    105 
    106 #if HAVE_DIRENT_H
    107 # include <dirent.h>
    108 # define NAMLEN(dirent) (strlen((dirent)->d_name))
    109 #else
    110 # define dirent direct
    111 # define NAMLEN(dirent) ((dirent)->d_namlen)
    112 # if HAVE_SYS_NDIR_H
    113 #  include <sys/ndir.h>
    114 # endif
    115 # if HAVE_SYS_DIR_H
    116 #  include <sys/dir.h>
    117 # endif
    118 # if HAVE_NDIR_H
    119 #  include <ndir.h>
    120 # endif
    121 #endif
    122 
    123 /* Type substitutes. */
    124 
    125 #if !HAVE_ID_T
    126 typedef unsigned long id_t;
    127 #endif
    128 
    129 #if !HAVE_SOCKLEN_T
    130 typedef int socklen_t;
    131 #endif
    132 
    133 #if !HAVE_U_LONG
    134 typedef unsigned long u_long;
    135 #endif
    136 
    137 #if !HAVE_U_CHAR
    138 typedef unsigned char u_char;
    139 #endif
    140 
    141 #if !HAVE_U_INT
    142 typedef unsigned int u_int;
    143 #endif
    144 
    145 #if !HAVE_U_SHORT
    146 typedef unsigned short u_short;
    147 #endif
    148 
    149 /* Prototypes for replacement functions. */
    150 
    151 #if !HAVE_ATOLL
    152 long long int atoll(const char *);
    153 #endif
    154 
    155 #if !HAVE_ASPRINTF
    156 int asprintf(char **, const char *, ...);
    157 #endif
    158 
    159 #if !HAVE_ASNPRINTF
    160 int asnprintf(char **, size_t, const char *, ...);
    161 #endif
    162 
    163 #if !HAVE_BASENAME
    164 char *basename(char *);
    165 #endif
    166 
    167 #if !HAVE_DECL_OPTIND
    168 int getopt(int, char *const *, const char *);
    169 extern char *optarg;
    170 extern int optind, opterr, optopt;
    171 #endif
    172 
    173 #if !HAVE_DIRNAME
    174 char *dirname(char *);
    175 #endif
    176 
    177 #if !HAVE_DIRFD
    178 #if HAVE_DIR_DD_FD
    179 #define dirfd(dirp) ((dirp)->dd_fd)
    180 #else
    181 /*XXX: Very hacky but no other way to bring this into scope w/o defining
    182   _NETBSD_SOURCE which we're avoiding. */
    183 #ifdef __NetBSD__
    184 struct _dirdesc {
    185         int     dd_fd;          /* file descriptor associated with directory */
    186 	long    dd_loc;         /* offset in current buffer */
    187 	long    dd_size;        /* amount of data returned by getdents */
    188 	char    *dd_buf;        /* data buffer */
    189 	int     dd_len;         /* size of data buffer */
    190 	off_t   dd_seek;        /* magic cookie returned by getdents */
    191 	long    dd_rewind;      /* magic cookie for rewinding */
    192 	int     dd_flags;       /* flags for readdir */
    193 	void    *dd_lock;       /* lock for concurrent access */
    194 };
    195 #define dirfd(dirp)     (((struct _dirdesc *)dirp)->dd_fd)
    196 #else
    197 #error cannot figure out how to turn a DIR * into a fd
    198 #endif
    199 #endif
    200 #endif
    201 
    202 #if !HAVE_ERR_H
    203 void err(int, const char *, ...);
    204 void errx(int, const char *, ...);
    205 void warn(const char *, ...);
    206 void warnx(const char *, ...);
    207 #endif
    208 
    209 #if !HAVE_FGETLN || defined(__NetBSD__)
    210 char *fgetln(FILE *, size_t *);
    211 #endif
    212 
    213 #if !HAVE_FLOCK
    214 # define LOCK_SH		0x01
    215 # define LOCK_EX		0x02
    216 # define LOCK_NB		0x04
    217 # define LOCK_UN		0x08
    218 int flock(int, int);
    219 #endif
    220 
    221 #if !HAVE_FPARSELN || defined(__NetBSD__)
    222 # define FPARSELN_UNESCESC	0x01
    223 # define FPARSELN_UNESCCONT	0x02
    224 # define FPARSELN_UNESCCOMM	0x04
    225 # define FPARSELN_UNESCREST	0x08
    226 # define FPARSELN_UNESCALL	0x0f
    227 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
    228 #endif
    229 
    230 #if !HAVE_ISSETUGID
    231 int issetugid(void);
    232 #endif
    233 
    234 #if !HAVE_ISBLANK && !defined(isblank)
    235 #define isblank(x) ((x) == ' ' || (x) == '\t')
    236 #endif
    237 
    238 #if !HAVE_LCHFLAGS
    239 int lchflags(const char *, u_long);
    240 #endif
    241 
    242 #if !HAVE_LCHMOD
    243 int lchmod(const char *, mode_t);
    244 #endif
    245 
    246 #if !HAVE_LCHOWN
    247 int lchown(const char *, uid_t, gid_t);
    248 #endif
    249 
    250 #define __nbcompat_bswap16(x)	((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
    251 
    252 #define __nbcompat_bswap32(x)	((((x) << 24) & 0xff000000) | \
    253 				 (((x) <<  8) & 0x00ff0000) | \
    254 				 (((x) >>  8) & 0x0000ff00) | \
    255 				 (((x) >> 24) & 0x000000ff))
    256 
    257 #define __nbcompat_bswap64(x)	(((u_int64_t)bswap32((x)) << 32) | \
    258 				 ((u_int64_t)bswap32((x) >> 32)))
    259 
    260 #if !HAVE_BSWAP16
    261 #ifdef bswap16
    262 #undef bswap16
    263 #endif
    264 #define bswap16(x)	__nbcompat_bswap16(x)
    265 #endif
    266 #if !HAVE_BSWAP32
    267 #ifdef bswap32
    268 #undef bswap32
    269 #endif
    270 #define bswap32(x)	__nbcompat_bswap32(x)
    271 #endif
    272 #if !HAVE_BSWAP64
    273 #ifdef bswap64
    274 #undef bswap64
    275 #endif
    276 #define bswap64(x)	__nbcompat_bswap64(x)
    277 #endif
    278 
    279 #if !HAVE_MKSTEMP
    280 int mkstemp(char *);
    281 #endif
    282 
    283 #if !HAVE_MKDTEMP
    284 char *mkdtemp(char *);
    285 #endif
    286 
    287 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
    288 /* This is a prototype for the internal function. */
    289 int gettemp(char *, int *, int);
    290 #endif
    291 
    292 #if !HAVE_PREAD
    293 ssize_t pread(int, void *, size_t, off_t);
    294 #endif
    295 
    296 #if !HAVE_PWCACHE_USERDB
    297 int uid_from_user(const char *, uid_t *);
    298 int pwcache_userdb(int (*)(int), void (*)(void),
    299 		struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
    300 int gid_from_group(const char *, gid_t *);
    301 int pwcache_groupdb(int (*)(int), void (*)(void),
    302 		struct group * (*)(const char *), struct group * (*)(gid_t));
    303 #endif
    304 /* Make them use our version */
    305 #  define user_from_uid __nbcompat_user_from_uid
    306 /* Make them use our version */
    307 #  define group_from_gid __nbcompat_group_from_gid
    308 
    309 #if !HAVE_PWRITE
    310 ssize_t pwrite(int, const void *, size_t, off_t);
    311 #endif
    312 
    313 #if !HAVE_SETENV
    314 int setenv(const char *, const char *, int);
    315 #endif
    316 
    317 #if !HAVE_DECL_SETGROUPENT
    318 int setgroupent(int);
    319 #endif
    320 
    321 #if !HAVE_DECL_SETPASSENT
    322 int setpassent(int);
    323 #endif
    324 
    325 #if !HAVE_SETPROGNAME || defined(__NetBSD__)
    326 const char *getprogname(void);
    327 void setprogname(const char *);
    328 #endif
    329 
    330 #if !HAVE_SNPRINTF
    331 int snprintf(char *, size_t, const char *, ...);
    332 #endif
    333 
    334 #if !HAVE_STRLCAT
    335 size_t strlcat(char *, const char *, size_t);
    336 #endif
    337 
    338 #if !HAVE_STRLCPY
    339 size_t strlcpy(char *, const char *, size_t);
    340 #endif
    341 
    342 #if !HAVE_STRSEP || defined(__NetBSD__)
    343 char *strsep(char **, const char *);
    344 #endif
    345 
    346 #if !HAVE_STRSUFTOLL
    347 long long strsuftoll(const char *, const char *, long long, long long);
    348 long long strsuftollx(const char *, const char *,
    349 			long long, long long, char *, size_t);
    350 #endif
    351 
    352 #if !HAVE_STRTOLL
    353 long long strtoll(const char *, char **, int);
    354 #endif
    355 
    356 #if !HAVE_USER_FROM_UID
    357 const char *user_from_uid(uid_t, int);
    358 #endif
    359 
    360 #if !HAVE_GROUP_FROM_GID
    361 const char *group_from_gid(gid_t, int);
    362 #endif
    363 
    364 #if !HAVE_VASPRINTF
    365 int vasprintf(char **, const char *, va_list);
    366 #endif
    367 
    368 #if !HAVE_VASNPRINTF
    369 int vasnprintf(char **, size_t, const char *, va_list);
    370 #endif
    371 
    372 #if !HAVE_VSNPRINTF
    373 int vsnprintf(char *, size_t, const char *, va_list);
    374 #endif
    375 
    376 /*
    377  * getmode() and setmode() are always defined, as these function names
    378  * exist but with very different meanings on other OS's.  The compat
    379  * versions here simply accept an octal mode number; the "u+x,g-w" type
    380  * of syntax is not accepted.
    381  */
    382 
    383 #define getmode __nbcompat_getmode
    384 #define setmode __nbcompat_setmode
    385 
    386 mode_t getmode(const void *, mode_t);
    387 void *setmode(const char *);
    388 
    389 /* Eliminate assertions embedded in binaries. */
    390 
    391 #undef _DIAGASSERT
    392 #define _DIAGASSERT(x)
    393 
    394 /* Various sources use this */
    395 #undef	__RCSID
    396 #define	__RCSID(x)
    397 #undef	__SCCSID
    398 #define	__SCCSID(x)
    399 #undef	__COPYRIGHT
    400 #define	__COPYRIGHT(x)
    401 #undef	__KERNEL_RCSID
    402 #define	__KERNEL_RCSID(x,y)
    403 
    404 /* Heimdal expects this one. */
    405 
    406 #undef RCSID
    407 #define RCSID(x)
    408 
    409 /* Some definitions not available on all systems. */
    410 
    411 /* <errno.h> */
    412 
    413 #ifndef EFTYPE
    414 #define EFTYPE EIO
    415 #endif
    416 
    417 /* <fcntl.h> */
    418 
    419 #ifndef O_EXLOCK
    420 #define O_EXLOCK 0
    421 #endif
    422 #ifndef O_SHLOCK
    423 #define O_SHLOCK 0
    424 #endif
    425 
    426 /* <limits.h> */
    427 
    428 #ifndef UID_MAX
    429 #define UID_MAX 32767
    430 #endif
    431 #ifndef GID_MAX
    432 #define GID_MAX UID_MAX
    433 #endif
    434 
    435 #ifndef UQUAD_MAX
    436 #define UQUAD_MAX ((u_quad_t)-1)
    437 #endif
    438 #ifndef QUAD_MAX
    439 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
    440 #endif
    441 #ifndef QUAD_MIN
    442 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
    443 #endif
    444 #ifndef ULLONG_MAX
    445 #define ULLONG_MAX ((unsigned long long)-1)
    446 #endif
    447 #ifndef LLONG_MAX
    448 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
    449 #endif
    450 #ifndef LLONG_MIN
    451 #define LLONG_MIN ((long long)(~LLONG_MAX))
    452 #endif
    453 
    454 /* <paths.h> */
    455 
    456 #ifndef _PATH_BSHELL
    457 #define _PATH_BSHELL PATH_BSHELL
    458 #endif
    459 #ifndef _PATH_DEFPATH
    460 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
    461 #endif
    462 #ifndef _PATH_DEV
    463 #define _PATH_DEV "/dev/"
    464 #endif
    465 #ifndef _PATH_DEVNULL
    466 #define _PATH_DEVNULL _PATH_DEV "null"
    467 #endif
    468 #ifndef _PATH_TMP
    469 #define _PATH_TMP "/tmp/"
    470 #endif
    471 #ifndef _PATH_DEFTAPE
    472 #define _PATH_DEFTAPE "/dev/nrst0"
    473 #endif
    474 
    475 /* <stdarg.h> */
    476 
    477 #ifndef _BSD_VA_LIST_
    478 #define _BSD_VA_LIST_ va_list
    479 #endif
    480 
    481 /* <stdint.h> */
    482 
    483 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
    484 #define SIZE_MAX SIZE_T_MAX
    485 #endif
    486 
    487 #ifndef UINT32_MAX
    488 #define UINT32_MAX 0xffffffffU
    489 #endif
    490 
    491 /* <stdlib.h> */
    492 
    493 #ifndef __GNUC__
    494 # if HAVE_ALLOCA_H
    495 #  include <alloca.h>
    496 # else
    497 #  ifndef alloca /* predefined by HP cc +Olibcalls */
    498 char *alloca ();
    499 #  endif
    500 # endif
    501 #endif
    502 
    503 /* avoid prototype conflicts with host */
    504 #define cgetcap __nbcompat_cgetcap
    505 #define cgetclose __nbcompat_cgetclose
    506 #define cgetent __nbcompat_cgetent
    507 #define cgetfirst __nbcompat_cgetfirst
    508 #define cgetmatch __nbcompat_cgetmatch
    509 #define cgetnext __nbcompat_cgetnext
    510 #define cgetnum __nbcompat_cgetnum
    511 #define cgetset __nbcompat_cgetset
    512 #define cgetstr __nbcompat_cgetstr
    513 #define cgetustr __nbcompat_cgetustr
    514 
    515 char	*cgetcap(char *, const char *, int);
    516 int	 cgetclose(void);
    517 int	 cgetent(char **, const char * const *, const char *);
    518 int	 cgetfirst(char **, const char * const *);
    519 int	 cgetmatch(const char *, const char *);
    520 int	 cgetnext(char **, const char * const *);
    521 int	 cgetnum(char *, const char *, long *);
    522 int	 cgetset(const char *);
    523 int	 cgetstr(char *, const char *, char **);
    524 int	 cgetustr(char *, const char *, char **);
    525 
    526 /* <sys/endian.h> */
    527 
    528 #if WORDS_BIGENDIAN
    529 #if !HAVE_HTOBE16
    530 #define htobe16(x)	(x)
    531 #endif
    532 #if !HAVE_HTOBE32
    533 #define htobe32(x)	(x)
    534 #endif
    535 #if !HAVE_HTOBE64
    536 #define htobe64(x)	(x)
    537 #endif
    538 #if !HAVE_HTOLE16
    539 #define htole16(x)	bswap16((u_int16_t)(x))
    540 #endif
    541 #if !HAVE_HTOLE32
    542 #define htole32(x)	bswap32((u_int32_t)(x))
    543 #endif
    544 #if !HAVE_HTOLE64
    545 #define htole64(x)	bswap64((u_int64_t)(x))
    546 #endif
    547 #else
    548 #if !HAVE_HTOBE16
    549 #define htobe16(x)	bswap16((u_int16_t)(x))
    550 #endif
    551 #if !HAVE_HTOBE32
    552 #define htobe32(x)	bswap32((u_int32_t)(x))
    553 #endif
    554 #if !HAVE_HTOBE64
    555 #define htobe64(x)	bswap64((u_int64_t)(x))
    556 #endif
    557 #if !HAVE_HTOLE16
    558 #define htole16(x)	(x)
    559 #endif
    560 #if !HAVE_HTOLE32
    561 #define htole32(x)	(x)
    562 #endif
    563 #if !HAVE_HTOLE64
    564 #define htole64(x)	(x)
    565 #endif
    566 #endif
    567 #if !HAVE_BE16TOH
    568 #define be16toh(x)	htobe16(x)
    569 #endif
    570 #if !HAVE_BE32TOH
    571 #define be32toh(x)	htobe32(x)
    572 #endif
    573 #if !HAVE_BE64TOH
    574 #define be64toh(x)	htobe64(x)
    575 #endif
    576 #if !HAVE_LE16TOH
    577 #define le16toh(x)	htole16(x)
    578 #endif
    579 #if !HAVE_LE32TOH
    580 #define le32toh(x)	htole32(x)
    581 #endif
    582 #if !HAVE_LE64TOH
    583 #define le64toh(x)	htole64(x)
    584 #endif
    585 
    586 /* <sys/mman.h> */
    587 
    588 #ifndef MAP_FILE
    589 #define MAP_FILE 0
    590 #endif
    591 
    592 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
    593 #ifndef MAP_ANON
    594 #ifdef MAP_ANONYMOUS
    595 #define MAP_ANON MAP_ANONYMOUS
    596 #endif
    597 #endif
    598 
    599 /* <sys/param.h> */
    600 
    601 #undef BIG_ENDIAN
    602 #undef LITTLE_ENDIAN
    603 #define BIG_ENDIAN 4321
    604 #define LITTLE_ENDIAN 1234
    605 
    606 #undef BYTE_ORDER
    607 #if WORDS_BIGENDIAN
    608 #define BYTE_ORDER BIG_ENDIAN
    609 #else
    610 #define BYTE_ORDER LITTLE_ENDIAN
    611 #endif
    612 
    613 #ifndef DEV_BSIZE
    614 #define DEV_BSIZE (1 << 9)
    615 #endif
    616 
    617 #undef MIN
    618 #undef MAX
    619 #define MIN(a,b) ((a) < (b) ? (a) : (b))
    620 #define MAX(a,b) ((a) > (b) ? (a) : (b))
    621 
    622 #ifndef MAXBSIZE
    623 #define MAXBSIZE (64 * 1024)
    624 #endif
    625 #ifndef MAXFRAG
    626 #define MAXFRAG 8
    627 #endif
    628 #ifndef MAXPHYS
    629 #define MAXPHYS (64 * 1024)
    630 #endif
    631 
    632 /* XXX needed by makefs; this should be done in a better way */
    633 #undef btodb
    634 #define btodb(x) ((x) << 9)
    635 
    636 #undef setbit
    637 #undef clrbit
    638 #undef isset
    639 #undef isclr
    640 #define	setbit(a,i)	((a)[(i)/NBBY] |= 1<<((i)%NBBY))
    641 #define	clrbit(a,i)	((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
    642 #define	isset(a,i)	((a)[(i)/NBBY] & (1<<((i)%NBBY)))
    643 #define	isclr(a,i)	(((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
    644 
    645 #ifndef powerof2
    646 #define powerof2(x) ((((x)-1)&(x))==0)
    647 #endif
    648 
    649 #undef roundup
    650 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
    651 
    652 /* <sys/stat.h> */
    653 
    654 #ifndef ALLPERMS
    655 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
    656 #endif
    657 #ifndef DEFFILEMODE
    658 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
    659 #endif
    660 #ifndef S_ISTXT
    661 #ifdef S_ISVTX
    662 #define S_ISTXT S_ISVTX
    663 #else
    664 #define S_ISTXT 0
    665 #endif
    666 #endif
    667 
    668 /* Protected by _NETBSD_SOURCE otherwise. */
    669 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
    670 #define UF_SETTABLE     0x0000ffff
    671 #define UF_NODUMP       0x00000001
    672 #define UF_IMMUTABLE    0x00000002
    673 #define UF_APPEND       0x00000004
    674 #define UF_OPAQUE       0x00000008
    675 #define SF_SETTABLE     0xffff0000
    676 #define SF_ARCHIVED     0x00010000
    677 #define SF_IMMUTABLE    0x00020000
    678 #define SF_APPEND       0x00040000
    679 #endif
    680 
    681 /* <sys/syslimits.h> */
    682 
    683 #ifndef LINE_MAX
    684 #define LINE_MAX 2048
    685 #endif
    686 
    687 /* <sys/time.h> */
    688 
    689 #ifndef timercmp
    690 #define	timercmp(tvp, uvp, cmp)						\
    691 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
    692 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
    693 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
    694 #endif
    695 #ifndef timeradd
    696 #define	timeradd(tvp, uvp, vvp)						\
    697 	do {								\
    698 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
    699 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
    700 		if ((vvp)->tv_usec >= 1000000) {			\
    701 			(vvp)->tv_sec++;				\
    702 			(vvp)->tv_usec -= 1000000;			\
    703 		}							\
    704 	} while (/* CONSTCOND */ 0)
    705 #endif
    706 #ifndef timersub
    707 #define	timersub(tvp, uvp, vvp)						\
    708 	do {								\
    709 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
    710 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
    711 		if ((vvp)->tv_usec < 0) {				\
    712 			(vvp)->tv_sec--;				\
    713 			(vvp)->tv_usec += 1000000;			\
    714 		}							\
    715 	} while (/* CONSTCOND */ 0)
    716 #endif
    717 
    718 /* <sys/types.h> */
    719 
    720 #ifdef major
    721 #undef major
    722 #endif
    723 #define major(x)        ((int32_t)((((x) & 0x000fff00) >>  8)))
    724 
    725 #ifdef minor
    726 #undef minor
    727 #endif
    728 #define minor(x)        ((int32_t)((((x) & 0xfff00000) >> 12) | \
    729                                    (((x) & 0x000000ff) >>  0)))
    730 #ifdef makedev
    731 #undef makedev
    732 #endif
    733 #define makedev(x,y)    ((dev_t)((((x) <<  8) & 0x000fff00) | \
    734 			(((y) << 12) & 0xfff00000) | \
    735 			(((y) <<  0) & 0x000000ff)))
    736 #ifndef NBBY
    737 #define NBBY 8
    738 #endif
    739 
    740 #if !HAVE_U_QUAD_T
    741 /* #define, not typedef, as quad_t exists as a struct on some systems */
    742 #define quad_t long long
    743 #define u_quad_t unsigned long long
    744 #define strtoq strtoll
    745 #define strtouq strtoull
    746 #endif
    747 
    748 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
    749 #ifdef __NetBSD__
    750 quad_t   strtoq __P((const char *, char **, int));
    751 u_quad_t strtouq __P((const char *, char **, int));
    752 #endif
    753 
    754 #endif	/* !__NETBSD_COMPAT_DEFS_H__ */
    755