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