1 /* $NetBSD: compat_defs.h,v 1.86 2012/06/04 10:18:01 joerg 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 #error _NETBSD_SOURCE is *not* to be defined.
69 /* Need this since we can't depend on NetBSD's version to be around */
73 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
75 #undef __predict_false
76 #define __predict_false(x) (x)
78 #define __predict_true(x) (x)
80 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
83 /* We don't include <grp.h> either */
86 /* Assume an ANSI compiler for the host. */
98 /* Some things usually in BSD <sys/cdefs.h>. */
101 #define __CONCAT(x,y) x ## y
103 #if !defined(__attribute__) && !defined(__GNUC__)
104 #define __attribute__(x)
106 #if !defined(__packed)
107 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
108 #define __packed __attribute__((__packed__))
109 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
110 #define __packed __attribute__((__packed__))
112 #define __packed error: no __packed for this compiler
114 #endif /* !__packed */
123 #define __printflike(x,y)
129 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
131 /* Dirent support. */
134 # if defined(__linux__) && defined(__USE_BSD)
141 # if defined(__DARWIN_UNIX03)
145 # define NAMLEN(dirent) (strlen((dirent)->d_name))
147 # define dirent direct
148 # define NAMLEN(dirent) ((dirent)->d_namlen)
150 # include <sys/ndir.h>
153 # include <sys/dir.h>
160 /* Type substitutes. */
163 typedef unsigned int id_t
;
167 typedef int socklen_t
;
171 typedef unsigned long u_long
;
175 typedef unsigned char u_char
;
179 typedef unsigned int u_int
;
183 typedef unsigned short u_short
;
186 /* Prototypes for replacement functions. */
189 long long int atoll(const char *);
193 int asprintf(char **, const char *, ...);
197 int asnprintf(char **, size_t, const char *, ...);
201 char *basename(char *);
204 #if !HAVE_DECL_OPTIND
205 int getopt(int, char *const *, const char *);
207 extern int optind
, opterr
, optopt
;
211 char *dirname(char *);
216 #define dirfd(dirp) ((dirp)->dd_fd)
217 #elif HAVE_DIR___DD_FD
218 #define dirfd(dirp) ((dirp)->__dd_fd)
220 /*XXX: Very hacky but no other way to bring this into scope w/o defining
221 _NETBSD_SOURCE which we're avoiding. */
222 #if defined(__NetBSD__) || defined(__minix)
224 int dd_fd
; /* file descriptor associated with directory */
225 long dd_loc
; /* offset in current buffer */
226 long dd_size
; /* amount of data returned by getdents */
227 char *dd_buf
; /* data buffer */
228 int dd_len
; /* size of data buffer */
229 off_t dd_seek
; /* magic cookie returned by getdents */
230 long dd_rewind
; /* magic cookie for rewinding */
231 int dd_flags
; /* flags for readdir */
232 void *dd_lock
; /* lock for concurrent access */
234 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
236 #error cannot figure out how to turn a DIR * into a fd
242 void err(int, const char *, ...);
243 void errx(int, const char *, ...);
244 void warn(const char *, ...);
245 void warnx(const char *, ...);
246 void vwarnx(const char *, va_list);
250 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
251 size_t estrlcpy(char *, const char *, size_t);
252 size_t estrlcat(char *, const char *, size_t);
253 char *estrdup(const char *);
254 char *estrndup(const char *, size_t);
255 void *ecalloc(size_t, size_t);
256 void *emalloc(size_t);
257 void *erealloc(void *, size_t);
258 FILE *efopen(const char *, const char *);
259 int easprintf(char **, const char *, ...);
260 int evasprintf(char **, const char *, va_list);
263 #if !HAVE_FGETLN || defined(__NetBSD__) || defined(__minix)
264 char *fgetln(FILE *, size_t *);
268 # define LOCK_SH 0x01
269 # define LOCK_EX 0x02
270 # define LOCK_NB 0x04
271 # define LOCK_UN 0x08
275 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) || defined(__minix)
276 # define FPARSELN_UNESCESC 0x01
277 # define FPARSELN_UNESCCONT 0x02
278 # define FPARSELN_UNESCCOMM 0x04
279 # define FPARSELN_UNESCREST 0x08
280 # define FPARSELN_UNESCALL 0x0f
281 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
285 ssize_t
getdelim(char **, size_t *, int, FILE *);
286 ssize_t
getline(char **, size_t *, FILE *);
293 #if !HAVE_ISBLANK && !defined(isblank)
294 #define isblank(x) ((x) == ' ' || (x) == '\t')
297 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
299 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
300 (((x) << 8) & 0x00ff0000) | \
301 (((x) >> 8) & 0x0000ff00) | \
302 (((x) >> 24) & 0x000000ff))
304 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
305 ((u_int64_t)bswap32((x) >> 32)))
307 #if ! HAVE_DECL_BSWAP16
311 #define bswap16(x) __nbcompat_bswap16(x)
313 #if ! HAVE_DECL_BSWAP32
317 #define bswap32(x) __nbcompat_bswap32(x)
319 #if ! HAVE_DECL_BSWAP64
323 #define bswap64(x) __nbcompat_bswap64(x)
331 char *mkdtemp(char *);
334 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
335 /* This is a prototype for the internal function defined in
336 * src/lib/lib/stdio/gettemp.c */
337 int __nbcompat_gettemp(char *, int *, int);
341 ssize_t
pread(int, void *, size_t, off_t
);
345 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
347 /* Make them use our version */
348 # define heapsort __nbcompat_heapsort
350 char *flags_to_string(unsigned long, const char *);
351 int string_to_flags(char **, unsigned long *, unsigned long *);
354 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
355 * supply an implementation of one without the others -- some parts are
356 * libc internal and this varies from system to system.
358 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
359 * XXX host system has all of these functions, all of their interfaces
360 * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
362 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
363 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
364 /* Make them use our version */
365 # define user_from_uid __nbcompat_user_from_uid
366 # define uid_from_user __nbcompat_uid_from_user
367 # define pwcache_userdb __nbcompat_pwcache_userdb
368 # define group_from_gid __nbcompat_group_from_gid
369 # define gid_from_group __nbcompat_gid_from_group
370 # define pwcache_groupdb __nbcompat_pwcache_groupdb
373 #if !HAVE_DECL_UID_FROM_USER
374 int uid_from_user(const char *, uid_t
*);
377 #if !HAVE_DECL_USER_FROM_UID
378 const char *user_from_uid(uid_t
, int);
381 #if !HAVE_DECL_PWCACHE_USERDB
382 int pwcache_userdb(int (*)(int), void (*)(void),
383 struct passwd
* (*)(const char *), struct passwd
* (*)(uid_t
));
386 #if !HAVE_DECL_GID_FROM_GROUP
387 int gid_from_group(const char *, gid_t
*);
390 #if !HAVE_DECL_GROUP_FROM_GID
391 const char *group_from_gid(gid_t
, int);
394 #if !HAVE_DECL_PWCACHE_GROUPDB
395 int pwcache_groupdb(int (*)(int), void (*)(void),
396 struct group
* (*)(const char *), struct group
* (*)(gid_t
));
399 #if !HAVE_DECL_STRNDUP
400 char *strndup(const char *, size_t);
402 #if !HAVE_DECL_LCHFLAGS
403 int lchflags(const char *, unsigned long);
405 #if !HAVE_DECL_LCHMOD
406 int lchmod(const char *, mode_t
);
408 #if !HAVE_DECL_LCHOWN
409 int lchown(const char *, uid_t
, gid_t
);
413 ssize_t
pwrite(int, const void *, size_t, off_t
);
416 #if !HAVE_RAISE_DEFAULT_SIGNAL
417 int raise_default_signal(int);
421 int setenv(const char *, const char *, int);
424 #if !HAVE_DECL_SETGROUPENT
425 int setgroupent(int);
428 #if !HAVE_DECL_SETPASSENT
432 #if !HAVE_SETPROGNAME || defined(__NetBSD__) || defined(__minix)
433 const char *getprogname(void);
434 void setprogname(const char *);
438 int snprintf(char *, size_t, const char *, ...);
442 size_t strlcat(char *, const char *, size_t);
446 size_t strlcpy(char *, const char *, size_t);
450 void strmode(mode_t
, char *);
454 char *strndup(const char *, size_t);
457 #if !HAVE_STRSEP || defined(__NetBSD__) || defined(__minix)
458 char *strsep(char **, const char *);
461 #if !HAVE_DECL_STRSUFTOLL
462 long long strsuftoll(const char *, const char *, long long, long long);
463 long long strsuftollx(const char *, const char *,
464 long long, long long, char *, size_t);
468 long long strtoll(const char *, char **, int);
471 #if !HAVE_USER_FROM_UID
472 const char *user_from_uid(uid_t
, int);
475 #if !HAVE_GROUP_FROM_GID
476 const char *group_from_gid(gid_t
, int);
480 int vasprintf(char **, const char *, va_list);
484 int vasnprintf(char **, size_t, const char *, va_list);
488 int vsnprintf(char *, size_t, const char *, va_list);
492 * getmode() and setmode() are always defined, as these function names
493 * exist but with very different meanings on other OS's. The compat
494 * versions here simply accept an octal mode number; the "u+x,g-w" type
495 * of syntax is not accepted.
498 #define getmode __nbcompat_getmode
499 #define setmode __nbcompat_setmode
501 mode_t
getmode(const void *, mode_t
);
502 void *setmode(const char *);
504 /* Eliminate assertions embedded in binaries. */
507 #define _DIAGASSERT(x)
509 /* Various sources use this */
511 #define __RCSID(x) struct XXXNETBSD_RCSID
515 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
516 #undef __KERNEL_RCSID
517 #define __KERNEL_RCSID(x,y)
519 /* Heimdal expects this one. */
524 /* Some definitions not available on all systems. */
527 #define __inline inline
547 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */
584 #endif /* char is an 8-bit type */
585 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
586 defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
587 #error "Don't know how to define PRI[diouxX]8"
589 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
590 defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
591 #error "Don't know how to define SCN[diouxX]8"
594 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */
631 #endif /* short is a 16-bit type */
632 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
633 defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
634 #error "Don't know how to define PRI[diouxX]16"
636 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
637 defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
638 #error "Don't know how to define SCN[diouxX]16"
641 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
678 #endif /* int is a 32-bit type */
679 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
716 #endif /* long is a 32-bit type */
717 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
718 defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
719 #error "Don't know how to define PRI[diouxX]32"
721 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
722 defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
723 #error "Don't know how to define SCN[diouxX]32"
726 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
763 #endif /* long is a 64-bit type */
764 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
801 #endif /* long long is a 64-bit type */
802 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
803 defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
804 #error "Don't know how to define PRI[diouxX]64"
806 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
807 defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
808 #error "Don't know how to define SCN[diouxX]64"
814 #define UID_MAX 32767
817 #define GID_MAX UID_MAX
821 #define UQUAD_MAX ((u_quad_t)-1)
824 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
827 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
830 #define ULLONG_MAX ((unsigned long long)-1)
833 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
836 #define LLONG_MIN ((long long)(~LLONG_MAX))
841 /* The host's _PATH_BSHELL might be broken, so override it. */
843 #define _PATH_BSHELL PATH_BSHELL
844 #ifndef _PATH_DEFPATH
845 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
848 #define _PATH_DEV "/dev/"
850 #ifndef _PATH_DEVNULL
851 #define _PATH_DEVNULL _PATH_DEV "null"
854 #define _PATH_TMP "/tmp/"
856 #ifndef _PATH_DEFTAPE
857 #define _PATH_DEFTAPE "/dev/nrst0"
860 #define _PATH_VI "/usr/bin/vi"
865 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
866 #define SIZE_MAX SIZE_T_MAX
870 #define UINT8_MAX 0xffU
874 #define UINT16_MAX 0xffffU
878 #define UINT32_MAX 0xffffffffU
887 # ifndef alloca /* predefined by HP cc +Olibcalls */
893 /* avoid prototype conflicts with host */
894 #define cgetcap __nbcompat_cgetcap
895 #define cgetclose __nbcompat_cgetclose
896 #define cgetent __nbcompat_cgetent
897 #define cgetfirst __nbcompat_cgetfirst
898 #define cgetmatch __nbcompat_cgetmatch
899 #define cgetnext __nbcompat_cgetnext
900 #define cgetnum __nbcompat_cgetnum
901 #define cgetset __nbcompat_cgetset
902 #define cgetstr __nbcompat_cgetstr
903 #define cgetustr __nbcompat_cgetustr
905 char *cgetcap(char *, const char *, int);
907 int cgetent(char **, const char * const *, const char *);
908 int cgetfirst(char **, const char * const *);
909 int cgetmatch(const char *, const char *);
910 int cgetnext(char **, const char * const *);
911 int cgetnum(char *, const char *, long *);
912 int cgetset(const char *);
913 int cgetstr(char *, const char *, char **);
914 int cgetustr(char *, const char *, char **);
919 #if !HAVE_DECL_HTOBE16
920 #define htobe16(x) (x)
922 #if !HAVE_DECL_HTOBE32
923 #define htobe32(x) (x)
925 #if !HAVE_DECL_HTOBE64
926 #define htobe64(x) (x)
928 #if !HAVE_DECL_HTOLE16
929 #define htole16(x) bswap16((u_int16_t)(x))
931 #if !HAVE_DECL_HTOLE32
932 #define htole32(x) bswap32((u_int32_t)(x))
934 #if !HAVE_DECL_HTOLE64
935 #define htole64(x) bswap64((u_int64_t)(x))
938 #if !HAVE_DECL_HTOBE16
939 #define htobe16(x) bswap16((u_int16_t)(x))
941 #if !HAVE_DECL_HTOBE32
942 #define htobe32(x) bswap32((u_int32_t)(x))
944 #if !HAVE_DECL_HTOBE64
945 #define htobe64(x) bswap64((u_int64_t)(x))
947 #if !HAVE_DECL_HTOLE16
948 #define htole16(x) (x)
950 #if !HAVE_DECL_HTOLE32
951 #define htole32(x) (x)
953 #if !HAVE_DECL_HTOLE64
954 #define htole64(x) (x)
957 #if !HAVE_DECL_BE16TOH
958 #define be16toh(x) htobe16(x)
960 #if !HAVE_DECL_BE32TOH
961 #define be32toh(x) htobe32(x)
963 #if !HAVE_DECL_BE64TOH
964 #define be64toh(x) htobe64(x)
966 #if !HAVE_DECL_LE16TOH
967 #define le16toh(x) htole16(x)
969 #if !HAVE_DECL_LE32TOH
970 #define le32toh(x) htole32(x)
972 #if !HAVE_DECL_LE64TOH
973 #define le64toh(x) htole64(x)
976 #define __GEN_ENDIAN_ENC(bits, endian) \
978 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
980 u = hto ## endian ## bits (u); \
981 memcpy(dst, &u, sizeof(u)); \
983 #if !HAVE_DECL_BE16ENC
984 __GEN_ENDIAN_ENC(16, be
)
986 #if !HAVE_DECL_BE32ENC
987 __GEN_ENDIAN_ENC(32, be
)
989 #if !HAVE_DECL_BE64ENC
990 __GEN_ENDIAN_ENC(64, be
)
992 #if !HAVE_DECL_LE16ENC
993 __GEN_ENDIAN_ENC(16, le
)
995 #if !HAVE_DECL_LE32ENC
996 __GEN_ENDIAN_ENC(32, le
)
998 #if !HAVE_DECL_LE64ENC
999 __GEN_ENDIAN_ENC(64, le
)
1001 #undef __GEN_ENDIAN_ENC
1003 #define __GEN_ENDIAN_DEC(bits, endian) \
1004 static uint ## bits ## _t \
1005 endian ## bits ## dec(const void *buf) \
1007 uint ## bits ## _t u; \
1008 memcpy(&u, buf, sizeof(u)); \
1009 return endian ## bits ## toh (u); \
1011 #if !HAVE_DECL_BE16DEC
1012 __GEN_ENDIAN_DEC(16, be
)
1014 #if !HAVE_DECL_BE32DEC
1015 __GEN_ENDIAN_DEC(32, be
)
1017 #if !HAVE_DECL_BE64DEC
1018 __GEN_ENDIAN_DEC(64, be
)
1020 #if !HAVE_DECL_LE16DEC
1021 __GEN_ENDIAN_DEC(16, le
)
1023 #if !HAVE_DECL_LE32DEC
1024 __GEN_ENDIAN_DEC(32, le
)
1026 #if !HAVE_DECL_LE64DEC
1027 __GEN_ENDIAN_DEC(64, le
)
1029 #undef __GEN_ENDIAN_DEC
1037 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
1039 #ifdef MAP_ANONYMOUS
1040 #define MAP_ANON MAP_ANONYMOUS
1047 #undef LITTLE_ENDIAN
1049 #define BIG_ENDIAN 4321
1050 #define LITTLE_ENDIAN 1234
1051 #define PDP_ENDIAN 3412
1055 #define BYTE_ORDER BIG_ENDIAN
1057 #define BYTE_ORDER LITTLE_ENDIAN
1060 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
1062 #define DEV_BSIZE (1 << 9)
1066 #define MIN(a,b) ((a) < (b) ? (a) : (b))
1067 #define MAX(a,b) ((a) > (b) ? (a) : (b))
1070 #define MAXBSIZE (64 * 1024)
1076 #define MAXPHYS (64 * 1024)
1079 /* XXX needed by makefs; this should be done in a better way */
1081 #define btodb(x) ((x) << 9)
1087 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1088 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1089 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1090 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1093 #define powerof2(x) ((((x)-1)&(x))==0)
1097 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1102 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
1105 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
1109 #define S_ISTXT S_ISVTX
1115 /* Protected by _NETBSD_SOURCE otherwise. */
1116 #if HAVE_STRUCT_STAT_ST_FLAGS && (defined(__NetBSD__) || defined(__minix))
1117 #define UF_SETTABLE 0x0000ffff
1118 #define UF_NODUMP 0x00000001
1119 #define UF_IMMUTABLE 0x00000002
1120 #define UF_APPEND 0x00000004
1121 #define UF_OPAQUE 0x00000008
1122 #define SF_SETTABLE 0xffff0000
1123 #define SF_ARCHIVED 0x00010000
1124 #define SF_IMMUTABLE 0x00020000
1125 #define SF_APPEND 0x00040000
1128 /* <sys/syslimits.h> */
1131 #define LINE_MAX 2048
1137 #define timercmp(tvp, uvp, cmp) \
1138 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
1139 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1140 ((tvp)->tv_sec cmp (uvp)->tv_sec))
1143 #define timeradd(tvp, uvp, vvp) \
1145 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
1146 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
1147 if ((vvp)->tv_usec >= 1000000) { \
1149 (vvp)->tv_usec -= 1000000; \
1151 } while (/* CONSTCOND */ 0)
1154 #define timersub(tvp, uvp, vvp) \
1156 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
1157 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
1158 if ((vvp)->tv_usec < 0) { \
1160 (vvp)->tv_usec += 1000000; \
1162 } while (/* CONSTCOND */ 0)
1170 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
1175 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
1176 (((x) & 0x000000ff) >> 0)))
1180 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
1181 (((y) << 12) & 0xfff00000) | \
1182 (((y) << 0) & 0x000000ff)))
1188 /* #define, not typedef, as quad_t exists as a struct on some systems */
1189 #define quad_t long long
1190 #define u_quad_t unsigned long long
1191 #define strtoq strtoll
1192 #define strtouq strtoull
1195 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
1196 #if defined(__NetBSD__) || defined(__minix)
1197 quad_t
strtoq(const char *, char **, int);
1198 u_quad_t
strtouq(const char *, char **, int);
1201 #endif /* !__NETBSD_COMPAT_DEFS_H__ */