roken.h.in revision 1.3 1 1.1 elric /* -*- C -*- */
2 1.1 elric /*
3 1.1 elric * Copyright (c) 1995-2005 Kungliga Tekniska Hgskolan
4 1.1 elric * (Royal Institute of Technology, Stockholm, Sweden).
5 1.1 elric * All rights reserved.
6 1.1 elric *
7 1.1 elric * Redistribution and use in source and binary forms, with or without
8 1.1 elric * modification, are permitted provided that the following conditions
9 1.1 elric * are met:
10 1.1 elric *
11 1.1 elric * 1. Redistributions of source code must retain the above copyright
12 1.1 elric * notice, this list of conditions and the following disclaimer.
13 1.1 elric *
14 1.1 elric * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 elric * notice, this list of conditions and the following disclaimer in the
16 1.1 elric * documentation and/or other materials provided with the distribution.
17 1.1 elric *
18 1.1 elric * 3. Neither the name of the Institute nor the names of its contributors
19 1.1 elric * may be used to endorse or promote products derived from this software
20 1.1 elric * without specific prior written permission.
21 1.1 elric *
22 1.1 elric * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 1.1 elric * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 elric * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 elric * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 1.1 elric * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 elric * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 elric * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 elric * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 elric * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 elric * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 elric * SUCH DAMAGE.
33 1.1 elric */
34 1.1 elric
35 1.1 elric #include <stdio.h>
36 1.1 elric #include <stdlib.h>
37 1.1 elric #include <stdarg.h>
38 1.1 elric #ifdef HAVE_STDINT_H
39 1.1 elric #include <stdint.h>
40 1.1 elric #endif
41 1.1 elric #include <string.h>
42 1.1 elric #include <signal.h>
43 1.1 elric
44 1.1 elric #ifndef ROKEN_LIB_FUNCTION
45 1.1 elric #ifdef _WIN32
46 1.1 elric # define ROKEN_LIB_CALL __cdecl
47 1.1 elric # ifdef ROKEN_LIB_DYNAMIC
48 1.1 elric # define ROKEN_LIB_FUNCTION __declspec(dllimport)
49 1.1 elric # define ROKEN_LIB_VARIABLE __declspec(dllimport)
50 1.1 elric # else
51 1.1 elric # define ROKEN_LIB_FUNCTION
52 1.1 elric # define ROKEN_LIB_VARIABLE
53 1.1 elric # endif
54 1.1 elric #else
55 1.1 elric #define ROKEN_LIB_FUNCTION
56 1.1 elric #define ROKEN_LIB_CALL
57 1.1 elric #define ROKEN_LIB_VARIABLE
58 1.1 elric #endif
59 1.1 elric #endif
60 1.1 elric
61 1.1 elric #ifdef HAVE_WINSOCK
62 1.1 elric /* Declarations for Microsoft Windows */
63 1.1 elric
64 1.1 elric #include <winsock2.h>
65 1.1 elric #include <ws2tcpip.h>
66 1.1 elric
67 1.1 elric /*
68 1.1 elric * error codes for inet_ntop/inet_pton
69 1.1 elric */
70 1.1 elric #define EAFNOSUPPORT WSAEAFNOSUPPORT
71 1.1 elric
72 1.1 elric typedef SOCKET rk_socket_t;
73 1.1 elric
74 1.1 elric #define rk_closesocket(x) closesocket(x)
75 1.1 elric #define rk_INVALID_SOCKET INVALID_SOCKET
76 1.1 elric #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
77 1.1 elric #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
78 1.1 elric #define rk_SOCK_ERRNO WSAGetLastError()
79 1.1 elric
80 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp);
81 1.1 elric
82 1.3 pettai /* Microsoft VC 2010 POSIX definitions */
83 1.3 pettai #ifndef ENOTSOCK
84 1.3 pettai #define ENOTSOCK 128
85 1.3 pettai #endif
86 1.3 pettai #ifndef ENOTSUP
87 1.3 pettai #define ENOTSUP 129
88 1.3 pettai #endif
89 1.3 pettai #ifndef EOVERFLOW
90 1.3 pettai #define EOVERFLOW 132
91 1.3 pettai #endif
92 1.3 pettai #ifndef ETIMEDOUT
93 1.3 pettai #define ETIMEDOUT 138
94 1.3 pettai #endif
95 1.3 pettai #ifndef EWOULDBLOCK
96 1.3 pettai #define EWOULDBLOCK 140
97 1.3 pettai #endif
98 1.1 elric
99 1.1 elric #define rk_SOCK_INIT() rk_WSAStartup()
100 1.1 elric #define rk_SOCK_EXIT() rk_WSACleanup()
101 1.1 elric
102 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
103 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
104 1.1 elric
105 1.1 elric #else /* not WinSock */
106 1.1 elric
107 1.1 elric typedef int rk_socket_t;
108 1.1 elric
109 1.1 elric #define rk_closesocket(x) close(x)
110 1.1 elric #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
111 1.1 elric #define rk_IS_BAD_SOCKET(s) ((s) < 0)
112 1.1 elric #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
113 1.1 elric #define rk_SOCK_ERRNO errno
114 1.1 elric #define rk_INVALID_SOCKET (-1)
115 1.1 elric
116 1.1 elric #define rk_SOCK_INIT() 0
117 1.1 elric #define rk_SOCK_EXIT() do { } while(0)
118 1.1 elric
119 1.1 elric #endif
120 1.1 elric
121 1.3 pettai #ifndef IN_LOOPBACKNET
122 1.3 pettai #define IN_LOOPBACKNET 127
123 1.3 pettai #endif
124 1.3 pettai
125 1.1 elric #ifdef _MSC_VER
126 1.1 elric /* Declarations for Microsoft Visual C runtime on Windows */
127 1.1 elric
128 1.1 elric #include<process.h>
129 1.1 elric
130 1.1 elric #include<io.h>
131 1.1 elric
132 1.1 elric #ifndef __BIT_TYPES_DEFINED__
133 1.1 elric #define __BIT_TYPES_DEFINED__
134 1.1 elric
135 1.1 elric typedef __int8 int8_t;
136 1.1 elric typedef __int16 int16_t;
137 1.1 elric typedef __int32 int32_t;
138 1.1 elric typedef __int64 int64_t;
139 1.1 elric typedef unsigned __int8 uint8_t;
140 1.1 elric typedef unsigned __int16 uint16_t;
141 1.1 elric typedef unsigned __int32 uint32_t;
142 1.1 elric typedef unsigned __int64 uint64_t;
143 1.1 elric typedef uint8_t u_int8_t;
144 1.1 elric typedef uint16_t u_int16_t;
145 1.1 elric typedef uint32_t u_int32_t;
146 1.1 elric typedef uint64_t u_int64_t;
147 1.1 elric
148 1.1 elric #endif /* __BIT_TYPES_DEFINED__ */
149 1.1 elric
150 1.1 elric #define UNREACHABLE(x) x
151 1.1 elric #define UNUSED_ARGUMENT(x) ((void) x)
152 1.1 elric
153 1.1 elric #define RETSIGTYPE void
154 1.1 elric
155 1.1 elric #define VOID_RETSIGTYPE 1
156 1.1 elric
157 1.1 elric #ifdef VOID_RETSIGTYPE
158 1.1 elric #define SIGRETURN(x) return
159 1.1 elric #else
160 1.1 elric #define SIGRETURN(x) return (RETSIGTYPE)(x)
161 1.1 elric #endif
162 1.1 elric
163 1.1 elric #ifndef CPP_ONLY
164 1.1 elric
165 1.1 elric typedef int pid_t;
166 1.1 elric
167 1.1 elric typedef unsigned int gid_t;
168 1.1 elric
169 1.1 elric typedef unsigned int uid_t;
170 1.1 elric
171 1.1 elric typedef unsigned short mode_t;
172 1.1 elric
173 1.1 elric #endif
174 1.1 elric
175 1.1 elric #ifndef __cplusplus
176 1.1 elric #define inline __inline
177 1.1 elric #endif
178 1.1 elric
179 1.1 elric #else
180 1.1 elric
181 1.1 elric #define UNREACHABLE(x)
182 1.1 elric #define UNUSED_ARGUMENT(x)
183 1.1 elric
184 1.1 elric #endif
185 1.1 elric
186 1.1 elric #ifdef _AIX
187 1.1 elric struct ether_addr;
188 1.1 elric struct sockaddr_dl;
189 1.1 elric #endif
190 1.1 elric #ifdef HAVE_SYS_PARAM_H
191 1.1 elric #include <sys/param.h>
192 1.1 elric #endif
193 1.1 elric #ifdef HAVE_INTTYPES_H
194 1.1 elric #include <inttypes.h>
195 1.1 elric #endif
196 1.1 elric #ifdef HAVE_SYS_TYPES_H
197 1.1 elric #include <sys/types.h>
198 1.1 elric #endif
199 1.1 elric #ifdef HAVE_SYS_BITYPES_H
200 1.1 elric #include <sys/bitypes.h>
201 1.1 elric #endif
202 1.1 elric #ifdef HAVE_BIND_BITYPES_H
203 1.1 elric #include <bind/bitypes.h>
204 1.1 elric #endif
205 1.1 elric #ifdef HAVE_NETINET_IN6_MACHTYPES_H
206 1.1 elric #include <netinet/in6_machtypes.h>
207 1.1 elric #endif
208 1.1 elric #ifdef HAVE_UNISTD_H
209 1.1 elric #include <unistd.h>
210 1.1 elric #endif
211 1.1 elric #ifdef HAVE_SYS_SOCKET_H
212 1.1 elric #include <sys/socket.h>
213 1.1 elric #endif
214 1.1 elric #ifdef HAVE_SYS_UIO_H
215 1.1 elric #include <sys/uio.h>
216 1.1 elric #endif
217 1.1 elric #ifdef HAVE_GRP_H
218 1.1 elric #include <grp.h>
219 1.1 elric #endif
220 1.1 elric #ifdef HAVE_SYS_STAT_H
221 1.1 elric #include <sys/stat.h>
222 1.1 elric #endif
223 1.1 elric #ifdef HAVE_NETINET_IN_H
224 1.1 elric #include <netinet/in.h>
225 1.1 elric #endif
226 1.1 elric #ifdef HAVE_NETINET_IN6_H
227 1.1 elric #include <netinet/in6.h>
228 1.1 elric #endif
229 1.1 elric #ifdef HAVE_NETINET6_IN6_H
230 1.1 elric #include <netinet6/in6.h>
231 1.1 elric #endif
232 1.1 elric #ifdef HAVE_ARPA_INET_H
233 1.1 elric #include <arpa/inet.h>
234 1.1 elric #endif
235 1.1 elric #ifdef HAVE_NETDB_H
236 1.1 elric #include <netdb.h>
237 1.1 elric #endif
238 1.1 elric #ifdef HAVE_ARPA_NAMESER_H
239 1.1 elric #include <arpa/nameser.h>
240 1.1 elric #endif
241 1.1 elric #ifdef HAVE_RESOLV_H
242 1.1 elric #include <resolv.h>
243 1.1 elric #endif
244 1.1 elric #ifdef HAVE_SYSLOG_H
245 1.1 elric #include <syslog.h>
246 1.1 elric #endif
247 1.1 elric #ifdef HAVE_FCNTL_H
248 1.1 elric #include <fcntl.h>
249 1.1 elric #endif
250 1.1 elric #ifdef HAVE_ERRNO_H
251 1.1 elric #include <errno.h>
252 1.1 elric #endif
253 1.1 elric #include <err.h>
254 1.1 elric #ifdef HAVE_TERMIOS_H
255 1.1 elric #include <termios.h>
256 1.1 elric #endif
257 1.1 elric #ifdef HAVE_SYS_IOCTL_H
258 1.1 elric #include <sys/ioctl.h>
259 1.1 elric #endif
260 1.1 elric #ifdef TIME_WITH_SYS_TIME
261 1.1 elric #include <sys/time.h>
262 1.1 elric #include <time.h>
263 1.1 elric #elif defined(HAVE_SYS_TIME_H)
264 1.1 elric #include <sys/time.h>
265 1.1 elric #else
266 1.1 elric #include <time.h>
267 1.1 elric #endif
268 1.1 elric
269 1.1 elric #ifdef HAVE_PATHS_H
270 1.1 elric #include <paths.h>
271 1.1 elric #endif
272 1.1 elric
273 1.1 elric #ifdef HAVE_DIRENT_H
274 1.1 elric #include <dirent.h>
275 1.1 elric #endif
276 1.1 elric
277 1.1 elric #ifdef BACKSLASH_PATH_DELIM
278 1.1 elric #define rk_PATH_DELIM '\\'
279 1.1 elric #endif
280 1.1 elric
281 1.1 elric #ifndef HAVE_SSIZE_T
282 1.1 elric #ifndef SSIZE_T_DEFINED
283 1.1 elric #ifdef ssize_t
284 1.1 elric #undef ssize_t
285 1.1 elric #endif
286 1.1 elric #ifdef _WIN64
287 1.1 elric typedef __int64 ssize_t;
288 1.1 elric #else
289 1.1 elric typedef int ssize_t;
290 1.1 elric #endif
291 1.1 elric #define SSIZE_T_DEFINED
292 1.1 elric #endif /* SSIZE_T_DEFINED */
293 1.1 elric #endif /* HAVE_SSIZE_T */
294 1.1 elric
295 1.1 elric #include <roken-common.h>
296 1.1 elric
297 1.1 elric ROKEN_CPP_START
298 1.1 elric
299 1.1 elric #ifdef HAVE_UINTPTR_T
300 1.1 elric #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
301 1.1 elric #else
302 1.1 elric #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
303 1.1 elric #endif
304 1.1 elric
305 1.1 elric #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
306 1.1 elric #define setsid _setsid
307 1.1 elric #endif
308 1.1 elric
309 1.1 elric #ifdef _MSC_VER
310 1.1 elric /* Additional macros for Visual C/C++ runtime */
311 1.1 elric
312 1.1 elric #define close _close
313 1.1 elric
314 1.1 elric #define getpid _getpid
315 1.1 elric
316 1.1 elric #define open _open
317 1.1 elric
318 1.1 elric #define chdir _chdir
319 1.1 elric
320 1.1 elric #define fsync _commit
321 1.1 elric
322 1.1 elric /* The MSVC implementation of snprintf is not C99 compliant. */
323 1.1 elric #define snprintf rk_snprintf
324 1.1 elric #define vsnprintf rk_vsnprintf
325 1.1 elric #define vasnprintf rk_vasnprintf
326 1.1 elric #define vasprintf rk_vasprintf
327 1.1 elric #define asnprintf rk_asnprintf
328 1.1 elric #define asprintf rk_asprintf
329 1.1 elric
330 1.1 elric #define _PIPE_BUFFER_SZ 8192
331 1.1 elric #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
332 1.1 elric
333 1.1 elric #define ftruncate(fd, sz) _chsize((fd), (sz))
334 1.1 elric
335 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
336 1.1 elric rk_snprintf (char *str, size_t sz, const char *format, ...);
337 1.1 elric
338 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
339 1.1 elric rk_asprintf (char **ret, const char *format, ...);
340 1.1 elric
341 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
342 1.1 elric rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
343 1.1 elric
344 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
345 1.1 elric rk_vasprintf (char **ret, const char *format, va_list args);
346 1.1 elric
347 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
348 1.1 elric rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
349 1.1 elric
350 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
351 1.1 elric rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
352 1.1 elric
353 1.1 elric /* missing stat.h predicates */
354 1.1 elric
355 1.1 elric #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
356 1.1 elric
357 1.1 elric #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
358 1.1 elric
359 1.1 elric #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
360 1.1 elric
361 1.1 elric #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
362 1.1 elric
363 1.1 elric /* The following are not implemented:
364 1.1 elric
365 1.1 elric S_ISLNK(m)
366 1.1 elric S_ISSOCK(m)
367 1.1 elric S_ISBLK(m)
368 1.1 elric */
369 1.1 elric
370 1.1 elric #endif /* _MSC_VER */
371 1.1 elric
372 1.1 elric #ifdef HAVE_WINSOCK
373 1.1 elric
374 1.1 elric /* While we are at it, define WinSock specific scatter gather socket
375 1.1 elric I/O. */
376 1.1 elric
377 1.1 elric #define iovec _WSABUF
378 1.1 elric #define iov_base buf
379 1.1 elric #define iov_len len
380 1.1 elric
381 1.1 elric struct msghdr {
382 1.1 elric void *msg_name;
383 1.1 elric socklen_t msg_namelen;
384 1.1 elric struct iovec *msg_iov;
385 1.1 elric size_t msg_iovlen;
386 1.1 elric void *msg_control;
387 1.1 elric socklen_t msg_controllen;
388 1.1 elric int msg_flags;
389 1.1 elric };
390 1.1 elric
391 1.1 elric #define sendmsg sendmsg_w32
392 1.1 elric
393 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
394 1.1 elric sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
395 1.1 elric
396 1.1 elric #endif /* HAVE_WINSOCK */
397 1.1 elric
398 1.1 elric #ifndef HAVE_PUTENV
399 1.1 elric #define putenv rk_putenv
400 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
401 1.1 elric #endif
402 1.1 elric
403 1.1 elric #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
404 1.1 elric #ifndef HAVE_SETENV
405 1.1 elric #define setenv rk_setenv
406 1.1 elric #endif
407 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
408 1.1 elric #endif
409 1.1 elric
410 1.1 elric #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
411 1.1 elric #ifndef HAVE_UNSETENV
412 1.1 elric #define unsetenv rk_unsetenv
413 1.1 elric #endif
414 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
415 1.1 elric #endif
416 1.1 elric
417 1.1 elric #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
418 1.1 elric #ifndef HAVE_GETUSERSHELL
419 1.1 elric #define getusershell rk_getusershell
420 1.1 elric #define endusershell rk_endusershell
421 1.1 elric #endif
422 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
423 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
424 1.1 elric #endif
425 1.1 elric
426 1.1 elric #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
427 1.1 elric #ifndef HAVE_SNPRINTF
428 1.1 elric #define snprintf rk_snprintf
429 1.1 elric #endif
430 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
431 1.1 elric rk_snprintf (char *, size_t, const char *, ...)
432 1.1 elric __attribute__ ((format (printf, 3, 4)));
433 1.1 elric #endif
434 1.1 elric
435 1.1 elric #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
436 1.1 elric #ifndef HAVE_VSNPRINTF
437 1.1 elric #define vsnprintf rk_vsnprintf
438 1.1 elric #endif
439 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
440 1.1 elric rk_vsnprintf (char *, size_t, const char *, va_list)
441 1.1 elric __attribute__((format (printf, 3, 0)));
442 1.1 elric #endif
443 1.1 elric
444 1.1 elric #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
445 1.1 elric #ifndef HAVE_ASPRINTF
446 1.1 elric #define asprintf rk_asprintf
447 1.1 elric #endif
448 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
449 1.1 elric rk_asprintf (char **, const char *, ...)
450 1.1 elric __attribute__ ((format (printf, 2, 3)));
451 1.1 elric #endif
452 1.1 elric
453 1.1 elric #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
454 1.1 elric #ifndef HAVE_VASPRINTF
455 1.1 elric #define vasprintf rk_vasprintf
456 1.1 elric #endif
457 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
458 1.1 elric rk_vasprintf (char **, const char *, va_list)
459 1.1 elric __attribute__((format (printf, 2, 0)));
460 1.1 elric #endif
461 1.1 elric
462 1.1 elric #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
463 1.1 elric #ifndef HAVE_ASNPRINTF
464 1.1 elric #define asnprintf rk_asnprintf
465 1.1 elric #endif
466 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
467 1.1 elric rk_asnprintf (char **, size_t, const char *, ...)
468 1.1 elric __attribute__ ((format (printf, 3, 4)));
469 1.1 elric #endif
470 1.1 elric
471 1.1 elric #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
472 1.1 elric #ifndef HAVE_VASNPRINTF
473 1.1 elric #define vasnprintf rk_vasnprintf
474 1.1 elric #endif
475 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
476 1.1 elric vasnprintf (char **, size_t, const char *, va_list)
477 1.1 elric __attribute__((format (printf, 3, 0)));
478 1.1 elric #endif
479 1.1 elric
480 1.1 elric #ifndef HAVE_STRDUP
481 1.1 elric #define strdup rk_strdup
482 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
483 1.1 elric #endif
484 1.1 elric
485 1.1 elric #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
486 1.1 elric #ifndef HAVE_STRNDUP
487 1.1 elric #define strndup rk_strndup
488 1.1 elric #endif
489 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
490 1.1 elric #endif
491 1.1 elric
492 1.1 elric #ifndef HAVE_STRLWR
493 1.1 elric #define strlwr rk_strlwr
494 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
495 1.1 elric #endif
496 1.1 elric
497 1.1 elric #ifndef HAVE_STRNLEN
498 1.1 elric #define strnlen rk_strnlen
499 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
500 1.1 elric #endif
501 1.1 elric
502 1.1 elric #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
503 1.1 elric #ifndef HAVE_STRSEP
504 1.1 elric #define strsep rk_strsep
505 1.1 elric #endif
506 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
507 1.1 elric #endif
508 1.1 elric
509 1.1 elric #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
510 1.1 elric #ifndef HAVE_STRSEP_COPY
511 1.1 elric #define strsep_copy rk_strsep_copy
512 1.1 elric #endif
513 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
514 1.1 elric #endif
515 1.1 elric
516 1.1 elric #ifndef HAVE_STRCASECMP
517 1.1 elric #define strcasecmp rk_strcasecmp
518 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
519 1.1 elric #endif
520 1.1 elric
521 1.1 elric #ifdef NEED_FCLOSE_PROTO
522 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
523 1.1 elric #endif
524 1.1 elric
525 1.1 elric #ifdef NEED_STRTOK_R_PROTO
526 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
527 1.1 elric #endif
528 1.1 elric
529 1.1 elric #ifndef HAVE_STRUPR
530 1.1 elric #define strupr rk_strupr
531 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
532 1.1 elric #endif
533 1.1 elric
534 1.1 elric #ifndef HAVE_STRLCPY
535 1.1 elric #define strlcpy rk_strlcpy
536 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
537 1.1 elric #endif
538 1.1 elric
539 1.1 elric #ifndef HAVE_STRLCAT
540 1.1 elric #define strlcat rk_strlcat
541 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
542 1.1 elric #endif
543 1.1 elric
544 1.1 elric #ifndef HAVE_GETDTABLESIZE
545 1.1 elric #define getdtablesize rk_getdtablesize
546 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
547 1.1 elric #endif
548 1.1 elric
549 1.1 elric #if !defined(HAVE_STRERROR) && !defined(strerror)
550 1.1 elric #define strerror rk_strerror
551 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
552 1.1 elric #endif
553 1.1 elric
554 1.1 elric #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
555 1.1 elric int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
556 1.1 elric #else
557 1.1 elric #define rk_strerror_r strerror_r
558 1.1 elric #endif
559 1.1 elric
560 1.1 elric #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
561 1.1 elric #ifndef HAVE_HSTRERROR
562 1.1 elric #define hstrerror rk_hstrerror
563 1.1 elric #endif
564 1.1 elric /* This causes a fatal error under Psoriasis */
565 1.1 elric #ifndef SunOS
566 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
567 1.1 elric #endif
568 1.1 elric #endif
569 1.1 elric
570 1.1 elric #if !HAVE_DECL_H_ERRNO
571 1.1 elric extern int h_errno;
572 1.1 elric #endif
573 1.1 elric
574 1.1 elric #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
575 1.1 elric #ifndef HAVE_INET_ATON
576 1.1 elric #define inet_aton rk_inet_aton
577 1.1 elric #endif
578 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
579 1.1 elric #endif
580 1.1 elric
581 1.1 elric #ifndef HAVE_INET_NTOP
582 1.1 elric #define inet_ntop rk_inet_ntop
583 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
584 1.1 elric inet_ntop(int af, const void *src, char *dst, size_t size);
585 1.1 elric #endif
586 1.1 elric
587 1.1 elric #ifndef HAVE_INET_PTON
588 1.1 elric #define inet_pton rk_inet_pton
589 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
590 1.1 elric inet_pton(int, const char *, void *);
591 1.1 elric #endif
592 1.1 elric
593 1.1 elric #ifndef HAVE_GETCWD
594 1.1 elric #define getcwd rk_getcwd
595 1.1 elric ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
596 1.1 elric #endif
597 1.1 elric
598 1.1 elric #ifdef HAVE_PWD_H
599 1.1 elric #include <pwd.h>
600 1.1 elric ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
601 1.1 elric ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
602 1.1 elric #endif
603 1.1 elric
604 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
605 1.1 elric
606 1.1 elric #ifndef HAVE_SETEUID
607 1.1 elric #define seteuid rk_seteuid
608 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
609 1.1 elric #endif
610 1.1 elric
611 1.1 elric #ifndef HAVE_SETEGID
612 1.1 elric #define setegid rk_setegid
613 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
614 1.1 elric #endif
615 1.1 elric
616 1.1 elric #ifndef HAVE_LSTAT
617 1.1 elric #define lstat rk_lstat
618 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
619 1.1 elric #endif
620 1.1 elric
621 1.1 elric #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
622 1.1 elric #ifndef HAVE_MKSTEMP
623 1.1 elric #define mkstemp rk_mkstemp
624 1.1 elric #endif
625 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
626 1.1 elric #endif
627 1.1 elric
628 1.1 elric #ifndef HAVE_CGETENT
629 1.1 elric #define cgetent rk_cgetent
630 1.1 elric #define cgetstr rk_cgetstr
631 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
632 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
633 1.1 elric #endif
634 1.1 elric
635 1.1 elric #ifndef HAVE_INITGROUPS
636 1.1 elric #define initgroups rk_initgroups
637 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
638 1.1 elric #endif
639 1.1 elric
640 1.1 elric #ifndef HAVE_FCHOWN
641 1.1 elric #define fchown rk_fchown
642 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
643 1.1 elric #endif
644 1.1 elric
645 1.1 elric #ifdef RENAME_DOES_NOT_UNLINK
646 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
647 1.1 elric #else
648 1.1 elric #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
649 1.1 elric #endif
650 1.1 elric
651 1.1 elric #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
652 1.1 elric #ifndef HAVE_DAEMON
653 1.1 elric #define daemon rk_daemon
654 1.1 elric #endif
655 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
656 1.1 elric #endif
657 1.1 elric
658 1.1 elric #ifndef HAVE_CHOWN
659 1.1 elric #define chown rk_chown
660 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
661 1.1 elric #endif
662 1.1 elric
663 1.1 elric #ifndef HAVE_RCMD
664 1.1 elric #define rcmd rk_rcmd
665 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
666 1.1 elric rcmd(char **, unsigned short, const char *,
667 1.1 elric const char *, const char *, int *);
668 1.1 elric #endif
669 1.1 elric
670 1.1 elric #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
671 1.1 elric #ifndef HAVE_INNETGR
672 1.1 elric #define innetgr rk_innetgr
673 1.1 elric #endif
674 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
675 1.1 elric const char*, const char*);
676 1.1 elric #endif
677 1.1 elric
678 1.1 elric #ifndef HAVE_IRUSEROK
679 1.1 elric #define iruserok rk_iruserok
680 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
681 1.1 elric const char *, const char *);
682 1.1 elric #endif
683 1.1 elric
684 1.1 elric #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
685 1.1 elric #ifndef HAVE_GETHOSTNAME
686 1.1 elric #define gethostname rk_gethostname
687 1.1 elric #endif
688 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
689 1.1 elric #endif
690 1.1 elric
691 1.1 elric #ifndef HAVE_WRITEV
692 1.1 elric #define writev rk_writev
693 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
694 1.1 elric writev(int, const struct iovec *, int);
695 1.1 elric #endif
696 1.1 elric
697 1.1 elric #ifndef HAVE_READV
698 1.1 elric #define readv rk_readv
699 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
700 1.1 elric readv(int, const struct iovec *, int);
701 1.1 elric #endif
702 1.1 elric
703 1.1 elric #ifndef HAVE_PIDFILE
704 1.1 elric #ifdef NO_PIDFILES
705 1.1 elric #define pidfile(x) ((void) 0)
706 1.1 elric #else
707 1.1 elric #define pidfile rk_pidfile
708 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
709 1.1 elric #endif
710 1.1 elric #endif
711 1.1 elric
712 1.1 elric #ifndef HAVE_BSWAP32
713 1.1 elric #define bswap32 rk_bswap32
714 1.1 elric ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
715 1.1 elric #endif
716 1.1 elric
717 1.1 elric #ifndef HAVE_BSWAP16
718 1.1 elric #define bswap16 rk_bswap16
719 1.1 elric ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
720 1.1 elric #endif
721 1.1 elric
722 1.1 elric #ifndef HAVE_FLOCK
723 1.1 elric #ifndef LOCK_SH
724 1.1 elric #define LOCK_SH 1 /* Shared lock */
725 1.1 elric #endif
726 1.1 elric #ifndef LOCK_EX
727 1.1 elric #define LOCK_EX 2 /* Exclusive lock */
728 1.1 elric #endif
729 1.1 elric #ifndef LOCK_NB
730 1.1 elric #define LOCK_NB 4 /* Don't block when locking */
731 1.1 elric #endif
732 1.1 elric #ifndef LOCK_UN
733 1.1 elric #define LOCK_UN 8 /* Unlock */
734 1.1 elric #endif
735 1.1 elric
736 1.1 elric #define flock(_x,_y) rk_flock(_x,_y)
737 1.1 elric int rk_flock(int fd, int operation);
738 1.1 elric #endif /* HAVE_FLOCK */
739 1.1 elric
740 1.1 elric #ifndef HAVE_DIRFD
741 1.1 elric #ifdef HAVE_DIR_DD_FD
742 1.1 elric #define dirfd(x) ((x)->dd_fd)
743 1.1 elric #else
744 1.1 elric #ifndef _WIN32 /* Windows code never calls dirfd */
745 1.1 elric #error Missing dirfd() and ->dd_fd
746 1.1 elric #endif
747 1.1 elric #endif
748 1.1 elric #endif
749 1.1 elric
750 1.1 elric ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
751 1.1 elric
752 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
753 1.1 elric
754 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
755 1.1 elric
756 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
757 1.1 elric
758 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
759 1.1 elric
760 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
761 1.1 elric roken_vmconcat (char **, size_t, va_list);
762 1.1 elric
763 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
764 1.1 elric net_write (rk_socket_t, const void *, size_t);
765 1.1 elric
766 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
767 1.1 elric net_read (rk_socket_t, void *, size_t);
768 1.1 elric
769 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
770 1.1 elric issuid(void);
771 1.1 elric
772 1.1 elric #ifndef HAVE_STRUCT_WINSIZE
773 1.1 elric struct winsize {
774 1.1 elric unsigned short ws_row, ws_col;
775 1.1 elric unsigned short ws_xpixel, ws_ypixel;
776 1.1 elric };
777 1.1 elric #endif
778 1.1 elric
779 1.2 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *);
780 1.1 elric
781 1.1 elric #ifndef HAVE_VSYSLOG
782 1.1 elric #define vsyslog rk_vsyslog
783 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
784 1.1 elric #endif
785 1.1 elric
786 1.1 elric #ifndef HAVE_GETOPT
787 1.1 elric #define getopt rk_getopt
788 1.1 elric #define optarg rk_optarg
789 1.1 elric #define optind rk_optind
790 1.1 elric #define opterr rk_opterr
791 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
792 1.1 elric getopt(int nargc, char * const *nargv, const char *ostr);
793 1.1 elric #endif
794 1.1 elric
795 1.1 elric #if !HAVE_DECL_OPTARG
796 1.1 elric ROKEN_LIB_VARIABLE extern char *optarg;
797 1.1 elric #endif
798 1.1 elric #if !HAVE_DECL_OPTIND
799 1.1 elric ROKEN_LIB_VARIABLE extern int optind;
800 1.1 elric #endif
801 1.1 elric #if !HAVE_DECL_OPTERR
802 1.1 elric ROKEN_LIB_VARIABLE extern int opterr;
803 1.1 elric #endif
804 1.1 elric
805 1.1 elric #ifndef HAVE_GETIPNODEBYNAME
806 1.1 elric #define getipnodebyname rk_getipnodebyname
807 1.1 elric ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
808 1.1 elric getipnodebyname (const char *, int, int, int *);
809 1.1 elric #endif
810 1.1 elric
811 1.1 elric #ifndef HAVE_GETIPNODEBYADDR
812 1.1 elric #define getipnodebyaddr rk_getipnodebyaddr
813 1.1 elric ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
814 1.1 elric getipnodebyaddr (const void *, size_t, int, int *);
815 1.1 elric #endif
816 1.1 elric
817 1.1 elric #ifndef HAVE_FREEHOSTENT
818 1.1 elric #define freehostent rk_freehostent
819 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
820 1.1 elric freehostent (struct hostent *);
821 1.1 elric #endif
822 1.1 elric
823 1.1 elric #ifndef HAVE_COPYHOSTENT
824 1.1 elric #define copyhostent rk_copyhostent
825 1.1 elric ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
826 1.1 elric copyhostent (const struct hostent *);
827 1.1 elric #endif
828 1.1 elric
829 1.1 elric #ifndef HAVE_SOCKLEN_T
830 1.1 elric typedef int socklen_t;
831 1.1 elric #endif
832 1.1 elric
833 1.1 elric #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
834 1.1 elric
835 1.1 elric #ifndef HAVE_SA_FAMILY_T
836 1.1 elric typedef unsigned short sa_family_t;
837 1.1 elric #endif
838 1.1 elric
839 1.1 elric #ifdef HAVE_IPV6
840 1.1 elric #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
841 1.1 elric #else
842 1.1 elric #define _SS_MAXSIZE sizeof(struct sockaddr_in)
843 1.1 elric #endif
844 1.1 elric
845 1.1 elric #define _SS_ALIGNSIZE sizeof(unsigned long)
846 1.1 elric
847 1.1 elric #if HAVE_STRUCT_SOCKADDR_SA_LEN
848 1.1 elric
849 1.1 elric typedef unsigned char roken_sa_family_t;
850 1.1 elric
851 1.1 elric #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
852 1.1 elric #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
853 1.1 elric
854 1.1 elric struct sockaddr_storage {
855 1.1 elric unsigned char ss_len;
856 1.1 elric roken_sa_family_t ss_family;
857 1.1 elric char __ss_pad1[_SS_PAD1SIZE];
858 1.1 elric unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
859 1.1 elric };
860 1.1 elric
861 1.1 elric #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
862 1.1 elric
863 1.1 elric typedef unsigned short roken_sa_family_t;
864 1.1 elric
865 1.1 elric #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
866 1.1 elric #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
867 1.1 elric
868 1.1 elric struct sockaddr_storage {
869 1.1 elric roken_sa_family_t ss_family;
870 1.1 elric char __ss_pad1[_SS_PAD1SIZE];
871 1.1 elric unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
872 1.1 elric };
873 1.1 elric
874 1.1 elric #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
875 1.1 elric
876 1.1 elric #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
877 1.1 elric
878 1.1 elric #ifndef HAVE_STRUCT_ADDRINFO
879 1.1 elric struct addrinfo {
880 1.1 elric int ai_flags;
881 1.1 elric int ai_family;
882 1.1 elric int ai_socktype;
883 1.1 elric int ai_protocol;
884 1.1 elric size_t ai_addrlen;
885 1.1 elric char *ai_canonname;
886 1.1 elric struct sockaddr *ai_addr;
887 1.1 elric struct addrinfo *ai_next;
888 1.1 elric };
889 1.1 elric #endif
890 1.1 elric
891 1.1 elric #ifndef HAVE_GETADDRINFO
892 1.1 elric #define getaddrinfo rk_getaddrinfo
893 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
894 1.1 elric getaddrinfo(const char *,
895 1.1 elric const char *,
896 1.1 elric const struct addrinfo *,
897 1.1 elric struct addrinfo **);
898 1.1 elric #endif
899 1.1 elric
900 1.1 elric #ifndef HAVE_GETNAMEINFO
901 1.1 elric #define getnameinfo rk_getnameinfo
902 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
903 1.1 elric getnameinfo(const struct sockaddr *, socklen_t,
904 1.1 elric char *, size_t,
905 1.1 elric char *, size_t,
906 1.1 elric int);
907 1.1 elric #endif
908 1.1 elric
909 1.1 elric #ifndef HAVE_FREEADDRINFO
910 1.1 elric #define freeaddrinfo rk_freeaddrinfo
911 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
912 1.1 elric freeaddrinfo(struct addrinfo *);
913 1.1 elric #endif
914 1.1 elric
915 1.1 elric #ifndef HAVE_GAI_STRERROR
916 1.1 elric #define gai_strerror rk_gai_strerror
917 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
918 1.1 elric gai_strerror(int);
919 1.1 elric #endif
920 1.1 elric
921 1.1 elric #ifdef NO_SLEEP
922 1.1 elric
923 1.1 elric ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
924 1.1 elric sleep(unsigned int seconds);
925 1.1 elric
926 1.1 elric #endif
927 1.1 elric
928 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
929 1.1 elric getnameinfo_verified(const struct sockaddr *, socklen_t,
930 1.1 elric char *, size_t,
931 1.1 elric char *, size_t,
932 1.1 elric int);
933 1.1 elric
934 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
935 1.1 elric roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
936 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
937 1.1 elric roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
938 1.1 elric
939 1.1 elric #ifndef HAVE_STRFTIME
940 1.1 elric #define strftime rk_strftime
941 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
942 1.1 elric strftime (char *, size_t, const char *, const struct tm *);
943 1.1 elric #endif
944 1.1 elric
945 1.1 elric #ifndef HAVE_STRPTIME
946 1.1 elric #define strptime rk_strptime
947 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
948 1.1 elric strptime (const char *, const char *, struct tm *);
949 1.1 elric #endif
950 1.1 elric
951 1.1 elric #ifndef HAVE_GETTIMEOFDAY
952 1.1 elric #define gettimeofday rk_gettimeofday
953 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
954 1.1 elric gettimeofday (struct timeval *, void *);
955 1.1 elric #endif
956 1.1 elric
957 1.1 elric #ifndef HAVE_EMALLOC
958 1.1 elric #define emalloc rk_emalloc
959 1.1 elric ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
960 1.1 elric #endif
961 1.1 elric #ifndef HAVE_ECALLOC
962 1.1 elric #define ecalloc rk_ecalloc
963 1.1 elric ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
964 1.1 elric #endif
965 1.1 elric #ifndef HAVE_EREALLOC
966 1.1 elric #define erealloc rk_erealloc
967 1.1 elric ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
968 1.1 elric #endif
969 1.1 elric #ifndef HAVE_ESTRDUP
970 1.1 elric #define estrdup rk_estrdup
971 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
972 1.1 elric #endif
973 1.1 elric
974 1.1 elric /*
975 1.1 elric * kludges and such
976 1.1 elric */
977 1.1 elric
978 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
979 1.1 elric roken_gethostby_setup(const char*, const char*);
980 1.1 elric ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
981 1.1 elric roken_gethostbyname(const char*);
982 1.1 elric ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
983 1.1 elric roken_gethostbyaddr(const void*, size_t, int);
984 1.1 elric
985 1.1 elric #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
986 1.1 elric #define roken_getservbyname(x,y) getservbyname(x,y)
987 1.1 elric #else
988 1.1 elric #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
989 1.1 elric #endif
990 1.1 elric
991 1.1 elric #ifdef OPENLOG_PROTO_COMPATIBLE
992 1.1 elric #define roken_openlog(a,b,c) openlog(a,b,c)
993 1.1 elric #else
994 1.1 elric #define roken_openlog(a,b,c) openlog((char *)a,b,c)
995 1.1 elric #endif
996 1.1 elric
997 1.1 elric #ifdef GETSOCKNAME_PROTO_COMPATIBLE
998 1.1 elric #define roken_getsockname(a,b,c) getsockname(a,b,c)
999 1.1 elric #else
1000 1.1 elric #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1001 1.1 elric #endif
1002 1.1 elric
1003 1.1 elric #ifndef HAVE_SETPROGNAME
1004 1.1 elric #define setprogname rk_setprogname
1005 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
1006 1.1 elric #endif
1007 1.1 elric
1008 1.1 elric #ifndef HAVE_GETPROGNAME
1009 1.1 elric #define getprogname rk_getprogname
1010 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
1011 1.1 elric #endif
1012 1.1 elric
1013 1.1 elric #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1014 1.1 elric extern const char *__progname;
1015 1.1 elric #endif
1016 1.1 elric
1017 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1018 1.1 elric mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
1019 1.1 elric
1020 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1021 1.1 elric mini_inetd (int, rk_socket_t *);
1022 1.1 elric
1023 1.1 elric #ifndef HAVE_LOCALTIME_R
1024 1.1 elric #define localtime_r rk_localtime_r
1025 1.1 elric ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1026 1.1 elric localtime_r(const time_t *, struct tm *);
1027 1.1 elric #endif
1028 1.1 elric
1029 1.1 elric #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1030 1.1 elric #ifndef HAVE_STRSVIS
1031 1.1 elric #define strsvis rk_strsvis
1032 1.1 elric #endif
1033 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1034 1.1 elric strsvis(char *, const char *, int, const char *);
1035 1.1 elric #endif
1036 1.1 elric
1037 1.1 elric #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1038 1.1 elric #ifndef HAVE_STRSVISX
1039 1.1 elric #define strsvisx rk_strsvisx
1040 1.1 elric #endif
1041 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1042 1.1 elric strsvisx(char *, const char *, size_t, int, const char *);
1043 1.1 elric #endif
1044 1.1 elric
1045 1.1 elric #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1046 1.1 elric #ifndef HAVE_STRUNVIS
1047 1.1 elric #define strunvis rk_strunvis
1048 1.1 elric #endif
1049 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1050 1.1 elric strunvis(char *, const char *);
1051 1.1 elric #endif
1052 1.1 elric
1053 1.1 elric #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1054 1.1 elric #ifndef HAVE_STRVIS
1055 1.1 elric #define strvis rk_strvis
1056 1.1 elric #endif
1057 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1058 1.1 elric strvis(char *, const char *, int);
1059 1.1 elric #endif
1060 1.1 elric
1061 1.1 elric #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1062 1.1 elric #ifndef HAVE_STRVISX
1063 1.1 elric #define strvisx rk_strvisx
1064 1.1 elric #endif
1065 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1066 1.1 elric strvisx(char *, const char *, size_t, int);
1067 1.1 elric #endif
1068 1.1 elric
1069 1.1 elric #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1070 1.1 elric #ifndef HAVE_SVIS
1071 1.1 elric #define svis rk_svis
1072 1.1 elric #endif
1073 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1074 1.1 elric svis(char *, int, int, int, const char *);
1075 1.1 elric #endif
1076 1.1 elric
1077 1.1 elric #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1078 1.1 elric #ifndef HAVE_UNVIS
1079 1.1 elric #define unvis rk_unvis
1080 1.1 elric #endif
1081 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1082 1.1 elric unvis(char *, int, int *, int);
1083 1.1 elric #endif
1084 1.1 elric
1085 1.1 elric #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1086 1.1 elric #ifndef HAVE_VIS
1087 1.1 elric #define vis rk_vis
1088 1.1 elric #endif
1089 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1090 1.1 elric vis(char *, int, int, int);
1091 1.1 elric #endif
1092 1.1 elric
1093 1.1 elric #if !defined(HAVE_CLOSEFROM)
1094 1.1 elric #define closefrom rk_closefrom
1095 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1096 1.1 elric closefrom(int);
1097 1.1 elric #endif
1098 1.1 elric
1099 1.1 elric #if !defined(HAVE_TIMEGM)
1100 1.1 elric #define timegm rk_timegm
1101 1.1 elric ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1102 1.1 elric rk_timegm(struct tm *tm);
1103 1.1 elric #endif
1104 1.1 elric
1105 1.1 elric #ifdef NEED_QSORT
1106 1.1 elric #define qsort rk_qsort
1107 1.1 elric void
1108 1.1 elric rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1109 1.1 elric #endif
1110 1.1 elric
1111 1.1 elric #if defined(HAVE_ARC4RANDOM)
1112 1.1 elric #define rk_random() arc4random()
1113 1.1 elric #elif defined(HAVE_RANDOM)
1114 1.1 elric #define rk_random() random()
1115 1.1 elric #else
1116 1.1 elric #define rk_random() rand()
1117 1.1 elric #endif
1118 1.1 elric
1119 1.1 elric #ifndef HAVE_TDELETE
1120 1.1 elric #define tdelete(a,b,c) rk_tdelete(a,b,c)
1121 1.1 elric #endif
1122 1.1 elric #ifndef HAVE_TFIND
1123 1.1 elric #define tfind(a,b,c) rk_tfind(a,b,c)
1124 1.1 elric #endif
1125 1.1 elric #ifndef HAVE_TSEARCH
1126 1.1 elric #define tsearch(a,b,c) rk_tsearch(a,b,c)
1127 1.1 elric #endif
1128 1.1 elric #ifndef HAVE_TWALK
1129 1.1 elric #define twalk(a,b) rk_twalk(a,b)
1130 1.1 elric #endif
1131 1.1 elric
1132 1.1 elric #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1133 1.1 elric #undef socket
1134 1.1 elric #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1135 1.1 elric int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1136 1.1 elric #endif
1137 1.1 elric
1138 1.1 elric #ifdef SOCKET_WRAPPER_REPLACE
1139 1.1 elric #include <socket_wrapper.h>
1140 1.1 elric #endif
1141 1.1 elric
1142 1.1 elric ROKEN_CPP_END
1143