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