-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpico_bsd_syscalls.h
341 lines (271 loc) · 7.74 KB
/
pico_bsd_syscalls.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#ifndef PICO_BSD_SYSCALLS_H_
#define PICO_BSD_SYSCALLS_H_
#include "pico_bsd_sockets.h"
/* Cannot be included directly, expect from pico_bsd_sockets.h */
#if !defined (__socklen_t_defined) && defined (REPLACE_STDCALLS)
/* For systems that have the syscalls already defined */
#ifdef socket
#undef socket
#endif
#define socket pico_newsocket
#ifdef bind
#undef bind
#endif
#define bind pico_bind
#ifdef listen
#undef listen
#endif
#define listen pico_listen
#ifdef connect
#undef connect
#endif
#define connect pico_connect
#ifdef accept
#undef accept
#endif
#define accept pico_accept
#ifdef sendto
#undef sendto
#endif
#define sendto pico_sendto
#ifdef recvfrom
#undef recvfrom
#endif
#define recvfrom pico_recvfrom
#ifdef write
#undef write
#endif
#define write pico_write
#ifdef read
#undef read
#endif
#define read pico_read
#ifdef send
#undef send
#endif
#define send pico_send
#ifdef recv
#undef recv
#endif
#define recv pico_recv
#ifdef close
#undef close
#endif
#define close pico_close
#ifdef shutdown
#undef shutdown
#endif
#define shutdown pico_shutdown
#ifdef getsockname
#undef getsockname
#endif
#define getsockname pico_getsockname
#ifdef getpeername
#undef getpeername
#endif
#define getpeername pico_getpeername
#ifdef setsockopt
#undef setsockopt
#endif
#define setsockopt pico_setsockopt
#ifdef getsockopt
#undef getsockopt
#endif
#define getsockopt pico_getsockopt
#ifdef gettimeofday
#undef gettimeofday
#endif
#define gettimeofday pico_gettimeofday
#ifdef gethostbyname
#undef gethostbyname
#endif
#define gethostbyname pico_gethostbyname
#ifdef getaddrinfo
#undef getaddrinfo
#endif
#define getaddrinfo pico_getaddrinfo
#ifdef freeaddrinfo
#undef freeaddrinfo
#endif
#define freeaddrinfo pico_freeaddrinfo
#ifdef htons
#undef htons
#endif
#define htons short_be
#ifdef htonl
#undef htonl
#endif
#define htonl long_be
#ifdef ntohs
#undef ntohs
#endif
#define ntohs short_be
#ifdef ntohl
#undef ntohl
#endif
#define ntohl long_be
#ifdef inet_ntoa
#undef inet_ntoa
#endif
#define inet_ntoa pico_inet_ntoa
#ifdef inet_ntop
#undef inet_ntop
#endif
#define inet_ntop pico_inet_ntop
#ifdef select
#undef select
#endif
#define select pico_select
#ifdef pselect
#undef pselect
#endif
#define pselect pico_pselect
#ifdef poll
#undef poll
#endif
#define poll pico_poll
#ifdef ppoll
#undef ppoll
#endif
#define ppoll pico_ppoll
#ifdef fcntl
#undef fcntl
#endif
#define fcntl pico_fcntl
#else
static inline int socket(int domain, int type, int proto)
{
return pico_newsocket(domain, type, proto);
}
static inline int bind(int sd, struct sockaddr * local_addr, socklen_t socklen)
{
return pico_bind(sd, local_addr, socklen);
}
static inline int listen(int sd, int backlog)
{
return pico_listen(sd, backlog);
}
static inline int connect(int sd, struct sockaddr *_saddr, socklen_t socklen)
{
return pico_connect(sd, _saddr, socklen);
}
static inline int accept(int sd, struct sockaddr *_orig, socklen_t *socklen)
{
return pico_accept(sd, _orig, socklen);
}
static inline int sendto(int sd, void * buf, int len, int flags, struct sockaddr *_dst, socklen_t socklen)
{
return pico_sendto(sd, buf, len, flags, _dst, socklen);
}
static inline int recvfrom(int sd, void * buf, int len, int flags, struct sockaddr *_addr, socklen_t *socklen)
{
return pico_recvfrom(sd, buf, len, flags, _addr, socklen);
}
static inline int write(int sd, void * buf, int len)
{
return pico_write(sd, buf, len);
}
static inline int send(int sd, void * buf, int len, int flags)
{
return pico_send(sd, buf, len, flags);
}
static inline int read(int sd, void * buf, int len)
{
return pico_read(sd, buf, len);
}
static inline int recv(int sd, void * buf, int len, int flags)
{
return pico_recv(sd, buf, len, flags);
}
static inline int close(int sd)
{
return pico_close(sd);
}
static inline int shutdown(int sd, int how)
{
return pico_shutdown(sd, how);
}
static inline int getsockname(int sd, struct sockaddr * local_addr, socklen_t *socklen)
{
return pico_getsockname(sd, local_addr, socklen);
}
static inline int getpeername(int sd, struct sockaddr * remote_addr, socklen_t *socklen)
{
return pico_getpeername(sd, remote_addr, socklen);
}
static inline int fcntl(int sd, int cmd, int arg)
{
return pico_fcntl(sd, cmd, arg);
}
#ifdef PICO_SUPPORT_DNS_CLIENT
static inline struct hostent *gethostbyname(const char *name)
{
return pico_gethostbyname(name);
}
static inline int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
{
return pico_getaddrinfo(node, service, hints, res);
}
static inline void freeaddrinfo(struct addrinfo *res)
{
return pico_freeaddrinfo(res);
}
#endif
static inline int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
{
return pico_setsockopt(sockfd, level, optname, optval, optlen);
}
static inline int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
{
return pico_getsockopt(sockfd, level, optname, optval, optlen);
}
static inline int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
return pico_select(nfds, readfds, writefds, exceptfds, timeout);
}
static inline int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
{
return pico_pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask);
}
static inline int poll(struct pollfd *pfd, nfds_t npfd, int timeout)
{
return pico_poll(pfd, npfd, timeout);
}
static inline int ppoll(struct pollfd *pfd, nfds_t npfd, const struct timespec *timeout_ts, const sigset_t *sigmask)
{
return pico_ppoll(pfd, npfd, timeout_ts, sigmask);
}
static int gettimeofday(struct timeval *tv, struct timezone *tz)
{
return pico_gettimeofday(tv, tz);
}
static int settimeofday(struct timeval *tv, struct timezone *tz)
{
return pico_settimeofday(tv, tz);
}
static inline const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
{
return pico_inet_ntop(af, src, dst, size);
}
static inline char *inet_ntoa(struct in_addr in)
{
return pico_inet_ntoa(in);
}
static inline uint32_t htonl(uint32_t le)
{
return long_be(le);
}
static inline uint32_t ntohl(uint32_t le)
{
return long_be(le);
}
static inline uint16_t htons(uint16_t le)
{
return short_be(le);
}
static inline uint16_t ntohs(uint16_t le)
{
return short_be(le);
}
#endif
#endif /* PICO_BSD_SYSCALLS_H_ */