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