rumpuser_port.h revision 1.3 1 /* $NetBSD: rumpuser_port.h,v 1.3 2012/09/03 11:33:35 pooka Exp $ */
2
3 /*
4 * Portability header for non-NetBSD platforms.
5 * Quick & dirty.
6 * Maybe should try to use the infrastructure in tools/compat instead?
7 */
8
9 /*
10 * XXX:
11 * There is currently no errno translation for the error values reported
12 * by the hypercall layer.
13 */
14
15 #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
16 #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
17
18 #ifdef __NetBSD__
19 #include <sys/cdefs.h>
20 #include <sys/param.h>
21
22 #define PLATFORM_HAS_KQUEUE
23 #define PLATFORM_HAS_CHFLAGS
24 #define PLATFORM_HAS_NBMOUNT
25 #define PLATFORM_HAS_NFSSVC
26 #define PLATFORM_HAS_FSYNC_RANGE
27 #define PLATFORM_HAS_NBSYSCTL
28 #define PLATFORM_HAS_NBFILEHANDLE
29
30 #if __NetBSD_Prereq__(5,99,48)
31 #define PLATFORM_HAS_NBQUOTA
32 #endif
33
34 /*
35 * This includes also statvfs1() and fstatvfs1(). They could be
36 * reasonably easily emulated on other platforms.
37 */
38 #define PLATFORM_HAS_NBVFSSTAT
39 #endif
40
41 #ifdef __linux__
42 #define _XOPEN_SOURCE 600
43 #define _BSD_SOURCE
44 #define _FILE_OFFSET_BITS 64
45 #define _GNU_SOURCE
46 #include <features.h>
47 #endif
48
49 #include <sys/types.h>
50 #include <sys/param.h>
51
52 #if defined(__linux__)
53 #include <errno.h>
54 #include <stdlib.h>
55 #include <string.h>
56
57 /* this is inline simply to make this header self-contained */
58 static inline int
59 getenv_r(const char *name, char *buf, size_t buflen)
60 {
61 char *tmp;
62
63 if ((tmp = getenv(name)) != NULL) {
64 if (strlen(tmp) >= buflen) {
65 errno = ERANGE;
66 return -1;
67 }
68 strcpy(buf, tmp);
69 return 0;
70 } else {
71 errno = ENOENT;
72 return -1;
73 }
74 }
75 #endif
76
77 #ifndef __RCSID
78 #define __RCSID(a)
79 #endif
80
81 #ifndef INFTIM
82 #define INFTIM (-1)
83 #endif
84
85 #ifndef _DIAGASSERT
86 #define _DIAGASSERT(_p_)
87 #endif
88
89 #ifdef __linux__
90 #define SA_SETLEN(a,b)
91 #else /* BSD */
92 #define SA_SETLEN(_sa_, _len_) ((struct sockaddr *)_sa_)->sa_len = _len_
93 #endif
94
95 #ifndef __predict_true
96 #define __predict_true(a) a
97 #define __predict_false(a) a
98 #endif
99
100 #ifndef __dead
101 #define __dead
102 #endif
103
104 #ifndef __printflike
105 #define __printflike(a,b)
106 #endif
107
108 #ifndef __noinline
109 #ifdef __GNUC__
110 #define __noinline __attribute__((__noinline__))
111 #else
112 #define __noinline
113 #endif
114 #endif
115
116 #ifndef __arraycount
117 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
118 #endif
119
120 #ifndef __UNCONST
121 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
122 #endif
123
124 #ifdef __linux__
125 #define arc4random() random()
126 #endif
127
128 #ifndef __NetBSD_Prereq__
129 #define __NetBSD_Prereq__(a,b,c) 0
130 #endif
131
132 #if !defined(__CMSG_ALIGN)
133 #include <sys/socket.h>
134 #ifdef CMSG_ALIGN
135 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
136 #endif
137 #endif
138
139 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
140