compat_defs.h revision 1.37 1 1.37 thorpej /* $NetBSD: compat_defs.h,v 1.37 2004/06/18 20:17:01 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej #ifndef __NETBSD_COMPAT_DEFS_H__
4 1.1 thorpej #define __NETBSD_COMPAT_DEFS_H__
5 1.1 thorpej
6 1.4 tv /* Work around some complete brain damage. */
7 1.4 tv
8 1.4 tv /*
9 1.4 tv * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the
10 1.4 tv * program (not the OS) should do that. Preload <features.h> to keep any
11 1.4 tv * of this crap from being pulled in, and undefine _POSIX_SOURCE.
12 1.4 tv */
13 1.4 tv
14 1.4 tv #if defined(__linux__) && HAVE_FEATURES_H
15 1.4 tv #include <features.h>
16 1.4 tv #endif
17 1.4 tv
18 1.4 tv #undef _POSIX_SOURCE
19 1.4 tv #undef _POSIX_C_SOURCE
20 1.4 tv
21 1.1 thorpej /* System headers needed for (re)definitions below. */
22 1.1 thorpej
23 1.1 thorpej #include <sys/types.h>
24 1.3 tv #include <sys/mman.h>
25 1.3 tv #include <sys/param.h>
26 1.3 tv #include <sys/stat.h>
27 1.4 tv #include <sys/time.h>
28 1.1 thorpej #include <errno.h>
29 1.1 thorpej #include <fcntl.h>
30 1.2 lukem #include <grp.h>
31 1.1 thorpej #include <limits.h>
32 1.1 thorpej #include <paths.h>
33 1.3 tv #include <stdarg.h>
34 1.1 thorpej #include <stdio.h>
35 1.36 jmc
36 1.36 jmc /* So extra NetBSD extentions don't get pulled in */
37 1.36 jmc #ifdef __NetBSD__
38 1.36 jmc #define _POSIX_C_SOURCE
39 1.36 jmc #undef _NETBSD_SOURCE
40 1.36 jmc #endif
41 1.36 jmc
42 1.3 tv #include <stdlib.h>
43 1.36 jmc
44 1.36 jmc #ifdef __NetBSD__
45 1.36 jmc #undef _POSIX_C_SOURCE
46 1.36 jmc #endif
47 1.36 jmc
48 1.1 thorpej #include <string.h>
49 1.1 thorpej
50 1.3 tv #if HAVE_SYS_CDEFS_H
51 1.3 tv #include <sys/cdefs.h>
52 1.3 tv #endif
53 1.6 tv #if HAVE_SYS_SYSLIMITS_H
54 1.6 tv #include <sys/syslimits.h>
55 1.6 tv #endif
56 1.3 tv #if HAVE_SYS_SYSMACROS_H
57 1.3 tv /* major(), minor() on SVR4 */
58 1.3 tv #include <sys/sysmacros.h>
59 1.3 tv #endif
60 1.1 thorpej #if HAVE_INTTYPES_H
61 1.1 thorpej #include <inttypes.h>
62 1.1 thorpej #endif
63 1.1 thorpej #if HAVE_STDDEF_H
64 1.1 thorpej #include <stddef.h>
65 1.1 thorpej #endif
66 1.3 tv
67 1.3 tv /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
68 1.3 tv struct passwd;
69 1.3 tv
70 1.3 tv /* Assume an ANSI compiler for the host. */
71 1.3 tv
72 1.3 tv #undef __P
73 1.3 tv #define __P(x) x
74 1.3 tv
75 1.3 tv #ifndef __BEGIN_DECLS
76 1.3 tv #define __BEGIN_DECLS
77 1.3 tv #endif
78 1.3 tv #ifndef __END_DECLS
79 1.3 tv #define __END_DECLS
80 1.3 tv #endif
81 1.3 tv
82 1.4 tv /* Some things usually in BSD <sys/cdefs.h>. */
83 1.3 tv
84 1.12 bjh21 #ifndef __CONCAT
85 1.12 bjh21 #define __CONCAT(x,y) x ## y
86 1.12 bjh21 #endif
87 1.1 thorpej #if !defined(__attribute__) && !defined(__GNUC__)
88 1.1 thorpej #define __attribute__(x)
89 1.1 thorpej #endif
90 1.34 matt #if !defined(__packed)
91 1.34 matt #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
92 1.34 matt #define __packed __attribute__((__packed__))
93 1.34 matt #else
94 1.34 matt #define __packed error: no __packed for this compiler
95 1.34 matt #endif
96 1.34 matt #endif /* !__packed */
97 1.3 tv #ifndef __RENAME
98 1.3 tv #define __RENAME(x)
99 1.3 tv #endif
100 1.3 tv #undef __aconst
101 1.3 tv #define __aconst
102 1.3 tv #undef __dead
103 1.3 tv #define __dead
104 1.17 bjh21 #undef __restrict
105 1.17 bjh21 #define __restrict
106 1.3 tv
107 1.3 tv /* Dirent support. */
108 1.3 tv
109 1.3 tv #if HAVE_DIRENT_H
110 1.3 tv # include <dirent.h>
111 1.3 tv # define NAMLEN(dirent) (strlen((dirent)->d_name))
112 1.3 tv #else
113 1.3 tv # define dirent direct
114 1.3 tv # define NAMLEN(dirent) ((dirent)->d_namlen)
115 1.3 tv # if HAVE_SYS_NDIR_H
116 1.3 tv # include <sys/ndir.h>
117 1.3 tv # endif
118 1.3 tv # if HAVE_SYS_DIR_H
119 1.3 tv # include <sys/dir.h>
120 1.3 tv # endif
121 1.3 tv # if HAVE_NDIR_H
122 1.3 tv # include <ndir.h>
123 1.3 tv # endif
124 1.3 tv #endif
125 1.3 tv
126 1.1 thorpej /* Type substitutes. */
127 1.1 thorpej
128 1.1 thorpej #if !HAVE_ID_T
129 1.1 thorpej typedef unsigned long id_t;
130 1.26 thorpej #endif
131 1.26 thorpej
132 1.26 thorpej #if !HAVE_SOCKLEN_T
133 1.26 thorpej typedef int socklen_t;
134 1.28 fredb #endif
135 1.28 fredb
136 1.28 fredb #if !HAVE_U_LONG
137 1.28 fredb typedef unsigned long u_long;
138 1.1 thorpej #endif
139 1.1 thorpej
140 1.1 thorpej /* Prototypes for replacement functions. */
141 1.27 uwe
142 1.27 uwe #if !HAVE_ATOLL
143 1.27 uwe long long int atoll(const char *);
144 1.27 uwe #endif
145 1.1 thorpej
146 1.3 tv #if !HAVE_ASPRINTF
147 1.3 tv int asprintf(char **, const char *, ...);
148 1.3 tv #endif
149 1.3 tv
150 1.3 tv #if !HAVE_ASNPRINTF
151 1.3 tv int asnprintf(char **, size_t, const char *, ...);
152 1.3 tv #endif
153 1.3 tv
154 1.1 thorpej #if !HAVE_BASENAME
155 1.1 thorpej char *basename(char *);
156 1.1 thorpej #endif
157 1.1 thorpej
158 1.4 tv #if !HAVE_DECL_OPTIND
159 1.4 tv int getopt(int, char *const *, const char *);
160 1.4 tv extern char *optarg;
161 1.4 tv extern int optind, opterr, optopt;
162 1.4 tv #endif
163 1.4 tv
164 1.1 thorpej #if !HAVE_DIRNAME
165 1.1 thorpej char *dirname(char *);
166 1.1 thorpej #endif
167 1.1 thorpej
168 1.3 tv #if !HAVE_DIRFD
169 1.3 tv #if HAVE_DIR_DD_FD
170 1.3 tv #define dirfd(dirp) ((dirp)->dd_fd)
171 1.3 tv #else
172 1.3 tv #error cannot figure out how to turn a DIR * into a fd
173 1.3 tv #endif
174 1.3 tv #endif
175 1.3 tv
176 1.1 thorpej #if !HAVE_ERR_H
177 1.3 tv void err(int, const char *, ...);
178 1.3 tv void errx(int, const char *, ...);
179 1.1 thorpej void warn(const char *, ...);
180 1.1 thorpej void warnx(const char *, ...);
181 1.1 thorpej #endif
182 1.1 thorpej
183 1.1 thorpej #if !HAVE_FGETLN
184 1.1 thorpej char *fgetln(FILE *, size_t *);
185 1.1 thorpej #endif
186 1.1 thorpej
187 1.1 thorpej #if !HAVE_FLOCK
188 1.1 thorpej # define LOCK_SH 0x01
189 1.1 thorpej # define LOCK_EX 0x02
190 1.1 thorpej # define LOCK_NB 0x04
191 1.1 thorpej # define LOCK_UN 0x08
192 1.1 thorpej int flock(int, int);
193 1.1 thorpej #endif
194 1.1 thorpej
195 1.1 thorpej #if !HAVE_FPARSELN
196 1.1 thorpej # define FPARSELN_UNESCESC 0x01
197 1.1 thorpej # define FPARSELN_UNESCCONT 0x02
198 1.1 thorpej # define FPARSELN_UNESCCOMM 0x04
199 1.1 thorpej # define FPARSELN_UNESCREST 0x08
200 1.1 thorpej # define FPARSELN_UNESCALL 0x0f
201 1.1 thorpej char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
202 1.10 bjh21 #endif
203 1.10 bjh21
204 1.10 bjh21 #if !HAVE_ISSETUGID
205 1.10 bjh21 int issetugid(void);
206 1.1 thorpej #endif
207 1.1 thorpej
208 1.3 tv #if !HAVE_ISBLANK && !defined(isblank)
209 1.3 tv #define isblank(x) ((x) == ' ' || (x) == '\t')
210 1.21 lukem #endif
211 1.21 lukem
212 1.21 lukem #if !HAVE_LCHFLAGS
213 1.21 lukem int lchflags(const char *, u_long);
214 1.21 lukem #endif
215 1.21 lukem
216 1.21 lukem #if !HAVE_LCHMOD
217 1.21 lukem int lchmod(const char *, mode_t);
218 1.21 lukem #endif
219 1.21 lukem
220 1.21 lukem #if !HAVE_LCHOWN
221 1.21 lukem int lchown(const char *, uid_t, gid_t);
222 1.1 thorpej #endif
223 1.1 thorpej
224 1.4 tv #if !HAVE_MACHINE_BSWAP_H
225 1.4 tv #define bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
226 1.4 tv
227 1.4 tv #define bswap32(x) ((((x) << 24) & 0xff000000) | \
228 1.4 tv (((x) << 8) & 0x00ff0000) | \
229 1.4 tv (((x) >> 8) & 0x0000ff00) | \
230 1.4 tv (((x) >> 24) & 0x000000ff))
231 1.4 tv
232 1.4 tv #define bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
233 1.4 tv ((u_int64_t)bswap32((x) >> 32)))
234 1.18 thorpej #endif
235 1.18 thorpej
236 1.18 thorpej #if !HAVE_MKSTEMP
237 1.18 thorpej int mkstemp(char *);
238 1.18 thorpej #endif
239 1.18 thorpej
240 1.18 thorpej #if !HAVE_MKDTEMP
241 1.18 thorpej char *mkdtemp(char *);
242 1.18 thorpej #endif
243 1.18 thorpej
244 1.18 thorpej #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
245 1.18 thorpej /* This is a prototype for the internal function. */
246 1.18 thorpej int gettemp(char *, int *, int);
247 1.4 tv #endif
248 1.4 tv
249 1.1 thorpej #if !HAVE_PREAD
250 1.1 thorpej ssize_t pread(int, void *, size_t, off_t);
251 1.2 lukem #endif
252 1.2 lukem
253 1.2 lukem #if !HAVE_PWCACHE_USERDB
254 1.2 lukem int uid_from_user(const char *, uid_t *);
255 1.2 lukem int pwcache_userdb(int (*)(int), void (*)(void),
256 1.2 lukem struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
257 1.2 lukem int gid_from_group(const char *, gid_t *);
258 1.2 lukem int pwcache_groupdb(int (*)(int), void (*)(void),
259 1.2 lukem struct group * (*)(const char *), struct group * (*)(gid_t));
260 1.35 sjg # if HAVE_USER_FROM_UID
261 1.35 sjg /* Make them use our version */
262 1.35 sjg # define user_from_uid __nbcompat_user_from_uid
263 1.37 thorpej # endif
264 1.37 thorpej # if HAVE_GROUP_FROM_GID
265 1.37 thorpej /* Make them use our version */
266 1.35 sjg # define group_from_gid __nbcompat_group_from_gid
267 1.35 sjg # endif
268 1.1 thorpej #endif
269 1.1 thorpej
270 1.1 thorpej #if !HAVE_PWRITE
271 1.1 thorpej ssize_t pwrite(int, const void *, size_t, off_t);
272 1.1 thorpej #endif
273 1.1 thorpej
274 1.3 tv #if !HAVE_SETENV
275 1.3 tv int setenv(const char *, const char *, int);
276 1.3 tv #endif
277 1.3 tv
278 1.6 tv #if !HAVE_DECL_SETGROUPENT
279 1.3 tv int setgroupent(int);
280 1.3 tv #endif
281 1.3 tv
282 1.6 tv #if !HAVE_DECL_SETPASSENT
283 1.3 tv int setpassent(int);
284 1.3 tv #endif
285 1.3 tv
286 1.3 tv #if !HAVE_SETPROGNAME
287 1.3 tv const char *getprogname(void);
288 1.3 tv void setprogname(const char *);
289 1.3 tv #endif
290 1.3 tv
291 1.3 tv #if !HAVE_SNPRINTF
292 1.3 tv int snprintf(char *, size_t, const char *, ...);
293 1.3 tv #endif
294 1.3 tv
295 1.3 tv #if !HAVE_STRLCAT
296 1.3 tv size_t strlcat(char *, const char *, size_t);
297 1.3 tv #endif
298 1.3 tv
299 1.3 tv #if !HAVE_STRLCPY
300 1.3 tv size_t strlcpy(char *, const char *, size_t);
301 1.3 tv #endif
302 1.3 tv
303 1.3 tv #if !HAVE_STRSEP
304 1.3 tv char *strsep(char **, const char *);
305 1.23 lukem #endif
306 1.23 lukem
307 1.23 lukem #if !HAVE_STRSUFTOLL
308 1.23 lukem long long strsuftoll(const char *, const char *, long long, long long);
309 1.23 lukem long long strsuftollx(const char *, const char *,
310 1.23 lukem long long, long long, char *, size_t);
311 1.16 pooka #endif
312 1.16 pooka
313 1.20 lukem #if !HAVE_STRTOLL
314 1.20 lukem long long strtoll(const char *, char **, int);
315 1.20 lukem #endif
316 1.20 lukem
317 1.16 pooka #if !HAVE_USER_FROM_UID
318 1.16 pooka const char *user_from_uid(uid_t, int);
319 1.16 pooka const char *group_from_gid(gid_t, int);
320 1.3 tv #endif
321 1.3 tv
322 1.3 tv #if !HAVE_VASPRINTF
323 1.3 tv int vasprintf(char **, const char *, va_list);
324 1.3 tv #endif
325 1.3 tv
326 1.3 tv #if !HAVE_VASNPRINTF
327 1.3 tv int vasnprintf(char **, size_t, const char *, va_list);
328 1.3 tv #endif
329 1.3 tv
330 1.3 tv #if !HAVE_VSNPRINTF
331 1.3 tv int vsnprintf(char *, size_t, const char *, va_list);
332 1.3 tv #endif
333 1.3 tv
334 1.1 thorpej /*
335 1.1 thorpej * getmode() and setmode() are always defined, as these function names
336 1.1 thorpej * exist but with very different meanings on other OS's. The compat
337 1.1 thorpej * versions here simply accept an octal mode number; the "u+x,g-w" type
338 1.1 thorpej * of syntax is not accepted.
339 1.1 thorpej */
340 1.1 thorpej
341 1.1 thorpej #define getmode __nbcompat_getmode
342 1.1 thorpej #define setmode __nbcompat_setmode
343 1.1 thorpej
344 1.1 thorpej mode_t getmode(const void *, mode_t);
345 1.1 thorpej void *setmode(const char *);
346 1.1 thorpej
347 1.3 tv /* Eliminate assertions embedded in binaries. */
348 1.1 thorpej
349 1.1 thorpej #undef _DIAGASSERT
350 1.3 tv #define _DIAGASSERT(x)
351 1.4 tv
352 1.31 lukem /* Various sources use this */
353 1.31 lukem #undef __RCSID
354 1.31 lukem #define __RCSID(x)
355 1.31 lukem #undef __SCCSID
356 1.31 lukem #define __SCCSID(x)
357 1.31 lukem #undef __COPYRIGHT
358 1.31 lukem #define __COPYRIGHT(x)
359 1.31 lukem #undef __KERNEL_RCSID
360 1.31 lukem #define __KERNEL_RCSID(x,y)
361 1.31 lukem
362 1.4 tv /* Heimdal expects this one. */
363 1.4 tv
364 1.3 tv #undef RCSID
365 1.3 tv #define RCSID(x)
366 1.1 thorpej
367 1.3 tv /* Some definitions not available on all systems. */
368 1.1 thorpej
369 1.4 tv /* <errno.h> */
370 1.4 tv
371 1.4 tv #ifndef EFTYPE
372 1.4 tv #define EFTYPE EIO
373 1.4 tv #endif
374 1.4 tv
375 1.4 tv /* <fcntl.h> */
376 1.4 tv
377 1.4 tv #ifndef O_EXLOCK
378 1.4 tv #define O_EXLOCK 0
379 1.4 tv #endif
380 1.4 tv #ifndef O_SHLOCK
381 1.4 tv #define O_SHLOCK 0
382 1.4 tv #endif
383 1.4 tv
384 1.8 bjh21 /* <limits.h> */
385 1.4 tv
386 1.4 tv #ifndef UID_MAX
387 1.4 tv #define UID_MAX 32767
388 1.4 tv #endif
389 1.4 tv #ifndef GID_MAX
390 1.4 tv #define GID_MAX UID_MAX
391 1.4 tv #endif
392 1.4 tv
393 1.4 tv #ifndef UQUAD_MAX
394 1.4 tv #define UQUAD_MAX ((u_quad_t)-1)
395 1.4 tv #endif
396 1.4 tv #ifndef QUAD_MAX
397 1.4 tv #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
398 1.4 tv #endif
399 1.4 tv #ifndef QUAD_MIN
400 1.4 tv #define QUAD_MIN ((quad_t)(~QUAD_MAX))
401 1.4 tv #endif
402 1.4 tv #ifndef ULLONG_MAX
403 1.4 tv #define ULLONG_MAX ((unsigned long long)-1)
404 1.4 tv #endif
405 1.4 tv #ifndef LLONG_MAX
406 1.4 tv #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
407 1.4 tv #endif
408 1.4 tv #ifndef LLONG_MIN
409 1.4 tv #define LLONG_MIN ((long long)(~LLONG_MAX))
410 1.3 tv #endif
411 1.1 thorpej
412 1.4 tv /* <paths.h> */
413 1.4 tv
414 1.3 tv #ifndef _PATH_BSHELL
415 1.15 bjh21 #define _PATH_BSHELL PATH_BSHELL
416 1.1 thorpej #endif
417 1.1 thorpej #ifndef _PATH_DEFPATH
418 1.1 thorpej #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
419 1.1 thorpej #endif
420 1.1 thorpej #ifndef _PATH_DEV
421 1.1 thorpej #define _PATH_DEV "/dev/"
422 1.1 thorpej #endif
423 1.1 thorpej #ifndef _PATH_DEVNULL
424 1.1 thorpej #define _PATH_DEVNULL _PATH_DEV "null"
425 1.1 thorpej #endif
426 1.1 thorpej #ifndef _PATH_TMP
427 1.1 thorpej #define _PATH_TMP "/tmp/"
428 1.22 christos #endif
429 1.22 christos #ifndef _PATH_DEFTAPE
430 1.22 christos #define _PATH_DEFTAPE "/dev/nrst0"
431 1.1 thorpej #endif
432 1.1 thorpej
433 1.4 tv /* <stdarg.h> */
434 1.3 tv
435 1.4 tv #ifndef _BSD_VA_LIST_
436 1.4 tv #define _BSD_VA_LIST_ va_list
437 1.9 bjh21 #endif
438 1.9 bjh21
439 1.13 bjh21 /* <stdint.h> */
440 1.30 uwe
441 1.30 uwe #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
442 1.30 uwe #define SIZE_MAX SIZE_T_MAX
443 1.30 uwe #endif
444 1.13 bjh21
445 1.13 bjh21 #ifndef UINT32_MAX
446 1.13 bjh21 #define UINT32_MAX 0xffffffffU
447 1.14 bjh21 #endif
448 1.14 bjh21
449 1.14 bjh21 /* <stdlib.h> */
450 1.14 bjh21
451 1.14 bjh21 #ifndef __GNUC__
452 1.14 bjh21 # if HAVE_ALLOCA_H
453 1.14 bjh21 # include <alloca.h>
454 1.14 bjh21 # else
455 1.14 bjh21 # ifndef alloca /* predefined by HP cc +Olibcalls */
456 1.14 bjh21 char *alloca ();
457 1.14 bjh21 # endif
458 1.14 bjh21 # endif
459 1.13 bjh21 #endif
460 1.25 uwe
461 1.25 uwe /* avoid prototype conflicts with host */
462 1.25 uwe #define cgetcap __nbcompat_cgetcap
463 1.25 uwe #define cgetclose __nbcompat_cgetclose
464 1.25 uwe #define cgetent __nbcompat_cgetent
465 1.25 uwe #define cgetfirst __nbcompat_cgetfirst
466 1.25 uwe #define cgetmatch __nbcompat_cgetmatch
467 1.25 uwe #define cgetnext __nbcompat_cgetnext
468 1.25 uwe #define cgetnum __nbcompat_cgetnum
469 1.25 uwe #define cgetset __nbcompat_cgetset
470 1.25 uwe #define cgetstr __nbcompat_cgetstr
471 1.25 uwe #define cgetustr __nbcompat_cgetustr
472 1.25 uwe
473 1.25 uwe char *cgetcap(char *, const char *, int);
474 1.25 uwe int cgetclose(void);
475 1.33 christos int cgetent(char **, const char * const *, const char *);
476 1.33 christos int cgetfirst(char **, const char * const *);
477 1.25 uwe int cgetmatch(const char *, const char *);
478 1.33 christos int cgetnext(char **, const char * const *);
479 1.25 uwe int cgetnum(char *, const char *, long *);
480 1.25 uwe int cgetset(const char *);
481 1.25 uwe int cgetstr(char *, const char *, char **);
482 1.25 uwe int cgetustr(char *, const char *, char **);
483 1.13 bjh21
484 1.9 bjh21 /* <sys/endian.h> */
485 1.9 bjh21
486 1.29 lukem #ifdef HAVE_SYS_ENDIAN_H
487 1.29 lukem #include <sys/endian.h>
488 1.29 lukem #else
489 1.9 bjh21 #if WORDS_BIGENDIAN
490 1.9 bjh21 #define htobe16(x) (x)
491 1.9 bjh21 #define htobe32(x) (x)
492 1.9 bjh21 #define htobe64(x) (x)
493 1.9 bjh21 #define htole16(x) bswap16((u_int16_t)(x))
494 1.9 bjh21 #define htole32(x) bswap32((u_int32_t)(x))
495 1.9 bjh21 #define htole64(x) bswap64((u_int64_t)(x))
496 1.9 bjh21 #else
497 1.9 bjh21 #define htobe16(x) bswap16((u_int16_t)(x))
498 1.9 bjh21 #define htobe32(x) bswap32((u_int32_t)(x))
499 1.9 bjh21 #define htobe64(x) bswap64((u_int64_t)(x))
500 1.9 bjh21 #define htole16(x) (x)
501 1.9 bjh21 #define htole32(x) (x)
502 1.9 bjh21 #define htole64(x) (x)
503 1.9 bjh21 #endif
504 1.9 bjh21 #define be16toh(x) htobe16(x)
505 1.9 bjh21 #define be32toh(x) htobe32(x)
506 1.9 bjh21 #define be64toh(x) htobe64(x)
507 1.9 bjh21 #define le16toh(x) htole16(x)
508 1.9 bjh21 #define le32toh(x) htole32(x)
509 1.9 bjh21 #define le64toh(x) htole64(x)
510 1.1 thorpej #endif
511 1.1 thorpej
512 1.4 tv /* <sys/mman.h> */
513 1.3 tv
514 1.3 tv #ifndef MAP_FILE
515 1.3 tv #define MAP_FILE 0
516 1.19 lukem #endif
517 1.19 lukem
518 1.19 lukem /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
519 1.19 lukem #ifndef MAP_ANON
520 1.19 lukem #ifdef MAP_ANONYMOUS
521 1.19 lukem #define MAP_ANON MAP_ANONYMOUS
522 1.19 lukem #endif
523 1.3 tv #endif
524 1.3 tv
525 1.4 tv /* <sys/param.h> */
526 1.4 tv
527 1.4 tv #undef BIG_ENDIAN
528 1.4 tv #undef LITTLE_ENDIAN
529 1.4 tv #define BIG_ENDIAN 4321
530 1.4 tv #define LITTLE_ENDIAN 1234
531 1.4 tv
532 1.4 tv #undef BYTE_ORDER
533 1.4 tv #if WORDS_BIGENDIAN
534 1.4 tv #define BYTE_ORDER BIG_ENDIAN
535 1.4 tv #else
536 1.4 tv #define BYTE_ORDER LITTLE_ENDIAN
537 1.4 tv #endif
538 1.4 tv
539 1.7 tv #ifndef DEV_BSIZE
540 1.7 tv #define DEV_BSIZE (1 << 9)
541 1.7 tv #endif
542 1.7 tv
543 1.4 tv #undef MIN
544 1.4 tv #undef MAX
545 1.4 tv #define MIN(a,b) ((a) < (b) ? (a) : (b))
546 1.4 tv #define MAX(a,b) ((a) > (b) ? (a) : (b))
547 1.4 tv
548 1.1 thorpej #ifndef MAXBSIZE
549 1.1 thorpej #define MAXBSIZE (64 * 1024)
550 1.1 thorpej #endif
551 1.4 tv #ifndef MAXFRAG
552 1.4 tv #define MAXFRAG 8
553 1.1 thorpej #endif
554 1.4 tv #ifndef MAXPHYS
555 1.4 tv #define MAXPHYS (64 * 1024)
556 1.3 tv #endif
557 1.4 tv
558 1.6 tv /* XXX needed by makefs; this should be done in a better way */
559 1.6 tv #undef btodb
560 1.6 tv #define btodb(x) ((x) << 9)
561 1.6 tv
562 1.6 tv #undef setbit
563 1.6 tv #undef clrbit
564 1.6 tv #undef isset
565 1.6 tv #undef isclr
566 1.6 tv #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
567 1.6 tv #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
568 1.6 tv #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
569 1.6 tv #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
570 1.6 tv
571 1.4 tv #ifndef powerof2
572 1.4 tv #define powerof2(x) ((((x)-1)&(x))==0)
573 1.3 tv #endif
574 1.7 tv
575 1.7 tv #undef roundup
576 1.7 tv #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
577 1.3 tv
578 1.4 tv /* <sys/stat.h> */
579 1.4 tv
580 1.4 tv #ifndef ALLPERMS
581 1.4 tv #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
582 1.4 tv #endif
583 1.4 tv #ifndef DEFFILEMODE
584 1.4 tv #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
585 1.4 tv #endif
586 1.3 tv #ifndef S_ISTXT
587 1.3 tv #ifdef S_ISVTX
588 1.3 tv #define S_ISTXT S_ISVTX
589 1.3 tv #else
590 1.3 tv #define S_ISTXT 0
591 1.3 tv #endif
592 1.6 tv #endif
593 1.6 tv
594 1.6 tv /* <sys/syslimits.h> */
595 1.6 tv
596 1.6 tv #ifndef LINE_MAX
597 1.6 tv #define LINE_MAX 2048
598 1.4 tv #endif
599 1.4 tv
600 1.4 tv /* <sys/time.h> */
601 1.4 tv
602 1.4 tv #ifndef timercmp
603 1.4 tv #define timercmp(tvp, uvp, cmp) \
604 1.4 tv (((tvp)->tv_sec == (uvp)->tv_sec) ? \
605 1.4 tv ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
606 1.4 tv ((tvp)->tv_sec cmp (uvp)->tv_sec))
607 1.4 tv #endif
608 1.4 tv #ifndef timeradd
609 1.4 tv #define timeradd(tvp, uvp, vvp) \
610 1.4 tv do { \
611 1.4 tv (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
612 1.4 tv (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
613 1.4 tv if ((vvp)->tv_usec >= 1000000) { \
614 1.4 tv (vvp)->tv_sec++; \
615 1.4 tv (vvp)->tv_usec -= 1000000; \
616 1.4 tv } \
617 1.4 tv } while (/* CONSTCOND */ 0)
618 1.4 tv #endif
619 1.4 tv #ifndef timersub
620 1.4 tv #define timersub(tvp, uvp, vvp) \
621 1.4 tv do { \
622 1.4 tv (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
623 1.4 tv (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
624 1.4 tv if ((vvp)->tv_usec < 0) { \
625 1.4 tv (vvp)->tv_sec--; \
626 1.4 tv (vvp)->tv_usec += 1000000; \
627 1.4 tv } \
628 1.4 tv } while (/* CONSTCOND */ 0)
629 1.4 tv #endif
630 1.4 tv
631 1.4 tv /* <sys/types.h> */
632 1.4 tv
633 1.4 tv #if !HAVE_U_QUAD_T
634 1.4 tv /* #define, not typedef, as quad_t exists as a struct on some systems */
635 1.4 tv #define quad_t long long
636 1.4 tv #define u_quad_t unsigned long long
637 1.20 lukem #define strtoq strtoll
638 1.4 tv #define strtouq strtoull
639 1.1 thorpej #endif
640 1.1 thorpej
641 1.1 thorpej #endif /* !__NETBSD_COMPAT_DEFS_H__ */
642