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