compat_defs.h revision 1.55 1 /* $NetBSD: compat_defs.h,v 1.55 2006/10/07 22:00:22 apb 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_STRMODE
372 void strmode(mode_t, char *);
373 #endif
374
375 #if !HAVE_STRSEP || defined(__NetBSD__)
376 char *strsep(char **, const char *);
377 #endif
378
379 #if !HAVE_DECL_STRSUFTOLL
380 long long strsuftoll(const char *, const char *, long long, long long);
381 long long strsuftollx(const char *, const char *,
382 long long, long long, char *, size_t);
383 #endif
384
385 #if !HAVE_STRTOLL
386 long long strtoll(const char *, char **, int);
387 #endif
388
389 #if !HAVE_USER_FROM_UID
390 const char *user_from_uid(uid_t, int);
391 #endif
392
393 #if !HAVE_GROUP_FROM_GID
394 const char *group_from_gid(gid_t, int);
395 #endif
396
397 #if !HAVE_VASPRINTF
398 int vasprintf(char **, const char *, va_list);
399 #endif
400
401 #if !HAVE_VASNPRINTF
402 int vasnprintf(char **, size_t, const char *, va_list);
403 #endif
404
405 #if !HAVE_VSNPRINTF
406 int vsnprintf(char *, size_t, const char *, va_list);
407 #endif
408
409 /*
410 * getmode() and setmode() are always defined, as these function names
411 * exist but with very different meanings on other OS's. The compat
412 * versions here simply accept an octal mode number; the "u+x,g-w" type
413 * of syntax is not accepted.
414 */
415
416 #define getmode __nbcompat_getmode
417 #define setmode __nbcompat_setmode
418
419 mode_t getmode(const void *, mode_t);
420 void *setmode(const char *);
421
422 /* Eliminate assertions embedded in binaries. */
423
424 #undef _DIAGASSERT
425 #define _DIAGASSERT(x)
426
427 /* Various sources use this */
428 #undef __RCSID
429 #define __RCSID(x)
430 #undef __SCCSID
431 #define __SCCSID(x)
432 #undef __COPYRIGHT
433 #define __COPYRIGHT(x)
434 #undef __KERNEL_RCSID
435 #define __KERNEL_RCSID(x,y)
436
437 /* Heimdal expects this one. */
438
439 #undef RCSID
440 #define RCSID(x)
441
442 /* Some definitions not available on all systems. */
443
444 /* <errno.h> */
445
446 #ifndef EFTYPE
447 #define EFTYPE EIO
448 #endif
449
450 /* <fcntl.h> */
451
452 #ifndef O_EXLOCK
453 #define O_EXLOCK 0
454 #endif
455 #ifndef O_SHLOCK
456 #define O_SHLOCK 0
457 #endif
458
459 /* <limits.h> */
460
461 #ifndef UID_MAX
462 #define UID_MAX 32767
463 #endif
464 #ifndef GID_MAX
465 #define GID_MAX UID_MAX
466 #endif
467
468 #ifndef UQUAD_MAX
469 #define UQUAD_MAX ((u_quad_t)-1)
470 #endif
471 #ifndef QUAD_MAX
472 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
473 #endif
474 #ifndef QUAD_MIN
475 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
476 #endif
477 #ifndef ULLONG_MAX
478 #define ULLONG_MAX ((unsigned long long)-1)
479 #endif
480 #ifndef LLONG_MAX
481 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
482 #endif
483 #ifndef LLONG_MIN
484 #define LLONG_MIN ((long long)(~LLONG_MAX))
485 #endif
486
487 /* <paths.h> */
488
489 /* The host's _PATH_BSHELL might be broken, so override it. */
490 #undef _PATH_BSHELL
491 #define _PATH_BSHELL PATH_BSHELL
492 #ifndef _PATH_DEFPATH
493 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
494 #endif
495 #ifndef _PATH_DEV
496 #define _PATH_DEV "/dev/"
497 #endif
498 #ifndef _PATH_DEVNULL
499 #define _PATH_DEVNULL _PATH_DEV "null"
500 #endif
501 #ifndef _PATH_TMP
502 #define _PATH_TMP "/tmp/"
503 #endif
504 #ifndef _PATH_DEFTAPE
505 #define _PATH_DEFTAPE "/dev/nrst0"
506 #endif
507 #ifndef _PATH_VI
508 #define _PATH_VI "/usr/bin/vi"
509 #endif
510
511 /* <stdarg.h> */
512
513 #ifndef _BSD_VA_LIST_
514 #define _BSD_VA_LIST_ va_list
515 #endif
516
517 /* <stdint.h> */
518
519 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
520 #define SIZE_MAX SIZE_T_MAX
521 #endif
522
523 #ifndef UINT8_MAX
524 #define UINT8_MAX 0xffU
525 #endif
526
527 #ifndef UINT16_MAX
528 #define UINT16_MAX 0xffffU
529 #endif
530
531 #ifndef UINT32_MAX
532 #define UINT32_MAX 0xffffffffU
533 #endif
534
535 /* <stdlib.h> */
536
537 #ifndef __GNUC__
538 # if HAVE_ALLOCA_H
539 # include <alloca.h>
540 # else
541 # ifndef alloca /* predefined by HP cc +Olibcalls */
542 char *alloca ();
543 # endif
544 # endif
545 #endif
546
547 /* avoid prototype conflicts with host */
548 #define cgetcap __nbcompat_cgetcap
549 #define cgetclose __nbcompat_cgetclose
550 #define cgetent __nbcompat_cgetent
551 #define cgetfirst __nbcompat_cgetfirst
552 #define cgetmatch __nbcompat_cgetmatch
553 #define cgetnext __nbcompat_cgetnext
554 #define cgetnum __nbcompat_cgetnum
555 #define cgetset __nbcompat_cgetset
556 #define cgetstr __nbcompat_cgetstr
557 #define cgetustr __nbcompat_cgetustr
558
559 char *cgetcap(char *, const char *, int);
560 int cgetclose(void);
561 int cgetent(char **, const char * const *, const char *);
562 int cgetfirst(char **, const char * const *);
563 int cgetmatch(const char *, const char *);
564 int cgetnext(char **, const char * const *);
565 int cgetnum(char *, const char *, long *);
566 int cgetset(const char *);
567 int cgetstr(char *, const char *, char **);
568 int cgetustr(char *, const char *, char **);
569
570 /* <sys/endian.h> */
571
572 #if WORDS_BIGENDIAN
573 #if !HAVE_DECL_HTOBE16
574 #define htobe16(x) (x)
575 #endif
576 #if !HAVE_DECL_HTOBE32
577 #define htobe32(x) (x)
578 #endif
579 #if !HAVE_DECL_HTOBE64
580 #define htobe64(x) (x)
581 #endif
582 #if !HAVE_DECL_HTOLE16
583 #define htole16(x) bswap16((u_int16_t)(x))
584 #endif
585 #if !HAVE_DECL_HTOLE32
586 #define htole32(x) bswap32((u_int32_t)(x))
587 #endif
588 #if !HAVE_DECL_HTOLE64
589 #define htole64(x) bswap64((u_int64_t)(x))
590 #endif
591 #else
592 #if !HAVE_DECL_HTOBE16
593 #define htobe16(x) bswap16((u_int16_t)(x))
594 #endif
595 #if !HAVE_DECL_HTOBE32
596 #define htobe32(x) bswap32((u_int32_t)(x))
597 #endif
598 #if !HAVE_DECL_HTOBE64
599 #define htobe64(x) bswap64((u_int64_t)(x))
600 #endif
601 #if !HAVE_DECL_HTOLE16
602 #define htole16(x) (x)
603 #endif
604 #if !HAVE_DECL_HTOLE32
605 #define htole32(x) (x)
606 #endif
607 #if !HAVE_DECL_HTOLE64
608 #define htole64(x) (x)
609 #endif
610 #endif
611 #if !HAVE_DECL_BE16TOH
612 #define be16toh(x) htobe16(x)
613 #endif
614 #if !HAVE_DECL_BE32TOH
615 #define be32toh(x) htobe32(x)
616 #endif
617 #if !HAVE_DECL_BE64TOH
618 #define be64toh(x) htobe64(x)
619 #endif
620 #if !HAVE_DECL_LE16TOH
621 #define le16toh(x) htole16(x)
622 #endif
623 #if !HAVE_DECL_LE32TOH
624 #define le32toh(x) htole32(x)
625 #endif
626 #if !HAVE_DECL_LE64TOH
627 #define le64toh(x) htole64(x)
628 #endif
629
630 /* <sys/mman.h> */
631
632 #ifndef MAP_FILE
633 #define MAP_FILE 0
634 #endif
635
636 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
637 #ifndef MAP_ANON
638 #ifdef MAP_ANONYMOUS
639 #define MAP_ANON MAP_ANONYMOUS
640 #endif
641 #endif
642
643 /* <sys/param.h> */
644
645 #undef BIG_ENDIAN
646 #undef LITTLE_ENDIAN
647 #define BIG_ENDIAN 4321
648 #define LITTLE_ENDIAN 1234
649
650 #undef BYTE_ORDER
651 #if WORDS_BIGENDIAN
652 #define BYTE_ORDER BIG_ENDIAN
653 #else
654 #define BYTE_ORDER LITTLE_ENDIAN
655 #endif
656
657 #ifndef DEV_BSIZE
658 #define DEV_BSIZE (1 << 9)
659 #endif
660
661 #undef MIN
662 #undef MAX
663 #define MIN(a,b) ((a) < (b) ? (a) : (b))
664 #define MAX(a,b) ((a) > (b) ? (a) : (b))
665
666 #ifndef MAXBSIZE
667 #define MAXBSIZE (64 * 1024)
668 #endif
669 #ifndef MAXFRAG
670 #define MAXFRAG 8
671 #endif
672 #ifndef MAXPHYS
673 #define MAXPHYS (64 * 1024)
674 #endif
675
676 /* XXX needed by makefs; this should be done in a better way */
677 #undef btodb
678 #define btodb(x) ((x) << 9)
679
680 #undef setbit
681 #undef clrbit
682 #undef isset
683 #undef isclr
684 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
685 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
686 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
687 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
688
689 #ifndef powerof2
690 #define powerof2(x) ((((x)-1)&(x))==0)
691 #endif
692
693 #undef roundup
694 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
695
696 /* <sys/stat.h> */
697
698 #ifndef ALLPERMS
699 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
700 #endif
701 #ifndef DEFFILEMODE
702 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
703 #endif
704 #ifndef S_ISTXT
705 #ifdef S_ISVTX
706 #define S_ISTXT S_ISVTX
707 #else
708 #define S_ISTXT 0
709 #endif
710 #endif
711
712 /* Protected by _NETBSD_SOURCE otherwise. */
713 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__)
714 #define UF_SETTABLE 0x0000ffff
715 #define UF_NODUMP 0x00000001
716 #define UF_IMMUTABLE 0x00000002
717 #define UF_APPEND 0x00000004
718 #define UF_OPAQUE 0x00000008
719 #define SF_SETTABLE 0xffff0000
720 #define SF_ARCHIVED 0x00010000
721 #define SF_IMMUTABLE 0x00020000
722 #define SF_APPEND 0x00040000
723 #endif
724
725 /* <sys/syslimits.h> */
726
727 #ifndef LINE_MAX
728 #define LINE_MAX 2048
729 #endif
730
731 /* <sys/time.h> */
732
733 #ifndef timercmp
734 #define timercmp(tvp, uvp, cmp) \
735 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
736 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
737 ((tvp)->tv_sec cmp (uvp)->tv_sec))
738 #endif
739 #ifndef timeradd
740 #define timeradd(tvp, uvp, vvp) \
741 do { \
742 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
743 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
744 if ((vvp)->tv_usec >= 1000000) { \
745 (vvp)->tv_sec++; \
746 (vvp)->tv_usec -= 1000000; \
747 } \
748 } while (/* CONSTCOND */ 0)
749 #endif
750 #ifndef timersub
751 #define timersub(tvp, uvp, vvp) \
752 do { \
753 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
754 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
755 if ((vvp)->tv_usec < 0) { \
756 (vvp)->tv_sec--; \
757 (vvp)->tv_usec += 1000000; \
758 } \
759 } while (/* CONSTCOND */ 0)
760 #endif
761
762 /* <sys/types.h> */
763
764 #ifdef major
765 #undef major
766 #endif
767 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
768
769 #ifdef minor
770 #undef minor
771 #endif
772 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
773 (((x) & 0x000000ff) >> 0)))
774 #ifdef makedev
775 #undef makedev
776 #endif
777 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
778 (((y) << 12) & 0xfff00000) | \
779 (((y) << 0) & 0x000000ff)))
780 #ifndef NBBY
781 #define NBBY 8
782 #endif
783
784 #if !HAVE_U_QUAD_T
785 /* #define, not typedef, as quad_t exists as a struct on some systems */
786 #define quad_t long long
787 #define u_quad_t unsigned long long
788 #define strtoq strtoll
789 #define strtouq strtoull
790 #endif
791
792 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
793 #ifdef __NetBSD__
794 quad_t strtoq __P((const char *, char **, int));
795 u_quad_t strtouq __P((const char *, char **, int));
796 #endif
797
798 #endif /* !__NETBSD_COMPAT_DEFS_H__ */
799