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
45 #ifndef ROKEN_LIB_FUNCTION
47 # define ROKEN_LIB_CALL __cdecl
48 # ifdef ROKEN_LIB_DYNAMIC
49 # define ROKEN_LIB_FUNCTION __declspec(dllimport)
50 # define ROKEN_LIB_VARIABLE __declspec(dllimport)
52 # define ROKEN_LIB_FUNCTION
53 # define ROKEN_LIB_VARIABLE
56 #define ROKEN_LIB_FUNCTION
57 #define ROKEN_LIB_CALL
58 #define ROKEN_LIB_VARIABLE
63 /* Declarations for Microsoft Windows */
69 * error codes for inet_ntop/inet_pton
71 typedef SOCKET rk_socket_t;
73 #define rk_closesocket(x) closesocket(x)
74 #define rk_INVALID_SOCKET INVALID_SOCKET
75 #define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
76 #define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
77 #define rk_SOCK_ERRNO WSAGetLastError()
79 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_IOCTL(SOCKET s, long cmd, int * argp);
81 #define rk_SOCK_INIT() rk_WSAStartup()
82 #define rk_SOCK_EXIT() rk_WSACleanup()
84 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
85 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
87 #else /* not WinSock */
89 typedef int rk_socket_t;
91 #define rk_closesocket(x) close(x)
92 #define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
93 #define rk_IS_BAD_SOCKET(s) ((s) < 0)
94 #define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
95 #define rk_SOCK_ERRNO errno
96 #define rk_INVALID_SOCKET (-1)
98 #define rk_SOCK_INIT() 0
99 #define rk_SOCK_EXIT() do { } while(0)
103 #ifndef IN_LOOPBACKNET
104 #define IN_LOOPBACKNET 127
108 #ifndef HAVE_STDINT_H
112 /* Declarations for Microsoft Visual C runtime on Windows */
118 #ifndef __BIT_TYPES_DEFINED__
119 #define __BIT_TYPES_DEFINED__
121 typedef __int8 int8_t;
122 typedef __int16 int16_t;
123 typedef __int32 int32_t;
124 typedef __int64 int64_t;
125 typedef unsigned __int8 uint8_t;
126 typedef unsigned __int16 uint16_t;
127 typedef unsigned __int32 uint32_t;
128 typedef unsigned __int64 uint64_t;
129 typedef uint8_t u_int8_t;
130 typedef uint16_t u_int16_t;
131 typedef uint32_t u_int32_t;
132 typedef uint64_t u_int64_t;
134 #endif /* __BIT_TYPES_DEFINED__ */
136 #define UNREACHABLE(x) x
137 #define UNUSED_ARGUMENT(x) ((void) x)
139 #define RETSIGTYPE void
141 #define VOID_RETSIGTYPE 1
143 #ifdef VOID_RETSIGTYPE
144 #define SIGRETURN(x) return
146 #define SIGRETURN(x) return (RETSIGTYPE)(x)
153 typedef unsigned int gid_t;
155 typedef unsigned int uid_t;
157 typedef unsigned short mode_t;
162 #define inline __inline
167 #define UNREACHABLE(x)
168 #define UNUSED_ARGUMENT(x)
176 #ifdef HAVE_SYS_PARAM_H
177 #include <sys/param.h>
179 #ifdef HAVE_INTTYPES_H
180 #include <inttypes.h>
182 #ifdef HAVE_SYS_TYPES_H
183 #include <sys/types.h>
185 #ifdef HAVE_SYS_BITYPES_H
186 #include <sys/bitypes.h>
188 #ifdef HAVE_BIND_BITYPES_H
189 #include <bind/bitypes.h>
191 #ifdef HAVE_NETINET_IN6_MACHTYPES_H
192 #include <netinet/in6_machtypes.h>
197 #ifdef HAVE_SYS_SOCKET_H
198 #include <sys/socket.h>
200 #ifdef HAVE_SYS_UIO_H
206 #ifdef HAVE_SYS_STAT_H
207 #include <sys/stat.h>
209 #ifdef HAVE_NETINET_IN_H
210 #include <netinet/in.h>
212 #ifdef HAVE_NETINET_IN6_H
213 #include <netinet/in6.h>
215 #ifdef HAVE_NETINET6_IN6_H
216 #include <netinet6/in6.h>
218 #ifdef HAVE_ARPA_INET_H
219 #include <arpa/inet.h>
224 #ifdef HAVE_ARPA_NAMESER_H
225 #include <arpa/nameser.h>
240 #ifdef HAVE_TERMIOS_H
243 #ifdef HAVE_SYS_IOCTL_H
244 #include <sys/ioctl.h>
246 #ifdef TIME_WITH_SYS_TIME
247 #include <sys/time.h>
249 #elif defined(HAVE_SYS_TIME_H)
250 #include <sys/time.h>
267 #ifdef BACKSLASH_PATH_DELIM
268 #define rk_PATH_DELIM '\\'
272 #ifndef SSIZE_T_DEFINED
277 typedef __int64 ssize_t;
281 #define SSIZE_T_DEFINED
282 #endif /* SSIZE_T_DEFINED */
283 #endif /* HAVE_SSIZE_T */
285 #include <roken-common.h>
289 #ifdef HAVE_UINTPTR_T
290 #define rk_UNCONST(x) ((void *)(uintptr_t)(const void *)(x))
292 #define rk_UNCONST(x) ((void *)(unsigned long)(const void *)(x))
295 #if !defined(HAVE_SETSID) && defined(HAVE__SETSID)
296 #define setsid _setsid
300 /* Additional macros for Visual C/C++ runtime */
304 #define getpid _getpid
310 #define fsync _commit
312 /* The MSVC implementation of snprintf is not C99 compliant. */
313 #define snprintf rk_snprintf
314 #define vsnprintf rk_vsnprintf
315 #define vasnprintf rk_vasnprintf
316 #define vasprintf rk_vasprintf
317 #define asnprintf rk_asnprintf
318 #define asprintf rk_asprintf
320 #define _PIPE_BUFFER_SZ 8192
321 #define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY);
323 #define ftruncate(fd, sz) _chsize((fd), (sz))
325 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
326 rk_snprintf (char *str, size_t sz, const char *format, ...);
328 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
329 rk_asprintf (char **ret, const char *format, ...);
331 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
332 rk_asnprintf (char **ret, size_t max_sz, const char *format, ...);
334 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
335 rk_vasprintf (char **ret, const char *format, va_list args);
337 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
338 rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args);
340 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
341 rk_vsnprintf (char *str, size_t sz, const char *format, va_list args);
343 /* missing stat.h predicates */
345 #define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG)
347 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
349 #define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR)
351 #define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO)
353 /* The following are not implemented:
360 /* The following symbolic constants are provided for rk_mkdir mode */
362 #define S_IRWXU 00700 /* user (file owner) has read, write and execute permission */
363 #define S_IRUSR 00400 /* user has read permission */
364 #define S_IWUSR 00200 /* user has write permission */
365 #define S_IXUSR 00100 /* user has execute permission */
366 #define S_IRWXG 00070 /* group has read, write and execute permission */
367 #define S_IRGRP 00040 /* group has read permission */
368 #define S_IWGRP 00020 /* group has write permission */
369 #define S_IXGRP 00010 /* group has execute permission */
370 #define S_IRWXO 00007 /* others have read, write and execute permission */
371 #define S_IROTH 00004 /* others have read permission */
372 #define S_IWOTH 00002 /* others have write permission */
373 #define S_IXOTH 00001 /* others have execute permission */
375 #if !defined(ROKEN_NO_DEFINE_ALLOCATORS)
376 /* Ensure that a common memory allocator is used by all */
377 #define calloc rk_calloc
379 #define malloc rk_malloc
380 #define realloc rk_realloc
381 #define strdup rk_strdup
382 #define wcsdup rk_wcsdup
385 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
386 rk_calloc(size_t, size_t);
388 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
391 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
394 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
395 rk_realloc(void *, size_t);
397 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
398 rk_strdup(const char *);
400 ROKEN_LIB_FUNCTION unsigned short * ROKEN_LIB_CALL
401 rk_wcsdup(const unsigned short *);
403 #endif /* _MSC_VER */
407 /* While we are at it, define WinSock specific scatter gather socket
410 #define iovec _WSABUF
416 socklen_t msg_namelen;
417 struct iovec *msg_iov;
420 socklen_t msg_controllen;
424 #define sendmsg sendmsg_w32
426 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
427 sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags);
429 #endif /* HAVE_WINSOCK */
432 #define putenv rk_putenv
433 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *);
436 #if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO)
438 #define setenv rk_setenv
440 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int);
443 #if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO)
444 #ifndef HAVE_UNSETENV
445 #define unsetenv rk_unsetenv
447 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *);
450 #if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO)
451 #ifndef HAVE_GETUSERSHELL
452 #define getusershell rk_getusershell
453 #define endusershell rk_endusershell
455 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void);
456 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void);
459 #if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO)
460 #ifndef HAVE_SNPRINTF
461 #define snprintf rk_snprintf
463 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
464 rk_snprintf (char *, size_t, const char *, ...)
465 __attribute__ ((format (printf, 3, 4)));
468 #if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO)
469 #ifndef HAVE_VSNPRINTF
470 #define vsnprintf rk_vsnprintf
472 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
473 rk_vsnprintf (char *, size_t, const char *, va_list)
474 __attribute__((format (printf, 3, 0)));
477 #if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO)
478 #ifndef HAVE_ASPRINTF
479 #define asprintf rk_asprintf
481 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
482 rk_asprintf (char **, const char *, ...)
483 __attribute__ ((format (printf, 2, 3)));
486 #if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO)
487 #ifndef HAVE_VASPRINTF
488 #define vasprintf rk_vasprintf
490 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
491 rk_vasprintf (char **, const char *, va_list)
492 __attribute__((format (printf, 2, 0)));
495 #if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO)
496 #ifndef HAVE_ASNPRINTF
497 #define asnprintf rk_asnprintf
499 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
500 rk_asnprintf (char **, size_t, const char *, ...)
501 __attribute__ ((format (printf, 3, 4)));
504 #if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO)
505 #ifndef HAVE_VASNPRINTF
506 #define vasnprintf rk_vasnprintf
508 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
509 vasnprintf (char **, size_t, const char *, va_list)
510 __attribute__((format (printf, 3, 0)));
514 #define strdup rk_strdup
515 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *);
518 #if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO)
520 #define strndup rk_strndup
522 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t);
526 #define strlwr rk_strlwr
527 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *);
531 #define strnlen rk_strnlen
532 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t);
535 #if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO)
537 #define strsep rk_strsep
539 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*);
542 #if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO)
543 #ifndef HAVE_STRSEP_COPY
544 #define strsep_copy rk_strsep_copy
546 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t);
549 #ifndef HAVE_STRCASECMP
550 #define strcasecmp rk_strcasecmp
551 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *);
554 #ifdef NEED_FCLOSE_PROTO
555 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *);
558 #ifdef NEED_STRTOK_R_PROTO
559 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **);
563 #define strupr rk_strupr
564 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *);
568 #define strlcpy rk_strlcpy
569 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t);
573 #define strlcat rk_strlcat
574 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t);
577 #ifndef HAVE_GETDTABLESIZE
578 #define getdtablesize rk_getdtablesize
579 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void);
582 #if !defined(HAVE_STRERROR) && !defined(strerror)
583 #define strerror rk_strerror
584 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int);
587 #if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R))
588 int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t);
590 #define rk_strerror_r strerror_r
593 #if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO)
594 #ifndef HAVE_HSTRERROR
595 #define hstrerror rk_hstrerror
597 /* This causes a fatal error under Psoriasis */
599 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int);
603 #if !HAVE_DECL_H_ERRNO
607 #if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO)
608 #ifndef HAVE_INET_ATON
609 #define inet_aton rk_inet_aton
611 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *);
614 #ifndef HAVE_INET_NTOP
615 #define inet_ntop rk_inet_ntop
616 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
617 inet_ntop(int af, const void *src, char *dst, size_t size);
620 #ifndef HAVE_INET_PTON
621 #define inet_pton rk_inet_pton
622 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
623 inet_pton(int, const char *, void *);
627 #define getcwd rk_getcwd
628 ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t);
633 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *);
634 ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t);
637 #ifdef POSIX_GETPWNAM_R
638 #define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd)
640 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
641 rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
644 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void);
647 #define seteuid rk_seteuid
648 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t);
652 #define setegid rk_setegid
653 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t);
657 #define lstat rk_lstat
658 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *);
661 #if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO)
663 #define mkstemp rk_mkstemp
665 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *);
669 #define cgetent rk_cgetent
670 #define cgetstr rk_cgetstr
671 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *);
672 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **);
675 #ifndef HAVE_INITGROUPS
676 #define initgroups rk_initgroups
677 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t);
681 #define fchown rk_fchown
682 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t);
685 #ifdef RENAME_DOES_NOT_UNLINK
686 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *);
688 #define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to)
691 #if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO)
693 #define daemon rk_daemon
695 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int);
699 #define chown rk_chown
700 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t);
705 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
706 rcmd(char **, unsigned short, const char *,
707 const char *, const char *, int *);
710 #if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO)
712 #define innetgr rk_innetgr
714 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*,
715 const char*, const char*);
718 #ifndef HAVE_IRUSEROK
719 #define iruserok rk_iruserok
720 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int,
721 const char *, const char *);
724 #if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO)
725 #ifndef HAVE_GETHOSTNAME
726 #define gethostname rk_gethostname
728 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int);
732 #define writev rk_writev
733 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
734 writev(int, const struct iovec *, int);
738 #define readv rk_readv
739 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
740 readv(int, const struct iovec *, int);
745 #define pidfile(x) ((void) 0)
747 #define pidfile rk_pidfile
748 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
753 #define bswap32 rk_bswap32
754 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int);
758 #define bswap16 rk_bswap16
759 ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short);
764 #define LOCK_SH 1 /* Shared lock */
767 #define LOCK_EX 2 /* Exclusive lock */
770 #define LOCK_NB 4 /* Don't block when locking */
773 #define LOCK_UN 8 /* Unlock */
776 #define flock(_x,_y) rk_flock(_x,_y)
777 int rk_flock(int fd, int operation);
778 #endif /* HAVE_FLOCK */
781 #ifdef HAVE_DIR_DD_FD
782 #define dirfd(x) ((x)->dd_fd)
784 #ifndef _WIN32 /* Windows code never calls dirfd */
785 #error Missing dirfd() and ->dd_fd
790 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int);
792 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *);
794 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...);
796 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...);
798 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
800 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
801 roken_vmconcat (char **, size_t, va_list);
803 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
804 net_write (rk_socket_t, const void *, size_t);
806 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
807 net_read (rk_socket_t, void *, size_t);
809 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
812 #ifndef HAVE_STRUCT_WINSIZE
814 unsigned short ws_row, ws_col;
815 unsigned short ws_xpixel, ws_ypixel;
819 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *);
822 #define vsyslog rk_vsyslog
823 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list);
827 #define getopt rk_getopt
828 #define optarg rk_optarg
829 #define optind rk_optind
830 #define opterr rk_opterr
831 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
832 getopt(int nargc, char * const *nargv, const char *ostr);
835 #if !HAVE_DECL_OPTARG
836 ROKEN_LIB_VARIABLE extern char *optarg;
838 #if !HAVE_DECL_OPTIND
839 ROKEN_LIB_VARIABLE extern int optind;
841 #if !HAVE_DECL_OPTERR
842 ROKEN_LIB_VARIABLE extern int opterr;
845 #ifndef HAVE_GETIPNODEBYNAME
846 #define getipnodebyname rk_getipnodebyname
847 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
848 getipnodebyname (const char *, int, int, int *);
851 #ifndef HAVE_GETIPNODEBYADDR
852 #define getipnodebyaddr rk_getipnodebyaddr
853 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
854 getipnodebyaddr (const void *, size_t, int, int *);
857 #ifndef HAVE_FREEHOSTENT
858 #define freehostent rk_freehostent
859 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
860 freehostent (struct hostent *);
863 #ifndef HAVE_COPYHOSTENT
864 #define copyhostent rk_copyhostent
865 ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
866 copyhostent (const struct hostent *);
869 #ifndef HAVE_SOCKLEN_T
870 typedef int socklen_t;
873 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE
875 #ifndef HAVE_SA_FAMILY_T
876 typedef unsigned short sa_family_t;
880 #define _SS_MAXSIZE sizeof(struct sockaddr_in6)
882 #define _SS_MAXSIZE sizeof(struct sockaddr_in)
885 #define _SS_ALIGNSIZE sizeof(unsigned long)
887 #if HAVE_STRUCT_SOCKADDR_SA_LEN
889 typedef unsigned char roken_sa_family_t;
891 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE)
892 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
894 struct sockaddr_storage {
895 unsigned char ss_len;
896 roken_sa_family_t ss_family;
897 char __ss_pad1[_SS_PAD1SIZE];
898 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
901 #else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */
903 typedef unsigned short roken_sa_family_t;
905 #define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE)
906 #define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE))
908 struct sockaddr_storage {
909 roken_sa_family_t ss_family;
910 char __ss_pad1[_SS_PAD1SIZE];
911 unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1];
914 #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
916 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
918 #ifndef HAVE_STRUCT_ADDRINFO
926 struct sockaddr *ai_addr;
927 struct addrinfo *ai_next;
931 #ifndef HAVE_GETADDRINFO
932 #define getaddrinfo rk_getaddrinfo
933 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
934 getaddrinfo(const char *,
936 const struct addrinfo *,
940 #ifndef HAVE_GETNAMEINFO
941 #define getnameinfo rk_getnameinfo
942 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
943 getnameinfo(const struct sockaddr *, socklen_t,
949 #ifndef HAVE_FREEADDRINFO
950 #define freeaddrinfo rk_freeaddrinfo
951 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
952 freeaddrinfo(struct addrinfo *);
955 #ifndef HAVE_GAI_STRERROR
956 #define gai_strerror rk_gai_strerror
957 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
963 ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
964 sleep(unsigned int seconds);
968 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
969 getnameinfo_verified(const struct sockaddr *, socklen_t,
974 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
975 roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **);
976 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
977 roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **);
979 #ifndef HAVE_STRFTIME
980 #define strftime rk_strftime
981 ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
982 strftime (char *, size_t, const char *, const struct tm *);
985 #ifndef HAVE_STRPTIME
986 #define strptime rk_strptime
987 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
988 strptime (const char *, const char *, struct tm *);
991 #ifndef HAVE_GETTIMEOFDAY
992 #define gettimeofday rk_gettimeofday
993 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
994 gettimeofday (struct timeval *, void *);
998 #define emalloc rk_emalloc
999 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t);
1001 #ifndef HAVE_ECALLOC
1002 #define ecalloc rk_ecalloc
1003 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t);
1005 #ifndef HAVE_EREALLOC
1006 #define erealloc rk_erealloc
1007 ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t);
1009 #ifndef HAVE_ESTRDUP
1010 #define estrdup rk_estrdup
1011 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *);
1018 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1019 roken_gethostby_setup(const char*, const char*);
1020 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
1021 roken_gethostbyname(const char*);
1022 ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL
1023 roken_gethostbyaddr(const void*, size_t, int);
1025 #ifdef GETSERVBYNAME_PROTO_COMPATIBLE
1026 #define roken_getservbyname(x,y) getservbyname(x,y)
1028 #define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y)
1031 #ifdef OPENLOG_PROTO_COMPATIBLE
1032 #define roken_openlog(a,b,c) openlog(a,b,c)
1034 #define roken_openlog(a,b,c) openlog((char *)a,b,c)
1037 #ifdef GETSOCKNAME_PROTO_COMPATIBLE
1038 #define roken_getsockname(a,b,c) getsockname(a,b,c)
1040 #define roken_getsockname(a,b,c) getsockname(a, b, (void*)c)
1043 #ifndef HAVE_SETPROGNAME
1044 #define setprogname rk_setprogname
1045 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *);
1048 #ifndef HAVE_GETPROGNAME
1049 #define getprogname rk_getprogname
1050 ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void);
1053 #if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME
1054 extern const char *__progname;
1057 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1058 mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *);
1060 ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
1061 mini_inetd (int, rk_socket_t *);
1063 #ifndef HAVE_LOCALTIME_R
1064 #define localtime_r rk_localtime_r
1065 ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
1066 localtime_r(const time_t *, struct tm *);
1069 #if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO)
1070 #ifndef HAVE_STRTOLL
1071 #define strtoll rk_strtoll
1073 ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL
1074 strtoll(const char * nptr, char ** endptr, int base);
1077 #if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO)
1078 #ifndef HAVE_STRTOULL
1079 #define strtoull rk_strtoull
1081 ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL
1082 strtoull(const char * nptr, char ** endptr, int base);
1085 #if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO)
1086 #ifndef HAVE_STRSVIS
1087 #define strsvis rk_strsvis
1089 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1090 strsvis(char *, const char *, int, const char *);
1093 #if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO)
1094 #ifndef HAVE_STRSVISX
1095 #define strsvisx rk_strsvisx
1097 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1098 strsvisx(char *, const char *, size_t, int, const char *);
1101 #if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO)
1102 #ifndef HAVE_STRUNVIS
1103 #define strunvis rk_strunvis
1105 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1106 strunvis(char *, const char *);
1109 #if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO)
1111 #define strvis rk_strvis
1113 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1114 strvis(char *, const char *, int);
1117 #if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO)
1118 #ifndef HAVE_STRVISX
1119 #define strvisx rk_strvisx
1121 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1122 strvisx(char *, const char *, size_t, int);
1125 #if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO)
1127 #define svis rk_svis
1129 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1130 svis(char *, int, int, int, const char *);
1133 #if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO)
1135 #define unvis rk_unvis
1137 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1138 unvis(char *, int, int *, int);
1141 #if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO)
1145 ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
1146 vis(char *, int, int, int);
1149 #if !defined(HAVE_CLOSEFROM)
1150 #define closefrom rk_closefrom
1151 ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
1155 #if !defined(HAVE_TIMEGM)
1156 #define timegm rk_timegm
1157 ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL
1158 rk_timegm(struct tm *tm);
1162 #define qsort rk_qsort
1164 rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *));
1167 #if defined(HAVE_ARC4RANDOM)
1168 #define rk_random() arc4random()
1169 #elif defined(HAVE_RANDOM)
1170 #define rk_random() random()
1172 #define rk_random() rand()
1175 #ifndef HAVE_TDELETE
1176 #define tdelete(a,b,c) rk_tdelete(a,b,c)
1179 #define tfind(a,b,c) rk_tfind(a,b,c)
1181 #ifndef HAVE_TSEARCH
1182 #define tsearch(a,b,c) rk_tsearch(a,b,c)
1185 #define twalk(a,b) rk_twalk(a,b)
1188 #if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__)
1190 #define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot)
1191 int ROKEN_LIB_FUNCTION rk_socket(int, int, int);
1194 /* Microsoft VC 2010 POSIX definitions */
1195 #ifndef EAFNOSUPPORT
1196 #define EAFNOSUPPORT 102
1199 #define EINPROGRESS 112
1202 #define ENOTSOCK 128
1208 #define EOVERFLOW 132
1211 #define ETIMEDOUT 138
1214 #define EWOULDBLOCK 140
1218 #ifdef SOCKET_WRAPPER_REPLACE
1219 #include <socket_wrapper.h>