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