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