roken.h.in revision 1.6 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.6 christos #include <krb5/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.5 christos #ifdef POSIX_GETPWUID_R
654 1.5 christos #define rk_getpwuid_r(_u, _pw, _b, _sz, _pwd) getpwuid_r(_u, _pw, _b, _sz, _pwd)
655 1.5 christos #else
656 1.5 christos ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
657 1.5 christos rk_getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
658 1.5 christos #endif
659 1.5 christos
660 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
661 1.1 elric
662 1.1 elric #ifndef HAVE_SETEUID
663 1.1 elric #define seteuid rk_seteuid
664 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
665 1.1 elric #endif
666 1.1 elric
667 1.1 elric #ifndef HAVE_SETEGID
668 1.1 elric #define setegid rk_setegid
669 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
670 1.1 elric #endif
671 1.1 elric
672 1.1 elric #ifndef HAVE_LSTAT
673 1.1 elric #define lstat rk_lstat
674 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
675 1.1 elric #endif
676 1.1 elric
677 1.1 elric #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
678 1.1 elric #ifndef HAVE_MKSTEMP
679 1.1 elric #define mkstemp rk_mkstemp
680 1.1 elric #endif
681 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
682 1.1 elric #endif
683 1.1 elric
684 1.1 elric #ifndef HAVE_CGETENT
685 1.1 elric #define cgetent rk_cgetent
686 1.1 elric #define cgetstr rk_cgetstr
687 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
688 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
689 1.1 elric #endif
690 1.1 elric
691 1.1 elric #ifndef HAVE_INITGROUPS
692 1.1 elric #define initgroups rk_initgroups
693 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
694 1.1 elric #endif
695 1.1 elric
696 1.1 elric #ifndef HAVE_FCHOWN
697 1.1 elric #define fchown rk_fchown
698 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
699 1.1 elric #endif
700 1.1 elric
701 1.1 elric #ifdef RENAME_DOES_NOT_UNLINK
702 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
703 1.1 elric #else
704 1.1 elric #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
705 1.1 elric #endif
706 1.1 elric
707 1.4 christos #ifdef MKDIR_DOES_NOT_HAVE_MODE
708 1.4 christos #define mkdir rk_mkdir
709 1.4 christos #else
710 1.4 christos #define rk_mkdir(__rk_rn_name, __rk_rn_mode) mkdir(__rk_rn_name,__rk_rn_mode)
711 1.4 christos #endif
712 1.4 christos
713 1.4 christos
714 1.1 elric #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
715 1.1 elric #ifndef HAVE_DAEMON
716 1.1 elric #define daemon rk_daemon
717 1.1 elric #endif
718 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
719 1.1 elric #endif
720 1.1 elric
721 1.1 elric #ifndef HAVE_CHOWN
722 1.1 elric #define chown rk_chown
723 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
724 1.1 elric #endif
725 1.1 elric
726 1.1 elric #ifndef HAVE_RCMD
727 1.1 elric #define rcmd rk_rcmd
728 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
729 1.1 elric rcmd(char **, unsigned short, const char *,
730 1.1 elric const char *, const char *, int *);
731 1.1 elric #endif
732 1.1 elric
733 1.1 elric #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
734 1.1 elric #ifndef HAVE_INNETGR
735 1.1 elric #define innetgr rk_innetgr
736 1.1 elric #endif
737 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
738 1.1 elric const char*, const char*);
739 1.1 elric #endif
740 1.1 elric
741 1.1 elric #ifndef HAVE_IRUSEROK
742 1.1 elric #define iruserok rk_iruserok
743 1.4 christos ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
744 1.1 elric const char *, const char *);
745 1.1 elric #endif
746 1.1 elric
747 1.1 elric #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
748 1.1 elric #ifndef HAVE_GETHOSTNAME
749 1.1 elric #define gethostname rk_gethostname
750 1.1 elric #endif
751 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
752 1.1 elric #endif
753 1.1 elric
754 1.1 elric #ifndef HAVE_WRITEV
755 1.1 elric #define writev rk_writev
756 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
757 1.1 elric writev(int, const struct iovec *, int);
758 1.1 elric #endif
759 1.1 elric
760 1.1 elric #ifndef HAVE_READV
761 1.1 elric #define readv rk_readv
762 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
763 1.1 elric readv(int, const struct iovec *, int);
764 1.1 elric #endif
765 1.1 elric
766 1.1 elric #ifdef NO_PIDFILES
767 1.4 christos #define rk_pidfile(x) ((void) 0)
768 1.1 elric #else
769 1.4 christos ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_pidfile (const char*);
770 1.1 elric #endif
771 1.4 christos
772 1.4 christos #ifndef HAVE_BSWAP64
773 1.4 christos #define bswap64 rk_bswap64
774 1.4 christos ROKEN_LIB_FUNCTION uint64_t ROKEN_LIB_CALL bswap64(uint64_t);
775 1.1 elric #endif
776 1.1 elric
777 1.1 elric #ifndef HAVE_BSWAP32
778 1.1 elric #define bswap32 rk_bswap32
779 1.1 elric ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
780 1.1 elric #endif
781 1.1 elric
782 1.1 elric #ifndef HAVE_BSWAP16
783 1.1 elric #define bswap16 rk_bswap16
784 1.1 elric ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
785 1.1 elric #endif
786 1.1 elric
787 1.1 elric #ifndef HAVE_FLOCK
788 1.1 elric #ifndef LOCK_SH
789 1.1 elric #define LOCK_SH 1 /* Shared lock */
790 1.1 elric #endif
791 1.1 elric #ifndef LOCK_EX
792 1.1 elric #define LOCK_EX 2 /* Exclusive lock */
793 1.1 elric #endif
794 1.1 elric #ifndef LOCK_NB
795 1.1 elric #define LOCK_NB 4 /* Don't block when locking */
796 1.1 elric #endif
797 1.1 elric #ifndef LOCK_UN
798 1.1 elric #define LOCK_UN 8 /* Unlock */
799 1.1 elric #endif
800 1.1 elric
801 1.1 elric #define flock(_x,_y) rk_flock(_x,_y)
802 1.1 elric int rk_flock(int fd, int operation);
803 1.1 elric #endif /* HAVE_FLOCK */
804 1.1 elric
805 1.1 elric #ifndef HAVE_DIRFD
806 1.1 elric #ifdef HAVE_DIR_DD_FD
807 1.1 elric #define dirfd(x) ((x)->dd_fd)
808 1.1 elric #else
809 1.1 elric #ifndef _WIN32 /* Windows code never calls dirfd */
810 1.1 elric #error Missing dirfd() and ->dd_fd
811 1.1 elric #endif
812 1.1 elric #endif
813 1.1 elric #endif
814 1.1 elric
815 1.1 elric ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
816 1.1 elric
817 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
818 1.1 elric
819 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
820 1.1 elric
821 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
822 1.1 elric
823 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
824 1.1 elric
825 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
826 1.1 elric roken_vmconcat (char **, size_t, va_list);
827 1.1 elric
828 1.4 christos ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_prep(int, char **, char *);
829 1.4 christos ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_finish(const char *, int);
830 1.4 christos
831 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
832 1.1 elric net_write (rk_socket_t, const void *, size_t);
833 1.1 elric
834 1.1 elric ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
835 1.1 elric net_read (rk_socket_t, void *, size_t);
836 1.1 elric
837 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
838 1.1 elric issuid(void);
839 1.1 elric
840 1.1 elric #ifndef HAVE_STRUCT_WINSIZE
841 1.1 elric struct winsize {
842 1.1 elric unsigned short ws_row, ws_col;
843 1.1 elric unsigned short ws_xpixel, ws_ypixel;
844 1.1 elric };
845 1.1 elric #endif
846 1.1 elric
847 1.2 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *);
848 1.1 elric
849 1.1 elric #ifndef HAVE_VSYSLOG
850 1.1 elric #define vsyslog rk_vsyslog
851 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
852 1.1 elric #endif
853 1.1 elric
854 1.1 elric #ifndef HAVE_GETOPT
855 1.1 elric #define getopt rk_getopt
856 1.1 elric #define optarg rk_optarg
857 1.1 elric #define optind rk_optind
858 1.1 elric #define opterr rk_opterr
859 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
860 1.1 elric getopt(int nargc, char * const *nargv, const char *ostr);
861 1.1 elric #endif
862 1.1 elric
863 1.1 elric #if !HAVE_DECL_OPTARG
864 1.1 elric ROKEN_LIB_VARIABLE extern char *optarg;
865 1.1 elric #endif
866 1.1 elric #if !HAVE_DECL_OPTIND
867 1.1 elric ROKEN_LIB_VARIABLE extern int optind;
868 1.1 elric #endif
869 1.1 elric #if !HAVE_DECL_OPTERR
870 1.1 elric ROKEN_LIB_VARIABLE extern int opterr;
871 1.1 elric #endif
872 1.1 elric
873 1.1 elric #ifndef HAVE_GETIPNODEBYNAME
874 1.1 elric #define getipnodebyname rk_getipnodebyname
875 1.1 elric ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
876 1.1 elric getipnodebyname (const char *, int, int, int *);
877 1.1 elric #endif
878 1.1 elric
879 1.1 elric #ifndef HAVE_GETIPNODEBYADDR
880 1.1 elric #define getipnodebyaddr rk_getipnodebyaddr
881 1.1 elric ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
882 1.1 elric getipnodebyaddr (const void *, size_t, int, int *);
883 1.1 elric #endif
884 1.1 elric
885 1.1 elric #ifndef HAVE_FREEHOSTENT
886 1.1 elric #define freehostent rk_freehostent
887 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
888 1.1 elric freehostent (struct hostent *);
889 1.1 elric #endif
890 1.1 elric
891 1.1 elric #ifndef HAVE_COPYHOSTENT
892 1.1 elric #define copyhostent rk_copyhostent
893 1.1 elric ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
894 1.1 elric copyhostent (const struct hostent *);
895 1.1 elric #endif
896 1.1 elric
897 1.1 elric #ifndef HAVE_SOCKLEN_T
898 1.1 elric typedef int socklen_t;
899 1.1 elric #endif
900 1.1 elric
901 1.1 elric #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
902 1.1 elric
903 1.1 elric #ifndef HAVE_SA_FAMILY_T
904 1.1 elric typedef unsigned short sa_family_t;
905 1.1 elric #endif
906 1.1 elric
907 1.1 elric #ifdef HAVE_IPV6
908 1.1 elric #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
909 1.1 elric #else
910 1.1 elric #define _SS_MAXSIZE sizeof(struct sockaddr_in)
911 1.1 elric #endif
912 1.1 elric
913 1.1 elric #define _SS_ALIGNSIZE sizeof(unsigned long)
914 1.1 elric
915 1.1 elric #if HAVE_STRUCT_SOCKADDR_SA_LEN
916 1.1 elric
917 1.1 elric typedef unsigned char roken_sa_family_t;
918 1.1 elric
919 1.1 elric #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
920 1.1 elric #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
921 1.1 elric
922 1.1 elric struct sockaddr_storage {
923 1.1 elric unsigned char ss_len;
924 1.1 elric roken_sa_family_t ss_family;
925 1.1 elric char __ss_pad1[_SS_PAD1SIZE];
926 1.1 elric unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
927 1.1 elric };
928 1.1 elric
929 1.1 elric #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
930 1.1 elric
931 1.1 elric typedef unsigned short roken_sa_family_t;
932 1.1 elric
933 1.1 elric #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
934 1.1 elric #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
935 1.1 elric
936 1.1 elric struct sockaddr_storage {
937 1.1 elric roken_sa_family_t ss_family;
938 1.1 elric char __ss_pad1[_SS_PAD1SIZE];
939 1.1 elric unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
940 1.1 elric };
941 1.1 elric
942 1.1 elric #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
943 1.1 elric
944 1.1 elric #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
945 1.1 elric
946 1.1 elric #ifndef HAVE_STRUCT_ADDRINFO
947 1.1 elric struct addrinfo {
948 1.1 elric int ai_flags;
949 1.1 elric int ai_family;
950 1.1 elric int ai_socktype;
951 1.1 elric int ai_protocol;
952 1.1 elric size_t ai_addrlen;
953 1.1 elric char *ai_canonname;
954 1.1 elric struct sockaddr *ai_addr;
955 1.1 elric struct addrinfo *ai_next;
956 1.1 elric };
957 1.1 elric #endif
958 1.1 elric
959 1.1 elric #ifndef HAVE_GETADDRINFO
960 1.1 elric #define getaddrinfo rk_getaddrinfo
961 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
962 1.1 elric getaddrinfo(const char *,
963 1.1 elric const char *,
964 1.1 elric const struct addrinfo *,
965 1.1 elric struct addrinfo **);
966 1.1 elric #endif
967 1.1 elric
968 1.1 elric #ifndef HAVE_GETNAMEINFO
969 1.1 elric #define getnameinfo rk_getnameinfo
970 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
971 1.1 elric getnameinfo(const struct sockaddr *, socklen_t,
972 1.1 elric char *, size_t,
973 1.1 elric char *, size_t,
974 1.1 elric int);
975 1.1 elric #endif
976 1.1 elric
977 1.1 elric #ifndef HAVE_FREEADDRINFO
978 1.1 elric #define freeaddrinfo rk_freeaddrinfo
979 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
980 1.1 elric freeaddrinfo(struct addrinfo *);
981 1.1 elric #endif
982 1.1 elric
983 1.1 elric #ifndef HAVE_GAI_STRERROR
984 1.1 elric #define gai_strerror rk_gai_strerror
985 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
986 1.1 elric gai_strerror(int);
987 1.1 elric #endif
988 1.1 elric
989 1.1 elric #ifdef NO_SLEEP
990 1.1 elric
991 1.1 elric ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
992 1.1 elric sleep(unsigned int seconds);
993 1.1 elric
994 1.4 christos ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
995 1.4 christos usleep(unsigned int useconds);
996 1.4 christos
997 1.1 elric #endif
998 1.1 elric
999 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1000 1.1 elric getnameinfo_verified(const struct sockaddr *, socklen_t,
1001 1.1 elric char *, size_t,
1002 1.1 elric char *, size_t,
1003 1.1 elric int);
1004 1.1 elric
1005 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1006 1.4 christos roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
1007 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1008 1.1 elric roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
1009 1.1 elric
1010 1.1 elric #ifndef HAVE_STRFTIME
1011 1.1 elric #define strftime rk_strftime
1012 1.1 elric ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
1013 1.1 elric strftime (char *, size_t, const char *, const struct tm *);
1014 1.1 elric #endif
1015 1.1 elric
1016 1.1 elric #ifndef HAVE_STRPTIME
1017 1.1 elric #define strptime rk_strptime
1018 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1019 1.1 elric strptime (const char *, const char *, struct tm *);
1020 1.1 elric #endif
1021 1.1 elric
1022 1.1 elric #ifndef HAVE_GETTIMEOFDAY
1023 1.1 elric #define gettimeofday rk_gettimeofday
1024 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1025 1.1 elric gettimeofday (struct timeval *, void *);
1026 1.1 elric #endif
1027 1.1 elric
1028 1.1 elric #ifndef HAVE_EMALLOC
1029 1.1 elric #define emalloc rk_emalloc
1030 1.1 elric ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
1031 1.1 elric #endif
1032 1.1 elric #ifndef HAVE_ECALLOC
1033 1.1 elric #define ecalloc rk_ecalloc
1034 1.1 elric ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
1035 1.1 elric #endif
1036 1.1 elric #ifndef HAVE_EREALLOC
1037 1.1 elric #define erealloc rk_erealloc
1038 1.1 elric ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
1039 1.1 elric #endif
1040 1.1 elric #ifndef HAVE_ESTRDUP
1041 1.1 elric #define estrdup rk_estrdup
1042 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
1043 1.1 elric #endif
1044 1.1 elric
1045 1.1 elric /*
1046 1.1 elric * kludges and such
1047 1.1 elric */
1048 1.1 elric
1049 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1050 1.1 elric roken_gethostby_setup(const char*, const char*);
1051 1.1 elric ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
1052 1.1 elric roken_gethostbyname(const char*);
1053 1.4 christos ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
1054 1.1 elric roken_gethostbyaddr(const void*, size_t, int);
1055 1.1 elric
1056 1.1 elric #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
1057 1.1 elric #define roken_getservbyname(x,y) getservbyname(x,y)
1058 1.1 elric #else
1059 1.1 elric #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
1060 1.1 elric #endif
1061 1.1 elric
1062 1.1 elric #ifdef OPENLOG_PROTO_COMPATIBLE
1063 1.1 elric #define roken_openlog(a,b,c) openlog(a,b,c)
1064 1.1 elric #else
1065 1.1 elric #define roken_openlog(a,b,c) openlog((char *)a,b,c)
1066 1.1 elric #endif
1067 1.1 elric
1068 1.1 elric #ifdef GETSOCKNAME_PROTO_COMPATIBLE
1069 1.1 elric #define roken_getsockname(a,b,c) getsockname(a,b,c)
1070 1.1 elric #else
1071 1.1 elric #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1072 1.1 elric #endif
1073 1.1 elric
1074 1.1 elric #ifndef HAVE_SETPROGNAME
1075 1.1 elric #define setprogname rk_setprogname
1076 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
1077 1.1 elric #endif
1078 1.1 elric
1079 1.1 elric #ifndef HAVE_GETPROGNAME
1080 1.1 elric #define getprogname rk_getprogname
1081 1.1 elric ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
1082 1.1 elric #endif
1083 1.1 elric
1084 1.1 elric #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1085 1.1 elric extern const char *__progname;
1086 1.1 elric #endif
1087 1.1 elric
1088 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1089 1.1 elric mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
1090 1.1 elric
1091 1.1 elric ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1092 1.1 elric mini_inetd (int, rk_socket_t *);
1093 1.1 elric
1094 1.1 elric #ifndef HAVE_LOCALTIME_R
1095 1.1 elric #define localtime_r rk_localtime_r
1096 1.1 elric ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1097 1.1 elric localtime_r(const time_t *, struct tm *);
1098 1.1 elric #endif
1099 1.1 elric
1100 1.4 christos #if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO)
1101 1.4 christos #ifndef HAVE_STRTOLL
1102 1.4 christos #define strtoll rk_strtoll
1103 1.4 christos #endif
1104 1.4 christos ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL
1105 1.4 christos strtoll(const char * nptr, char ** endptr, int base);
1106 1.4 christos #endif
1107 1.4 christos
1108 1.4 christos #if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO)
1109 1.4 christos #ifndef HAVE_STRTOULL
1110 1.4 christos #define strtoull rk_strtoull
1111 1.4 christos #endif
1112 1.4 christos ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL
1113 1.4 christos strtoull(const char * nptr, char ** endptr, int base);
1114 1.4 christos #endif
1115 1.4 christos
1116 1.1 elric #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1117 1.1 elric #ifndef HAVE_STRSVIS
1118 1.1 elric #define strsvis rk_strsvis
1119 1.1 elric #endif
1120 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1121 1.1 elric strsvis(char *, const char *, int, const char *);
1122 1.1 elric #endif
1123 1.1 elric
1124 1.1 elric #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1125 1.1 elric #ifndef HAVE_STRSVISX
1126 1.1 elric #define strsvisx rk_strsvisx
1127 1.1 elric #endif
1128 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1129 1.1 elric strsvisx(char *, const char *, size_t, int, const char *);
1130 1.1 elric #endif
1131 1.1 elric
1132 1.1 elric #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1133 1.1 elric #ifndef HAVE_STRUNVIS
1134 1.1 elric #define strunvis rk_strunvis
1135 1.1 elric #endif
1136 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1137 1.1 elric strunvis(char *, const char *);
1138 1.1 elric #endif
1139 1.1 elric
1140 1.1 elric #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1141 1.1 elric #ifndef HAVE_STRVIS
1142 1.1 elric #define strvis rk_strvis
1143 1.1 elric #endif
1144 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1145 1.1 elric strvis(char *, const char *, int);
1146 1.1 elric #endif
1147 1.1 elric
1148 1.1 elric #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1149 1.1 elric #ifndef HAVE_STRVISX
1150 1.1 elric #define strvisx rk_strvisx
1151 1.1 elric #endif
1152 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1153 1.1 elric strvisx(char *, const char *, size_t, int);
1154 1.1 elric #endif
1155 1.1 elric
1156 1.1 elric #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1157 1.1 elric #ifndef HAVE_SVIS
1158 1.1 elric #define svis rk_svis
1159 1.1 elric #endif
1160 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1161 1.1 elric svis(char *, int, int, int, const char *);
1162 1.1 elric #endif
1163 1.1 elric
1164 1.1 elric #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1165 1.1 elric #ifndef HAVE_UNVIS
1166 1.1 elric #define unvis rk_unvis
1167 1.1 elric #endif
1168 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1169 1.1 elric unvis(char *, int, int *, int);
1170 1.1 elric #endif
1171 1.1 elric
1172 1.1 elric #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1173 1.1 elric #ifndef HAVE_VIS
1174 1.1 elric #define vis rk_vis
1175 1.1 elric #endif
1176 1.1 elric ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1177 1.1 elric vis(char *, int, int, int);
1178 1.1 elric #endif
1179 1.1 elric
1180 1.1 elric #if !defined(HAVE_CLOSEFROM)
1181 1.1 elric #define closefrom rk_closefrom
1182 1.1 elric ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1183 1.1 elric closefrom(int);
1184 1.1 elric #endif
1185 1.1 elric
1186 1.1 elric #if !defined(HAVE_TIMEGM)
1187 1.1 elric #define timegm rk_timegm
1188 1.1 elric ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1189 1.1 elric rk_timegm(struct tm *tm);
1190 1.1 elric #endif
1191 1.1 elric
1192 1.1 elric #ifdef NEED_QSORT
1193 1.1 elric #define qsort rk_qsort
1194 1.1 elric void
1195 1.1 elric rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1196 1.1 elric #endif
1197 1.1 elric
1198 1.4 christos #ifndef HAVE_MEMSET_S
1199 1.4 christos #define memset_s rk_memset_s
1200 1.4 christos ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL memset_s(void *s, size_t smax,
1201 1.4 christos int c, size_t n);
1202 1.4 christos #endif
1203 1.4 christos
1204 1.1 elric #if defined(HAVE_ARC4RANDOM)
1205 1.4 christos # define rk_random() arc4random()
1206 1.1 elric #elif defined(HAVE_RANDOM)
1207 1.4 christos # define rk_random() random()
1208 1.1 elric #else
1209 1.4 christos # ifdef HAVE_WIN32_RAND_S
1210 1.4 christos ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
1211 1.4 christos rk_random(void);
1212 1.4 christos # else
1213 1.4 christos # define rk_random() rand()
1214 1.4 christos # endif
1215 1.1 elric #endif
1216 1.1 elric
1217 1.1 elric #ifndef HAVE_TDELETE
1218 1.1 elric #define tdelete(a,b,c) rk_tdelete(a,b,c)
1219 1.1 elric #endif
1220 1.1 elric #ifndef HAVE_TFIND
1221 1.1 elric #define tfind(a,b,c) rk_tfind(a,b,c)
1222 1.1 elric #endif
1223 1.1 elric #ifndef HAVE_TSEARCH
1224 1.1 elric #define tsearch(a,b,c) rk_tsearch(a,b,c)
1225 1.1 elric #endif
1226 1.1 elric #ifndef HAVE_TWALK
1227 1.1 elric #define twalk(a,b) rk_twalk(a,b)
1228 1.1 elric #endif
1229 1.1 elric
1230 1.1 elric #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1231 1.1 elric #undef socket
1232 1.1 elric #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1233 1.1 elric int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1234 1.1 elric #endif
1235 1.1 elric
1236 1.4 christos /* Microsoft VC 2010 POSIX definitions */
1237 1.4 christos #ifndef EAFNOSUPPORT
1238 1.4 christos #define EAFNOSUPPORT 102
1239 1.4 christos #endif
1240 1.4 christos #ifndef EINPROGRESS
1241 1.4 christos #define EINPROGRESS 112
1242 1.4 christos #endif
1243 1.4 christos #ifndef ELOOP
1244 1.4 christos #define ELOOP 114
1245 1.4 christos #endif
1246 1.4 christos #ifndef ENOTSOCK
1247 1.4 christos #define ENOTSOCK 128
1248 1.4 christos #endif
1249 1.4 christos #ifndef ENOTSUP
1250 1.4 christos #define ENOTSUP 129
1251 1.4 christos #endif
1252 1.4 christos #ifndef EOVERFLOW
1253 1.4 christos #define EOVERFLOW 132
1254 1.4 christos #endif
1255 1.4 christos #ifndef ETIMEDOUT
1256 1.4 christos #define ETIMEDOUT 138
1257 1.4 christos #endif
1258 1.4 christos #ifndef EWOULDBLOCK
1259 1.4 christos #define EWOULDBLOCK 140
1260 1.4 christos #endif
1261 1.4 christos
1262 1.4 christos
1263 1.1 elric #ifdef SOCKET_WRAPPER_REPLACE
1264 1.1 elric #include <socket_wrapper.h>
1265 1.1 elric #endif
1266 1.1 elric
1267 1.1 elric ROKEN_CPP_END
1268