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