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