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