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