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