1 /* $NetBSD: compat_defs.h,v 1.83 2012/01/21 20:05:27 tsutsui 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. */
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 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
78 /* We don't include <grp.h> either */
81 /* Assume an ANSI compiler for the host. */
93 /* Some things usually in BSD <sys/cdefs.h>. */
96 #define __CONCAT(x,y) x ## y
98 #if !defined(__attribute__) && !defined(__GNUC__)
99 #define __attribute__(x)
101 #if !defined(__packed)
102 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
103 #define __packed __attribute__((__packed__))
104 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
105 #define __packed __attribute__((__packed__))
107 #define __packed error: no __packed for this compiler
109 #endif /* !__packed */
118 #define __printflike(x,y)
124 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
126 /* Dirent support. */
129 # if defined(__linux__) && defined(__USE_BSD)
136 # if defined(__DARWIN_UNIX03)
140 # define NAMLEN(dirent) (strlen((dirent)->d_name))
142 # define dirent direct
143 # define NAMLEN(dirent) ((dirent)->d_namlen)
145 # include <sys/ndir.h>
148 # include <sys/dir.h>
155 /* Type substitutes. */
158 typedef unsigned int id_t
;
162 typedef int socklen_t
;
166 typedef unsigned long u_long
;
170 typedef unsigned char u_char
;
174 typedef unsigned int u_int
;
178 typedef unsigned short u_short
;
181 /* Prototypes for replacement functions. */
184 long long int atoll(const char *);
188 int asprintf(char **, const char *, ...);
192 int asnprintf(char **, size_t, const char *, ...);
196 char *basename(char *);
199 #if !HAVE_DECL_OPTIND
200 int getopt(int, char *const *, const char *);
202 extern int optind
, opterr
, optopt
;
206 char *dirname(char *);
211 #define dirfd(dirp) ((dirp)->dd_fd)
212 #elif HAVE_DIR___DD_FD
213 #define dirfd(dirp) ((dirp)->__dd_fd)
215 /*XXX: Very hacky but no other way to bring this into scope w/o defining
216 _NETBSD_SOURCE which we're avoiding. */
219 int dd_fd
; /* file descriptor associated with directory */
220 long dd_loc
; /* offset in current buffer */
221 long dd_size
; /* amount of data returned by getdents */
222 char *dd_buf
; /* data buffer */
223 int dd_len
; /* size of data buffer */
224 off_t dd_seek
; /* magic cookie returned by getdents */
225 long dd_rewind
; /* magic cookie for rewinding */
226 int dd_flags
; /* flags for readdir */
227 void *dd_lock
; /* lock for concurrent access */
229 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
231 #error cannot figure out how to turn a DIR * into a fd
237 void err(int, const char *, ...);
238 void errx(int, const char *, ...);
239 void warn(const char *, ...);
240 void warnx(const char *, ...);
241 void vwarnx(const char *, va_list);
245 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
246 size_t estrlcpy(char *, const char *, size_t);
247 size_t estrlcat(char *, const char *, size_t);
248 char *estrdup(const char *);
249 char *estrndup(const char *, size_t);
250 void *ecalloc(size_t, size_t);
251 void *emalloc(size_t);
252 void *erealloc(void *, size_t);
253 FILE *efopen(const char *, const char *);
254 int easprintf(char **, const char *, ...);
255 int evasprintf(char **, const char *, va_list);
258 #if !HAVE_FGETLN || defined(__NetBSD__)
259 char *fgetln(FILE *, size_t *);
263 # define LOCK_SH 0x01
264 # define LOCK_EX 0x02
265 # define LOCK_NB 0x04
266 # define LOCK_UN 0x08
270 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__)
271 # define FPARSELN_UNESCESC 0x01
272 # define FPARSELN_UNESCCONT 0x02
273 # define FPARSELN_UNESCCOMM 0x04
274 # define FPARSELN_UNESCREST 0x08
275 # define FPARSELN_UNESCALL 0x0f
276 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
280 ssize_t
getdelim(char **, size_t *, int, FILE *);
281 ssize_t
getline(char **, size_t *, FILE *);
288 #if !HAVE_ISBLANK && !defined(isblank)
289 #define isblank(x) ((x) == ' ' || (x) == '\t')
292 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
294 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
295 (((x) << 8) & 0x00ff0000) | \
296 (((x) >> 8) & 0x0000ff00) | \
297 (((x) >> 24) & 0x000000ff))
299 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
300 ((u_int64_t)bswap32((x) >> 32)))
302 #if ! HAVE_DECL_BSWAP16
306 #define bswap16(x) __nbcompat_bswap16(x)
308 #if ! HAVE_DECL_BSWAP32
312 #define bswap32(x) __nbcompat_bswap32(x)
314 #if ! HAVE_DECL_BSWAP64
318 #define bswap64(x) __nbcompat_bswap64(x)
326 char *mkdtemp(char *);
329 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
330 /* This is a prototype for the internal function defined in
331 * src/lib/lib/stdio/gettemp.c */
332 int __nbcompat_gettemp(char *, int *, int);
336 ssize_t
pread(int, void *, size_t, off_t
);
340 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
342 /* Make them use our version */
343 # define heapsort __nbcompat_heapsort
345 char *flags_to_string(unsigned long, const char *);
346 int string_to_flags(char **, unsigned long *, unsigned long *);
349 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
350 * supply an implementation of one without the others -- some parts are
351 * libc internal and this varies from system to system.
353 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
354 * XXX host system has all of these functions, all of their interfaces
355 * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
357 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
358 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
359 /* Make them use our version */
360 # define user_from_uid __nbcompat_user_from_uid
361 # define uid_from_user __nbcompat_uid_from_user
362 # define pwcache_userdb __nbcompat_pwcache_userdb
363 # define group_from_gid __nbcompat_group_from_gid
364 # define gid_from_group __nbcompat_gid_from_group
365 # define pwcache_groupdb __nbcompat_pwcache_groupdb
368 #if !HAVE_DECL_UID_FROM_USER
369 int uid_from_user(const char *, uid_t
*);
372 #if !HAVE_DECL_USER_FROM_UID
373 const char *user_from_uid(uid_t
, int);
376 #if !HAVE_DECL_PWCACHE_USERDB
377 int pwcache_userdb(int (*)(int), void (*)(void),
378 struct passwd
* (*)(const char *), struct passwd
* (*)(uid_t
));
381 #if !HAVE_DECL_GID_FROM_GROUP
382 int gid_from_group(const char *, gid_t
*);
385 #if !HAVE_DECL_GROUP_FROM_GID
386 const char *group_from_gid(gid_t
, int);
389 #if !HAVE_DECL_PWCACHE_GROUPDB
390 int pwcache_groupdb(int (*)(int), void (*)(void),
391 struct group
* (*)(const char *), struct group
* (*)(gid_t
));
394 #if !HAVE_DECL_STRNDUP
395 char *strndup(const char *, size_t);
397 #if !HAVE_DECL_LCHFLAGS
398 int lchflags(const char *, unsigned long);
400 #if !HAVE_DECL_LCHMOD
401 int lchmod(const char *, mode_t
);
403 #if !HAVE_DECL_LCHOWN
404 int lchown(const char *, uid_t
, gid_t
);
408 ssize_t
pwrite(int, const void *, size_t, off_t
);
411 #if !HAVE_RAISE_DEFAULT_SIGNAL
412 int raise_default_signal(int);
416 int setenv(const char *, const char *, int);
419 #if !HAVE_DECL_SETGROUPENT
420 int setgroupent(int);
423 #if !HAVE_DECL_SETPASSENT
427 #if !HAVE_SETPROGNAME || defined(__NetBSD__)
428 const char *getprogname(void);
429 void setprogname(const char *);
433 int snprintf(char *, size_t, const char *, ...);
437 size_t strlcat(char *, const char *, size_t);
441 size_t strlcpy(char *, const char *, size_t);
445 void strmode(mode_t
, char *);
449 char *strndup(const char *, size_t);
452 #if !HAVE_STRSEP || defined(__NetBSD__)
453 char *strsep(char **, const char *);
456 #if !HAVE_DECL_STRSUFTOLL
457 long long strsuftoll(const char *, const char *, long long, long long);
458 long long strsuftollx(const char *, const char *,
459 long long, long long, char *, size_t);
463 long long strtoll(const char *, char **, int);
466 #if !HAVE_USER_FROM_UID
467 const char *user_from_uid(uid_t
, int);
470 #if !HAVE_GROUP_FROM_GID
471 const char *group_from_gid(gid_t
, int);
475 int vasprintf(char **, const char *, va_list);
479 int vasnprintf(char **, size_t, const char *, va_list);
483 int vsnprintf(char *, size_t, const char *, va_list);
487 * getmode() and setmode() are always defined, as these function names
488 * exist but with very different meanings on other OS's. The compat
489 * versions here simply accept an octal mode number; the "u+x,g-w" type
490 * of syntax is not accepted.
493 #define getmode __nbcompat_getmode
494 #define setmode __nbcompat_setmode
496 mode_t
getmode(const void *, mode_t
);
497 void *setmode(const char *);
499 /* Eliminate assertions embedded in binaries. */
502 #define _DIAGASSERT(x)
504 /* Various sources use this */
506 #define __RCSID(x) struct XXXNETBSD_RCSID
510 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
511 #undef __KERNEL_RCSID
512 #define __KERNEL_RCSID(x,y)
514 /* Heimdal expects this one. */
519 /* Some definitions not available on all systems. */
522 #define __inline inline
542 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */
579 #endif /* char is an 8-bit type */
580 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
581 defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
582 #error "Don't know how to define PRI[diouxX]8"
584 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
585 defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
586 #error "Don't know how to define SCN[diouxX]8"
589 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */
626 #endif /* short is a 16-bit type */
627 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
628 defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
629 #error "Don't know how to define PRI[diouxX]16"
631 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
632 defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
633 #error "Don't know how to define SCN[diouxX]16"
636 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
673 #endif /* int is a 32-bit type */
674 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
711 #endif /* long is a 32-bit type */
712 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
713 defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
714 #error "Don't know how to define PRI[diouxX]32"
716 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
717 defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
718 #error "Don't know how to define SCN[diouxX]32"
721 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
758 #endif /* long is a 64-bit type */
759 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
796 #endif /* long long is a 64-bit type */
797 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
798 defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
799 #error "Don't know how to define PRI[diouxX]64"
801 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
802 defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
803 #error "Don't know how to define SCN[diouxX]64"
809 #define UID_MAX 32767
812 #define GID_MAX UID_MAX
816 #define UQUAD_MAX ((u_quad_t)-1)
819 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
822 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
825 #define ULLONG_MAX ((unsigned long long)-1)
828 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
831 #define LLONG_MIN ((long long)(~LLONG_MAX))
836 /* The host's _PATH_BSHELL might be broken, so override it. */
838 #define _PATH_BSHELL PATH_BSHELL
839 #ifndef _PATH_DEFPATH
840 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
843 #define _PATH_DEV "/dev/"
845 #ifndef _PATH_DEVNULL
846 #define _PATH_DEVNULL _PATH_DEV "null"
849 #define _PATH_TMP "/tmp/"
851 #ifndef _PATH_DEFTAPE
852 #define _PATH_DEFTAPE "/dev/nrst0"
855 #define _PATH_VI "/usr/bin/vi"
860 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
861 #define SIZE_MAX SIZE_T_MAX
865 #define UINT8_MAX 0xffU
869 #define UINT16_MAX 0xffffU
873 #define UINT32_MAX 0xffffffffU
882 # ifndef alloca /* predefined by HP cc +Olibcalls */
888 /* avoid prototype conflicts with host */
889 #define cgetcap __nbcompat_cgetcap
890 #define cgetclose __nbcompat_cgetclose
891 #define cgetent __nbcompat_cgetent
892 #define cgetfirst __nbcompat_cgetfirst
893 #define cgetmatch __nbcompat_cgetmatch
894 #define cgetnext __nbcompat_cgetnext
895 #define cgetnum __nbcompat_cgetnum
896 #define cgetset __nbcompat_cgetset
897 #define cgetstr __nbcompat_cgetstr
898 #define cgetustr __nbcompat_cgetustr
900 char *cgetcap(char *, const char *, int);
902 int cgetent(char **, const char * const *, const char *);
903 int cgetfirst(char **, const char * const *);
904 int cgetmatch(const char *, const char *);
905 int cgetnext(char **, const char * const *);
906 int cgetnum(char *, const char *, long *);
907 int cgetset(const char *);
908 int cgetstr(char *, const char *, char **);
909 int cgetustr(char *, const char *, char **);
914 #if !HAVE_DECL_HTOBE16
915 #define htobe16(x) (x)
917 #if !HAVE_DECL_HTOBE32
918 #define htobe32(x) (x)
920 #if !HAVE_DECL_HTOBE64
921 #define htobe64(x) (x)
923 #if !HAVE_DECL_HTOLE16
924 #define htole16(x) bswap16((u_int16_t)(x))
926 #if !HAVE_DECL_HTOLE32
927 #define htole32(x) bswap32((u_int32_t)(x))
929 #if !HAVE_DECL_HTOLE64
930 #define htole64(x) bswap64((u_int64_t)(x))
933 #if !HAVE_DECL_HTOBE16
934 #define htobe16(x) bswap16((u_int16_t)(x))
936 #if !HAVE_DECL_HTOBE32
937 #define htobe32(x) bswap32((u_int32_t)(x))
939 #if !HAVE_DECL_HTOBE64
940 #define htobe64(x) bswap64((u_int64_t)(x))
942 #if !HAVE_DECL_HTOLE16
943 #define htole16(x) (x)
945 #if !HAVE_DECL_HTOLE32
946 #define htole32(x) (x)
948 #if !HAVE_DECL_HTOLE64
949 #define htole64(x) (x)
952 #if !HAVE_DECL_BE16TOH
953 #define be16toh(x) htobe16(x)
955 #if !HAVE_DECL_BE32TOH
956 #define be32toh(x) htobe32(x)
958 #if !HAVE_DECL_BE64TOH
959 #define be64toh(x) htobe64(x)
961 #if !HAVE_DECL_LE16TOH
962 #define le16toh(x) htole16(x)
964 #if !HAVE_DECL_LE32TOH
965 #define le32toh(x) htole32(x)
967 #if !HAVE_DECL_LE64TOH
968 #define le64toh(x) htole64(x)
971 #define __GEN_ENDIAN_ENC(bits, endian) \
973 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
975 u = hto ## endian ## bits (u); \
976 memcpy(dst, &u, sizeof(u)); \
978 #if !HAVE_DECL_BE16ENC
979 __GEN_ENDIAN_ENC(16, be
)
981 #if !HAVE_DECL_BE32ENC
982 __GEN_ENDIAN_ENC(32, be
)
984 #if !HAVE_DECL_BE64ENC
985 __GEN_ENDIAN_ENC(64, be
)
987 #if !HAVE_DECL_LE16ENC
988 __GEN_ENDIAN_ENC(16, le
)
990 #if !HAVE_DECL_LE32ENC
991 __GEN_ENDIAN_ENC(32, le
)
993 #if !HAVE_DECL_LE64ENC
994 __GEN_ENDIAN_ENC(64, le
)
996 #undef __GEN_ENDIAN_ENC
998 #define __GEN_ENDIAN_DEC(bits, endian) \
999 static uint ## bits ## _t \
1000 endian ## bits ## dec(const void *buf) \
1002 uint ## bits ## _t u; \
1003 memcpy(&u, buf, sizeof(u)); \
1004 return endian ## bits ## toh (u); \
1006 #if !HAVE_DECL_BE16DEC
1007 __GEN_ENDIAN_DEC(16, be
)
1009 #if !HAVE_DECL_BE32DEC
1010 __GEN_ENDIAN_DEC(32, be
)
1012 #if !HAVE_DECL_BE64DEC
1013 __GEN_ENDIAN_DEC(64, be
)
1015 #if !HAVE_DECL_LE16DEC
1016 __GEN_ENDIAN_DEC(16, le
)
1018 #if !HAVE_DECL_LE32DEC
1019 __GEN_ENDIAN_DEC(32, le
)
1021 #if !HAVE_DECL_LE64DEC
1022 __GEN_ENDIAN_DEC(64, le
)
1024 #undef __GEN_ENDIAN_DEC
1032 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
1034 #ifdef MAP_ANONYMOUS
1035 #define MAP_ANON MAP_ANONYMOUS
1042 #undef LITTLE_ENDIAN
1044 #define BIG_ENDIAN 4321
1045 #define LITTLE_ENDIAN 1234
1046 #define PDP_ENDIAN 3412
1050 #define BYTE_ORDER BIG_ENDIAN
1052 #define BYTE_ORDER LITTLE_ENDIAN
1055 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
1057 #define DEV_BSIZE (1 << 9)
1061 #define MIN(a,b) ((a) < (b) ? (a) : (b))
1062 #define MAX(a,b) ((a) > (b) ? (a) : (b))
1065 #define MAXBSIZE (64 * 1024)
1071 #define MAXPHYS (64 * 1024)
1074 /* XXX needed by makefs; this should be done in a better way */
1076 #define btodb(x) ((x) << 9)
1082 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1083 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1084 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1085 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1088 #define powerof2(x) ((((x)-1)&(x))==0)
1092 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1097 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
1100 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
1104 #define S_ISTXT S_ISVTX
1110 /* Protected by _NETBSD_SOURCE otherwise. */
1111 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
1112 #define UF_SETTABLE 0x0000ffff
1113 #define UF_NODUMP 0x00000001
1114 #define UF_IMMUTABLE 0x00000002
1115 #define UF_APPEND 0x00000004
1116 #define UF_OPAQUE 0x00000008
1117 #define SF_SETTABLE 0xffff0000
1118 #define SF_ARCHIVED 0x00010000
1119 #define SF_IMMUTABLE 0x00020000
1120 #define SF_APPEND 0x00040000
1123 /* <sys/syslimits.h> */
1126 #define LINE_MAX 2048
1132 #define timercmp(tvp, uvp, cmp) \
1133 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
1134 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1135 ((tvp)->tv_sec cmp (uvp)->tv_sec))
1138 #define timeradd(tvp, uvp, vvp) \
1140 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
1141 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
1142 if ((vvp)->tv_usec >= 1000000) { \
1144 (vvp)->tv_usec -= 1000000; \
1146 } while (/* CONSTCOND */ 0)
1149 #define timersub(tvp, uvp, vvp) \
1151 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
1152 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
1153 if ((vvp)->tv_usec < 0) { \
1155 (vvp)->tv_usec += 1000000; \
1157 } while (/* CONSTCOND */ 0)
1165 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
1170 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
1171 (((x) & 0x000000ff) >> 0)))
1175 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
1176 (((y) << 12) & 0xfff00000) | \
1177 (((y) << 0) & 0x000000ff)))
1183 /* #define, not typedef, as quad_t exists as a struct on some systems */
1184 #define quad_t long long
1185 #define u_quad_t unsigned long long
1186 #define strtoq strtoll
1187 #define strtouq strtoull
1190 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
1192 quad_t strtoq
__P((const char *, char **, int));
1193 u_quad_t strtouq
__P((const char *, char **, int));
1196 #endif /* !__NETBSD_COMPAT_DEFS_H__ */