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