3 * Copyright (c) 1995-2005 Kungliga Tekniska Högskolan
4 * (Royal Institute of Technology, Stockholm, Sweden).
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
44 #ifndef ROKEN_LIB_FUNCTION
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)
51 # define ROKEN_LIB_FUNCTION
52 # define ROKEN_LIB_VARIABLE
55 #define ROKEN_LIB_FUNCTION
56 #define ROKEN_LIB_CALL
57 #define ROKEN_LIB_VARIABLE
62 /* Declarations for Microsoft Windows */
68 * error codes for inet_ntop/inet_pton
70 typedef SOCKET rk_socket_t;
72 #define rk_closesocket(x) closesocket(x)
73 #define rk_INVALID_SOCKET INVALID_SOCKET
74 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
75 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
76 #define rk_SOCK_ERRNO WSAGetLastError()
78 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp);
80 #define rk_SOCK_INIT() rk_WSAStartup()
81 #define rk_SOCK_EXIT() rk_WSACleanup()
83 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
84 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
86 #else /* not WinSock */
88 typedef int rk_socket_t;
90 #define rk_closesocket(x) close(x)
91 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
92 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
93 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
94 #define rk_SOCK_ERRNO errno
95 #define rk_INVALID_SOCKET (-1)
97 #define rk_SOCK_INIT() 0
98 #define rk_SOCK_EXIT() do { } while(0)
102 #ifndef IN_LOOPBACKNET
103 #define IN_LOOPBACKNET 127
107 #ifndef HAVE_STDINT_H
111 /* Declarations for Microsoft Visual C runtime on Windows */
117 #ifndef __BIT_TYPES_DEFINED__
118 #define __BIT_TYPES_DEFINED__
120 typedef __int8 int8_t;
121 typedef __int16 int16_t;
122 typedef __int32 int32_t;
123 typedef __int64 int64_t;
124 typedef unsigned __int8 uint8_t;
125 typedef unsigned __int16 uint16_t;
126 typedef unsigned __int32 uint32_t;
127 typedef unsigned __int64 uint64_t;
128 typedef uint8_t u_int8_t;
129 typedef uint16_t u_int16_t;
130 typedef uint32_t u_int32_t;
131 typedef uint64_t u_int64_t;
133 #endif /* __BIT_TYPES_DEFINED__ */
135 #define UNREACHABLE(x) x
136 #define UNUSED_ARGUMENT(x) ((void) x)
138 #define RETSIGTYPE void
140 #define VOID_RETSIGTYPE 1
142 #ifdef VOID_RETSIGTYPE
143 #define SIGRETURN(x) return
145 #define SIGRETURN(x) return (RETSIGTYPE)(x)
152 typedef unsigned int gid_t;
154 typedef unsigned int uid_t;
156 typedef unsigned short mode_t;
161 #define inline __inline
166 #define UNREACHABLE(x)
167 #define UNUSED_ARGUMENT(x)
175 #ifdef HAVE_SYS_PARAM_H
176 #include <sys/param.h>
178 #ifdef HAVE_INTTYPES_H
179 #include <inttypes.h>
181 #ifdef HAVE_SYS_TYPES_H
182 #include <sys/types.h>
184 #ifdef HAVE_SYS_BITYPES_H
185 #include <sys/bitypes.h>
187 #ifdef HAVE_BIND_BITYPES_H
188 #include <bind/bitypes.h>
190 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
191 #include <netinet/in6_machtypes.h>
196 #ifdef HAVE_SYS_SOCKET_H
197 #include <sys/socket.h>
199 #ifdef HAVE_SYS_UIO_H
205 #ifdef HAVE_SYS_STAT_H
206 #include <sys/stat.h>
208 #ifdef HAVE_NETINET_IN_H
209 #include <netinet/in.h>
211 #ifdef HAVE_NETINET_IN6_H
212 #include <netinet/in6.h>
214 #ifdef HAVE_NETINET6_IN6_H
215 #include <netinet6/in6.h>
217 #ifdef HAVE_ARPA_INET_H
218 #include <arpa/inet.h>
223 #ifdef HAVE_ARPA_NAMESER_H
224 #include <arpa/nameser.h>
239 #ifdef HAVE_TERMIOS_H
242 #ifdef HAVE_SYS_IOCTL_H
243 #include <sys/ioctl.h>
245 #ifdef TIME_WITH_SYS_TIME
246 #include <sys/time.h>
248 #elif defined(HAVE_SYS_TIME_H)
249 #include <sys/time.h>
262 #ifdef BACKSLASH_PATH_DELIM
263 #define rk_PATH_DELIM '\\'
267 #ifndef SSIZE_T_DEFINED
272 typedef __int64 ssize_t;
276 #define SSIZE_T_DEFINED
277 #endif /* SSIZE_T_DEFINED */
278 #endif /* HAVE_SSIZE_T */
280 #include <roken-common.h>
284 #ifdef HAVE_UINTPTR_T
285 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
287 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
290 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
291 #define setsid _setsid
295 /* Additional macros for Visual C/C++ runtime */
299 #define getpid _getpid
305 #define fsync _commit
307 /* The MSVC implementation of snprintf is not C99 compliant. */
308 #define snprintf rk_snprintf
309 #define vsnprintf rk_vsnprintf
310 #define vasnprintf rk_vasnprintf
311 #define vasprintf rk_vasprintf
312 #define asnprintf rk_asnprintf
313 #define asprintf rk_asprintf
315 #define _PIPE_BUFFER_SZ 8192
316 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
318 #define ftruncate(fd, sz) _chsize((fd), (sz))
320 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
321 rk_snprintf (char *str, size_t sz, const char *format, ...);
323 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
324 rk_asprintf (char **ret, const char *format, ...);
326 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
327 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
329 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
330 rk_vasprintf (char **ret, const char *format, va_list args);
332 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
333 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
335 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
336 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
338 /* missing stat.h predicates */
340 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
342 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
344 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
346 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
348 /* The following are not implemented:
355 #if !defined(ROKEN_NO_DEFINE_ALLOCATORS)
356 /* Ensure that a common memory allocator is used by all */
357 #define calloc rk_calloc
359 #define malloc rk_malloc
360 #define realloc rk_realloc
361 #define strdup rk_strdup
362 #define wcsdup rk_wcsdup
365 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
366 rk_calloc(size_t, size_t);
368 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
371 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
374 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
375 rk_realloc(void *, size_t);
377 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
378 rk_strdup(const char *);
380 ROKEN_LIB_FUNCTION unsigned short * ROKEN_LIB_CALL
381 rk_wcsdup(const unsigned short *);
383 #endif /* _MSC_VER */
387 /* While we are at it, define WinSock specific scatter gather socket
390 #define iovec _WSABUF
396 socklen_t msg_namelen;
397 struct iovec *msg_iov;
400 socklen_t msg_controllen;
404 #define sendmsg sendmsg_w32
406 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
407 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
409 #endif /* HAVE_WINSOCK */
412 #define putenv rk_putenv
413 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
416 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
418 #define setenv rk_setenv
420 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
423 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
424 #ifndef HAVE_UNSETENV
425 #define unsetenv rk_unsetenv
427 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
430 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
431 #ifndef HAVE_GETUSERSHELL
432 #define getusershell rk_getusershell
433 #define endusershell rk_endusershell
435 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
436 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
439 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
440 #ifndef HAVE_SNPRINTF
441 #define snprintf rk_snprintf
443 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
444 rk_snprintf (char *, size_t, const char *, ...)
445 __attribute__ ((format (printf, 3, 4)));
448 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
449 #ifndef HAVE_VSNPRINTF
450 #define vsnprintf rk_vsnprintf
452 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
453 rk_vsnprintf (char *, size_t, const char *, va_list)
454 __attribute__((format (printf, 3, 0)));
457 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
458 #ifndef HAVE_ASPRINTF
459 #define asprintf rk_asprintf
461 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
462 rk_asprintf (char **, const char *, ...)
463 __attribute__ ((format (printf, 2, 3)));
466 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
467 #ifndef HAVE_VASPRINTF
468 #define vasprintf rk_vasprintf
470 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
471 rk_vasprintf (char **, const char *, va_list)
472 __attribute__((format (printf, 2, 0)));
475 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
476 #ifndef HAVE_ASNPRINTF
477 #define asnprintf rk_asnprintf
479 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
480 rk_asnprintf (char **, size_t, const char *, ...)
481 __attribute__ ((format (printf, 3, 4)));
484 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
485 #ifndef HAVE_VASNPRINTF
486 #define vasnprintf rk_vasnprintf
488 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
489 vasnprintf (char **, size_t, const char *, va_list)
490 __attribute__((format (printf, 3, 0)));
494 #define strdup rk_strdup
495 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
498 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
500 #define strndup rk_strndup
502 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
506 #define strlwr rk_strlwr
507 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
511 #define strnlen rk_strnlen
512 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
515 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
517 #define strsep rk_strsep
519 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
522 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
523 #ifndef HAVE_STRSEP_COPY
524 #define strsep_copy rk_strsep_copy
526 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
529 #ifndef HAVE_STRCASECMP
530 #define strcasecmp rk_strcasecmp
531 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
534 #ifdef NEED_FCLOSE_PROTO
535 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
538 #ifdef NEED_STRTOK_R_PROTO
539 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
543 #define strupr rk_strupr
544 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
548 #define strlcpy rk_strlcpy
549 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
553 #define strlcat rk_strlcat
554 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
557 #ifndef HAVE_GETDTABLESIZE
558 #define getdtablesize rk_getdtablesize
559 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
562 #if !defined(HAVE_STRERROR) && !defined(strerror)
563 #define strerror rk_strerror
564 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
567 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
568 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
570 #define rk_strerror_r strerror_r
573 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
574 #ifndef HAVE_HSTRERROR
575 #define hstrerror rk_hstrerror
577 /* This causes a fatal error under Psoriasis */
579 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
583 #if !HAVE_DECL_H_ERRNO
587 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
588 #ifndef HAVE_INET_ATON
589 #define inet_aton rk_inet_aton
591 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
594 #ifndef HAVE_INET_NTOP
595 #define inet_ntop rk_inet_ntop
596 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
597 inet_ntop(int af, const void *src, char *dst, size_t size);
600 #ifndef HAVE_INET_PTON
601 #define inet_pton rk_inet_pton
602 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
603 inet_pton(int, const char *, void *);
607 #define getcwd rk_getcwd
608 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
613 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
614 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
617 #ifdef POSIX_GETPWNAM_R
618 #define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
620 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
621 rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
624 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
627 #define seteuid rk_seteuid
628 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
632 #define setegid rk_setegid
633 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
637 #define lstat rk_lstat
638 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
641 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
643 #define mkstemp rk_mkstemp
645 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
649 #define cgetent rk_cgetent
650 #define cgetstr rk_cgetstr
651 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
652 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
655 #ifndef HAVE_INITGROUPS
656 #define initgroups rk_initgroups
657 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
661 #define fchown rk_fchown
662 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
665 #ifdef RENAME_DOES_NOT_UNLINK
666 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
668 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
671 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
673 #define daemon rk_daemon
675 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
679 #define chown rk_chown
680 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
685 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
686 rcmd(char **, unsigned short, const char *,
687 const char *, const char *, int *);
690 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
692 #define innetgr rk_innetgr
694 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
695 const char*, const char*);
698 #ifndef HAVE_IRUSEROK
699 #define iruserok rk_iruserok
700 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
701 const char *, const char *);
704 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
705 #ifndef HAVE_GETHOSTNAME
706 #define gethostname rk_gethostname
708 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
712 #define writev rk_writev
713 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
714 writev(int, const struct iovec *, int);
718 #define readv rk_readv
719 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
720 readv(int, const struct iovec *, int);
725 #define pidfile(x) ((void) 0)
727 #define pidfile rk_pidfile
728 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
733 #define bswap32 rk_bswap32
734 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
738 #define bswap16 rk_bswap16
739 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
744 #define LOCK_SH 1 /* Shared lock */
747 #define LOCK_EX 2 /* Exclusive lock */
750 #define LOCK_NB 4 /* Don't block when locking */
753 #define LOCK_UN 8 /* Unlock */
756 #define flock(_x,_y) rk_flock(_x,_y)
757 int rk_flock(int fd, int operation);
758 #endif /* HAVE_FLOCK */
761 #ifdef HAVE_DIR_DD_FD
762 #define dirfd(x) ((x)->dd_fd)
764 #ifndef _WIN32 /* Windows code never calls dirfd */
765 #error Missing dirfd() and ->dd_fd
770 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
772 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
774 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
776 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
778 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
780 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
781 roken_vmconcat (char **, size_t, va_list);
783 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
784 net_write (rk_socket_t, const void *, size_t);
786 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
787 net_read (rk_socket_t, void *, size_t);
789 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
792 #ifndef HAVE_STRUCT_WINSIZE
794 unsigned short ws_row, ws_col;
795 unsigned short ws_xpixel, ws_ypixel;
799 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *);
802 #define vsyslog rk_vsyslog
803 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
807 #define getopt rk_getopt
808 #define optarg rk_optarg
809 #define optind rk_optind
810 #define opterr rk_opterr
811 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
812 getopt(int nargc, char * const *nargv, const char *ostr);
815 #if !HAVE_DECL_OPTARG
816 ROKEN_LIB_VARIABLE extern char *optarg;
818 #if !HAVE_DECL_OPTIND
819 ROKEN_LIB_VARIABLE extern int optind;
821 #if !HAVE_DECL_OPTERR
822 ROKEN_LIB_VARIABLE extern int opterr;
825 #ifndef HAVE_GETIPNODEBYNAME
826 #define getipnodebyname rk_getipnodebyname
827 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
828 getipnodebyname (const char *, int, int, int *);
831 #ifndef HAVE_GETIPNODEBYADDR
832 #define getipnodebyaddr rk_getipnodebyaddr
833 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
834 getipnodebyaddr (const void *, size_t, int, int *);
837 #ifndef HAVE_FREEHOSTENT
838 #define freehostent rk_freehostent
839 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
840 freehostent (struct hostent *);
843 #ifndef HAVE_COPYHOSTENT
844 #define copyhostent rk_copyhostent
845 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
846 copyhostent (const struct hostent *);
849 #ifndef HAVE_SOCKLEN_T
850 typedef int socklen_t;
853 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
855 #ifndef HAVE_SA_FAMILY_T
856 typedef unsigned short sa_family_t;
860 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
862 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
865 #define _SS_ALIGNSIZE sizeof(unsigned long)
867 #if HAVE_STRUCT_SOCKADDR_SA_LEN
869 typedef unsigned char roken_sa_family_t;
871 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
872 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
874 struct sockaddr_storage {
875 unsigned char ss_len;
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 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
883 typedef unsigned short roken_sa_family_t;
885 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
886 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
888 struct sockaddr_storage {
889 roken_sa_family_t ss_family;
890 char __ss_pad1[_SS_PAD1SIZE];
891 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
894 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
896 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
898 #ifndef HAVE_STRUCT_ADDRINFO
906 struct sockaddr *ai_addr;
907 struct addrinfo *ai_next;
911 #ifndef HAVE_GETADDRINFO
912 #define getaddrinfo rk_getaddrinfo
913 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
914 getaddrinfo(const char *,
916 const struct addrinfo *,
920 #ifndef HAVE_GETNAMEINFO
921 #define getnameinfo rk_getnameinfo
922 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
923 getnameinfo(const struct sockaddr *, socklen_t,
929 #ifndef HAVE_FREEADDRINFO
930 #define freeaddrinfo rk_freeaddrinfo
931 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
932 freeaddrinfo(struct addrinfo *);
935 #ifndef HAVE_GAI_STRERROR
936 #define gai_strerror rk_gai_strerror
937 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
943 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
944 sleep(unsigned int seconds);
948 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
949 getnameinfo_verified(const struct sockaddr *, socklen_t,
954 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
955 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
956 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
957 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
959 #ifndef HAVE_STRFTIME
960 #define strftime rk_strftime
961 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
962 strftime (char *, size_t, const char *, const struct tm *);
965 #ifndef HAVE_STRPTIME
966 #define strptime rk_strptime
967 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
968 strptime (const char *, const char *, struct tm *);
971 #ifndef HAVE_GETTIMEOFDAY
972 #define gettimeofday rk_gettimeofday
973 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
974 gettimeofday (struct timeval *, void *);
978 #define emalloc rk_emalloc
979 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
982 #define ecalloc rk_ecalloc
983 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
985 #ifndef HAVE_EREALLOC
986 #define erealloc rk_erealloc
987 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
990 #define estrdup rk_estrdup
991 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
998 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
999 roken_gethostby_setup(const char*, const char*);
1000 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
1001 roken_gethostbyname(const char*);
1002 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
1003 roken_gethostbyaddr(const void*, size_t, int);
1005 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
1006 #define roken_getservbyname(x,y) getservbyname(x,y)
1008 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
1011 #ifdef OPENLOG_PROTO_COMPATIBLE
1012 #define roken_openlog(a,b,c) openlog(a,b,c)
1014 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
1017 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
1018 #define roken_getsockname(a,b,c) getsockname(a,b,c)
1020 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1023 #ifndef HAVE_SETPROGNAME
1024 #define setprogname rk_setprogname
1025 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
1028 #ifndef HAVE_GETPROGNAME
1029 #define getprogname rk_getprogname
1030 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
1033 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1034 extern const char *__progname;
1037 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1038 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
1040 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1041 mini_inetd (int, rk_socket_t *);
1043 #ifndef HAVE_LOCALTIME_R
1044 #define localtime_r rk_localtime_r
1045 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1046 localtime_r(const time_t *, struct tm *);
1049 #if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO)
1050 #ifndef HAVE_STRTOLL
1051 #define strtoll rk_strtoll
1053 ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL
1054 strtoll(const char * nptr, char ** endptr, int base);
1057 #if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO)
1058 #ifndef HAVE_STRTOULL
1059 #define strtoull rk_strtoull
1061 ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL
1062 strtoull(const char * nptr, char ** endptr, int base);
1065 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1066 #ifndef HAVE_STRSVIS
1067 #define strsvis rk_strsvis
1069 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1070 strsvis(char *, const char *, int, const char *);
1073 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1074 #ifndef HAVE_STRSVISX
1075 #define strsvisx rk_strsvisx
1077 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1078 strsvisx(char *, const char *, size_t, int, const char *);
1081 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1082 #ifndef HAVE_STRUNVIS
1083 #define strunvis rk_strunvis
1085 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1086 strunvis(char *, const char *);
1089 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1091 #define strvis rk_strvis
1093 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1094 strvis(char *, const char *, int);
1097 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1098 #ifndef HAVE_STRVISX
1099 #define strvisx rk_strvisx
1101 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1102 strvisx(char *, const char *, size_t, int);
1105 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1107 #define svis rk_svis
1109 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1110 svis(char *, int, int, int, const char *);
1113 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1115 #define unvis rk_unvis
1117 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1118 unvis(char *, int, int *, int);
1121 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1125 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1126 vis(char *, int, int, int);
1129 #if !defined(HAVE_CLOSEFROM)
1130 #define closefrom rk_closefrom
1131 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1135 #if !defined(HAVE_TIMEGM)
1136 #define timegm rk_timegm
1137 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1138 rk_timegm(struct tm *tm);
1142 #define qsort rk_qsort
1144 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1147 #if defined(HAVE_ARC4RANDOM)
1148 #define rk_random() arc4random()
1149 #elif defined(HAVE_RANDOM)
1150 #define rk_random() random()
1152 #define rk_random() rand()
1155 #ifndef HAVE_TDELETE
1156 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1159 #define tfind(a,b,c) rk_tfind(a,b,c)
1161 #ifndef HAVE_TSEARCH
1162 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1165 #define twalk(a,b) rk_twalk(a,b)
1168 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1170 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1171 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1174 /* Microsoft VC 2010 POSIX definitions */
1175 #ifndef EAFNOSUPPORT
1176 #define EAFNOSUPPORT 102
1179 #define ENOTSOCK 128
1185 #define EOVERFLOW 132
1188 #define ETIMEDOUT 138
1191 #define EWOULDBLOCK 140
1195 #ifdef SOCKET_WRAPPER_REPLACE
1196 #include <socket_wrapper.h>