1 /* $NetBSD: compat_defs.h,v 1.93 2013/10/24 13:59:47 apb Exp $ */
3 #ifndef __NETBSD_COMPAT_DEFS_H__
4 #define __NETBSD_COMPAT_DEFS_H__
7 /* Work around some complete brain damage. */
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.
14 #if defined(__linux__) && HAVE_FEATURES_H
16 #define __USE_ISOC99 1
19 /* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard
20 defs. Other platforms may need similiar defines. */
21 #if defined(__NetBSD__) || defined(__minix)
22 #define _ISOC99_SOURCE
23 #define _POSIX_SOURCE 1
24 #define _POSIX_C_SOURCE 200112L
25 #define _XOPEN_SOURCE 600
28 #undef _POSIX_C_SOURCE
31 /* System headers needed for (re)definitions below. */
33 #include <sys/types.h>
35 #include <sys/param.h>
36 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
49 #include <sys/cdefs.h>
51 #if HAVE_SYS_SYSLIMITS_H
52 #include <sys/syslimits.h>
54 #if HAVE_SYS_SYSMACROS_H
55 /* major(), minor() on SVR4 */
56 #include <sys/sysmacros.h>
66 #include <rpc/types.h>
70 #error _NETBSD_SOURCE is *not* to be defined.
73 /* Need this since we can't depend on NetBSD's version to be around */
77 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
79 #undef __predict_false
80 #define __predict_false(x) (x)
82 #define __predict_true(x) (x)
84 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
87 /* We don't include <grp.h> either */
90 /* Assume an ANSI compiler for the host. */
102 /* Some things usually in BSD <sys/cdefs.h>. */
105 #define __CONCAT(x,y) x ## y
107 #if !defined(__attribute__) && !defined(__GNUC__)
108 #define __attribute__(x)
110 #if !defined(__packed)
111 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
112 #define __packed __attribute__((__packed__))
113 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
114 #define __packed __attribute__((__packed__))
116 #define __packed error: no __packed for this compiler
118 #endif /* !__packed */
127 #define __printflike(x,y)
129 #define __format_arg(x)
135 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
137 #define __USE(a) ((void)(a))
139 /* Dirent support. */
142 # if defined(__linux__) && defined(__USE_BSD)
149 # if defined(__DARWIN_UNIX03)
153 # define NAMLEN(dirent) (strlen((dirent)->d_name))
155 # define dirent direct
156 # define NAMLEN(dirent) ((dirent)->d_namlen)
158 # include <sys/ndir.h>
161 # include <sys/dir.h>
168 /* Type substitutes. */
171 typedef unsigned int id_t
;
176 * This is defined as int for compatibility with legacy systems (and not
177 * unsigned int), since universally it was int in most systems that did not
180 typedef int socklen_t
;
184 typedef unsigned long u_long
;
188 typedef unsigned char u_char
;
192 typedef unsigned int u_int
;
196 typedef unsigned short u_short
;
199 /* Prototypes for replacement functions. */
202 long long int atoll(const char *);
206 int asprintf(char **, const char *, ...);
210 int asnprintf(char **, size_t, const char *, ...);
214 char *basename(char *);
217 #if !HAVE_DECL_OPTIND
218 int getopt(int, char *const *, const char *);
220 extern int optind
, opterr
, optopt
;
224 char *dirname(char *);
229 #define dirfd(dirp) ((dirp)->dd_fd)
230 #elif HAVE_DIR___DD_FD
231 #define dirfd(dirp) ((dirp)->__dd_fd)
233 /*XXX: Very hacky but no other way to bring this into scope w/o defining
234 _NETBSD_SOURCE which we're avoiding. */
235 #if defined(__NetBSD__) || defined(__minix)
237 int dd_fd
; /* file descriptor associated with directory */
238 long dd_loc
; /* offset in current buffer */
239 long dd_size
; /* amount of data returned by getdents */
240 char *dd_buf
; /* data buffer */
241 int dd_len
; /* size of data buffer */
242 off_t dd_seek
; /* magic cookie returned by getdents */
243 long dd_rewind
; /* magic cookie for rewinding */
244 int dd_flags
; /* flags for readdir */
245 void *dd_lock
; /* lock for concurrent access */
247 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
249 #error cannot figure out how to turn a DIR * into a fd
255 void err(int, const char *, ...);
256 void errx(int, const char *, ...);
257 void warn(const char *, ...);
258 void warnx(const char *, ...);
259 void vwarnx(const char *, va_list);
263 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
264 size_t estrlcpy(char *, const char *, size_t);
265 size_t estrlcat(char *, const char *, size_t);
266 char *estrdup(const char *);
267 char *estrndup(const char *, size_t);
268 void *ecalloc(size_t, size_t);
269 void *emalloc(size_t);
270 void *erealloc(void *, size_t);
271 FILE *efopen(const char *, const char *);
272 int easprintf(char **, const char *, ...);
273 int evasprintf(char **, const char *, va_list);
276 #if !HAVE_FGETLN || defined(__NetBSD__) || defined(__minix)
277 char *fgetln(FILE *, size_t *);
280 int dprintf(int, const char *, ...);
284 # define LOCK_SH 0x01
285 # define LOCK_EX 0x02
286 # define LOCK_NB 0x04
287 # define LOCK_UN 0x08
291 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) || defined(__minix)
292 # define FPARSELN_UNESCESC 0x01
293 # define FPARSELN_UNESCCONT 0x02
294 # define FPARSELN_UNESCCOMM 0x04
295 # define FPARSELN_UNESCREST 0x08
296 # define FPARSELN_UNESCALL 0x0f
297 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
301 ssize_t
getdelim(char **, size_t *, int, FILE *);
302 ssize_t
getline(char **, size_t *, FILE *);
309 #if !HAVE_ISBLANK && !defined(isblank)
310 #define isblank(x) ((x) == ' ' || (x) == '\t')
313 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
315 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
316 (((x) << 8) & 0x00ff0000) | \
317 (((x) >> 8) & 0x0000ff00) | \
318 (((x) >> 24) & 0x000000ff))
320 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
321 ((u_int64_t)bswap32((x) >> 32)))
323 #if ! HAVE_DECL_BSWAP16
327 #define bswap16(x) __nbcompat_bswap16(x)
329 #if ! HAVE_DECL_BSWAP32
333 #define bswap32(x) __nbcompat_bswap32(x)
335 #if ! HAVE_DECL_BSWAP64
339 #define bswap64(x) __nbcompat_bswap64(x)
347 char *mkdtemp(char *);
350 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
351 /* This is a prototype for the internal function defined in
352 * src/lib/lib/stdio/gettemp.c */
353 int __nbcompat_gettemp(char *, int *, int);
357 ssize_t
pread(int, void *, size_t, off_t
);
361 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
363 /* Make them use our version */
364 # define heapsort __nbcompat_heapsort
366 char *flags_to_string(unsigned long, const char *);
367 int string_to_flags(char **, unsigned long *, unsigned long *);
370 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
371 * supply an implementation of one without the others -- some parts are
372 * libc internal and this varies from system to system.
374 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
375 * XXX host system has all of these functions, all of their interfaces
376 * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
378 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
379 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
380 /* Make them use our version */
381 # define user_from_uid __nbcompat_user_from_uid
382 # define uid_from_user __nbcompat_uid_from_user
383 # define pwcache_userdb __nbcompat_pwcache_userdb
384 # define group_from_gid __nbcompat_group_from_gid
385 # define gid_from_group __nbcompat_gid_from_group
386 # define pwcache_groupdb __nbcompat_pwcache_groupdb
389 #if !HAVE_DECL_UID_FROM_USER
390 int uid_from_user(const char *, uid_t
*);
393 #if !HAVE_DECL_USER_FROM_UID
394 const char *user_from_uid(uid_t
, int);
397 #if !HAVE_DECL_PWCACHE_USERDB
398 int pwcache_userdb(int (*)(int), void (*)(void),
399 struct passwd
* (*)(const char *), struct passwd
* (*)(uid_t
));
402 #if !HAVE_DECL_GID_FROM_GROUP
403 int gid_from_group(const char *, gid_t
*);
406 #if !HAVE_DECL_GROUP_FROM_GID
407 const char *group_from_gid(gid_t
, int);
410 #if !HAVE_DECL_PWCACHE_GROUPDB
411 int pwcache_groupdb(int (*)(int), void (*)(void),
412 struct group
* (*)(const char *), struct group
* (*)(gid_t
));
415 #if !HAVE_DECL_STRNDUP
416 char *strndup(const char *, size_t);
418 #if !HAVE_DECL_LCHFLAGS
419 int lchflags(const char *, unsigned long);
421 #if !HAVE_DECL_LCHMOD
422 int lchmod(const char *, mode_t
);
424 #if !HAVE_DECL_LCHOWN
425 int lchown(const char *, uid_t
, gid_t
);
429 ssize_t
pwrite(int, const void *, size_t, off_t
);
432 #if !HAVE_RAISE_DEFAULT_SIGNAL
433 int raise_default_signal(int);
437 int setenv(const char *, const char *, int);
440 #if !HAVE_DECL_SETGROUPENT
441 int setgroupent(int);
444 #if !HAVE_DECL_SETPASSENT
448 #if !HAVE_SETPROGNAME || defined(__NetBSD__) || defined(__minix)
449 const char *getprogname(void);
450 void setprogname(const char *);
454 int snprintb(char *, size_t, const char *, uint64_t);
455 int snprintb_m(char *, size_t, const char *, uint64_t, size_t);
459 int snprintf(char *, size_t, const char *, ...);
463 size_t strlcat(char *, const char *, size_t);
467 size_t strlcpy(char *, const char *, size_t);
471 void strmode(mode_t
, char *);
475 char *strndup(const char *, size_t);
478 #if !HAVE_STRSEP || defined(__NetBSD__) || defined(__minix)
479 char *strsep(char **, const char *);
482 #if !HAVE_DECL_STRSUFTOLL
483 long long strsuftoll(const char *, const char *, long long, long long);
484 long long strsuftollx(const char *, const char *,
485 long long, long long, char *, size_t);
489 long long strtoll(const char *, char **, int);
492 #if !HAVE_USER_FROM_UID
493 const char *user_from_uid(uid_t
, int);
496 #if !HAVE_GROUP_FROM_GID
497 const char *group_from_gid(gid_t
, int);
501 int vasprintf(char **, const char *, va_list);
505 int vasnprintf(char **, size_t, const char *, va_list);
509 int vsnprintf(char *, size_t, const char *, va_list);
513 * getmode() and setmode() are always defined, as these function names
514 * exist but with very different meanings on other OS's. The compat
515 * versions here simply accept an octal mode number; the "u+x,g-w" type
516 * of syntax is not accepted.
519 #define getmode __nbcompat_getmode
520 #define setmode __nbcompat_setmode
522 mode_t
getmode(const void *, mode_t
);
523 void *setmode(const char *);
525 /* Eliminate assertions embedded in binaries. */
528 #define _DIAGASSERT(x)
530 /* Various sources use this */
532 #define __RCSID(x) struct XXXNETBSD_RCSID
536 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
537 #undef __KERNEL_RCSID
538 #define __KERNEL_RCSID(x,y)
540 /* Heimdal expects this one. */
545 /* Some definitions not available on all systems. */
548 #define __inline inline
568 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */
605 #endif /* char is an 8-bit type */
606 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
607 defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
608 #error "Don't know how to define PRI[diouxX]8"
610 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
611 defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
612 #error "Don't know how to define SCN[diouxX]8"
615 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */
652 #endif /* short is a 16-bit type */
653 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
654 defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
655 #error "Don't know how to define PRI[diouxX]16"
657 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
658 defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
659 #error "Don't know how to define SCN[diouxX]16"
662 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
699 #endif /* int is a 32-bit type */
700 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
737 #endif /* long is a 32-bit type */
738 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
739 defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
740 #error "Don't know how to define PRI[diouxX]32"
742 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
743 defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
744 #error "Don't know how to define SCN[diouxX]32"
747 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
784 #endif /* long is a 64-bit type */
785 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
822 #endif /* long long is a 64-bit type */
823 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
824 defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
825 #error "Don't know how to define PRI[diouxX]64"
827 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
828 defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
829 #error "Don't know how to define SCN[diouxX]64"
835 #define UID_MAX 32767
838 #define GID_MAX UID_MAX
842 #define UQUAD_MAX ((u_quad_t)-1)
845 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
848 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
851 #define ULLONG_MAX ((unsigned long long)-1)
854 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
857 #define LLONG_MIN ((long long)(~LLONG_MAX))
862 /* The host's _PATH_BSHELL might be broken, so override it. */
864 #define _PATH_BSHELL PATH_BSHELL
865 #ifndef _PATH_DEFPATH
866 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
869 #define _PATH_DEV "/dev/"
871 #ifndef _PATH_DEVNULL
872 #define _PATH_DEVNULL _PATH_DEV "null"
875 #define _PATH_TMP "/tmp/"
877 #ifndef _PATH_DEFTAPE
878 #define _PATH_DEFTAPE "/dev/nrst0"
881 #define _PATH_VI "/usr/bin/vi"
886 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
887 #define SIZE_MAX SIZE_T_MAX
891 #define UINT8_MAX 0xffU
895 #define UINT16_MAX 0xffffU
899 #define UINT32_MAX 0xffffffffU
908 # ifndef alloca /* predefined by HP cc +Olibcalls */
914 /* avoid prototype conflicts with host */
915 #define cgetcap __nbcompat_cgetcap
916 #define cgetclose __nbcompat_cgetclose
917 #define cgetent __nbcompat_cgetent
918 #define cgetfirst __nbcompat_cgetfirst
919 #define cgetmatch __nbcompat_cgetmatch
920 #define cgetnext __nbcompat_cgetnext
921 #define cgetnum __nbcompat_cgetnum
922 #define cgetset __nbcompat_cgetset
923 #define cgetstr __nbcompat_cgetstr
924 #define cgetustr __nbcompat_cgetustr
926 char *cgetcap(char *, const char *, int);
928 int cgetent(char **, const char * const *, const char *);
929 int cgetfirst(char **, const char * const *);
930 int cgetmatch(const char *, const char *);
931 int cgetnext(char **, const char * const *);
932 int cgetnum(char *, const char *, long *);
933 int cgetset(const char *);
934 int cgetstr(char *, const char *, char **);
935 int cgetustr(char *, const char *, char **);
940 #if !HAVE_DECL_HTOBE16
941 #define htobe16(x) (x)
943 #if !HAVE_DECL_HTOBE32
944 #define htobe32(x) (x)
946 #if !HAVE_DECL_HTOBE64
947 #define htobe64(x) (x)
949 #if !HAVE_DECL_HTOLE16
950 #define htole16(x) bswap16((u_int16_t)(x))
952 #if !HAVE_DECL_HTOLE32
953 #define htole32(x) bswap32((u_int32_t)(x))
955 #if !HAVE_DECL_HTOLE64
956 #define htole64(x) bswap64((u_int64_t)(x))
959 #if !HAVE_DECL_HTOBE16
960 #define htobe16(x) bswap16((u_int16_t)(x))
962 #if !HAVE_DECL_HTOBE32
963 #define htobe32(x) bswap32((u_int32_t)(x))
965 #if !HAVE_DECL_HTOBE64
966 #define htobe64(x) bswap64((u_int64_t)(x))
968 #if !HAVE_DECL_HTOLE16
969 #define htole16(x) (x)
971 #if !HAVE_DECL_HTOLE32
972 #define htole32(x) (x)
974 #if !HAVE_DECL_HTOLE64
975 #define htole64(x) (x)
978 #if !HAVE_DECL_BE16TOH
979 #define be16toh(x) htobe16(x)
981 #if !HAVE_DECL_BE32TOH
982 #define be32toh(x) htobe32(x)
984 #if !HAVE_DECL_BE64TOH
985 #define be64toh(x) htobe64(x)
987 #if !HAVE_DECL_LE16TOH
988 #define le16toh(x) htole16(x)
990 #if !HAVE_DECL_LE32TOH
991 #define le32toh(x) htole32(x)
993 #if !HAVE_DECL_LE64TOH
994 #define le64toh(x) htole64(x)
997 #define __GEN_ENDIAN_ENC(bits, endian) \
999 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
1001 u = hto ## endian ## bits (u); \
1002 memcpy(dst, &u, sizeof(u)); \
1004 #if !HAVE_DECL_BE16ENC
1005 __GEN_ENDIAN_ENC(16, be
)
1007 #if !HAVE_DECL_BE32ENC
1008 __GEN_ENDIAN_ENC(32, be
)
1010 #if !HAVE_DECL_BE64ENC
1011 __GEN_ENDIAN_ENC(64, be
)
1013 #if !HAVE_DECL_LE16ENC
1014 __GEN_ENDIAN_ENC(16, le
)
1016 #if !HAVE_DECL_LE32ENC
1017 __GEN_ENDIAN_ENC(32, le
)
1019 #if !HAVE_DECL_LE64ENC
1020 __GEN_ENDIAN_ENC(64, le
)
1022 #undef __GEN_ENDIAN_ENC
1024 #define __GEN_ENDIAN_DEC(bits, endian) \
1025 static uint ## bits ## _t \
1026 endian ## bits ## dec(const void *buf) \
1028 uint ## bits ## _t u; \
1029 memcpy(&u, buf, sizeof(u)); \
1030 return endian ## bits ## toh (u); \
1032 #if !HAVE_DECL_BE16DEC
1033 __GEN_ENDIAN_DEC(16, be
)
1035 #if !HAVE_DECL_BE32DEC
1036 __GEN_ENDIAN_DEC(32, be
)
1038 #if !HAVE_DECL_BE64DEC
1039 __GEN_ENDIAN_DEC(64, be
)
1041 #if !HAVE_DECL_LE16DEC
1042 __GEN_ENDIAN_DEC(16, le
)
1044 #if !HAVE_DECL_LE32DEC
1045 __GEN_ENDIAN_DEC(32, le
)
1047 #if !HAVE_DECL_LE64DEC
1048 __GEN_ENDIAN_DEC(64, le
)
1050 #undef __GEN_ENDIAN_DEC
1058 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
1060 #ifdef MAP_ANONYMOUS
1061 #define MAP_ANON MAP_ANONYMOUS
1068 #undef LITTLE_ENDIAN
1070 #define BIG_ENDIAN 4321
1071 #define LITTLE_ENDIAN 1234
1072 #define PDP_ENDIAN 3412
1076 #define BYTE_ORDER BIG_ENDIAN
1078 #define BYTE_ORDER LITTLE_ENDIAN
1081 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
1083 #define DEV_BSIZE (1 << 9)
1087 #define MIN(a,b) ((a) < (b) ? (a) : (b))
1088 #define MAX(a,b) ((a) > (b) ? (a) : (b))
1091 #define MAXBSIZE (64 * 1024)
1097 #define MAXPHYS (64 * 1024)
1100 /* XXX needed by makefs; this should be done in a better way */
1102 #define btodb(x) ((x) << 9)
1108 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1109 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1110 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1111 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1114 #define powerof2(x) ((((x)-1)&(x))==0)
1118 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1123 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
1126 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
1130 #define S_ISTXT S_ISVTX
1136 /* Protected by _NETBSD_SOURCE otherwise. */
1137 #if HAVE_STRUCT_STAT_ST_FLAGS && (defined(__NetBSD__) || defined(__minix))
1138 #define UF_SETTABLE 0x0000ffff
1139 #define UF_NODUMP 0x00000001
1140 #define UF_IMMUTABLE 0x00000002
1141 #define UF_APPEND 0x00000004
1142 #define UF_OPAQUE 0x00000008
1143 #define SF_SETTABLE 0xffff0000
1144 #define SF_ARCHIVED 0x00010000
1145 #define SF_IMMUTABLE 0x00020000
1146 #define SF_APPEND 0x00040000
1149 /* <sys/syslimits.h> */
1152 #define LINE_MAX 2048
1158 #define timercmp(tvp, uvp, cmp) \
1159 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
1160 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1161 ((tvp)->tv_sec cmp (uvp)->tv_sec))
1164 #define timeradd(tvp, uvp, vvp) \
1166 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
1167 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
1168 if ((vvp)->tv_usec >= 1000000) { \
1170 (vvp)->tv_usec -= 1000000; \
1172 } while (/* CONSTCOND */ 0)
1175 #define timersub(tvp, uvp, vvp) \
1177 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
1178 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
1179 if ((vvp)->tv_usec < 0) { \
1181 (vvp)->tv_usec += 1000000; \
1183 } while (/* CONSTCOND */ 0)
1191 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
1196 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
1197 (((x) & 0x000000ff) >> 0)))
1201 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
1202 (((y) << 12) & 0xfff00000) | \
1203 (((y) << 0) & 0x000000ff)))
1209 /* #define, not typedef, as quad_t exists as a struct on some systems */
1210 #define quad_t long long
1211 #define u_quad_t unsigned long long
1212 #define strtoq strtoll
1213 #define strtouq strtoull
1216 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
1217 #if defined(__NetBSD__) || defined(__minix)
1218 quad_t
strtoq(const char *, char **, int);
1219 u_quad_t
strtouq(const char *, char **, int);
1222 #endif /* !__NETBSD_COMPAT_DEFS_H__ */