| 1 |
/* -*- C -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 1995-2005 Kungliga Tekniska Högskolan |
| 4 |
* (Royal Institute of Technology, Stockholm, Sweden). |
| 5 |
* All rights reserved. |
| 6 |
* |
| 7 |
* Redistribution and use in source and binary forms, with or without |
| 8 |
* modification, are permitted provided that the following conditions |
| 9 |
* are met: |
| 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 |
#define timezone _timezone |
| 322 |
|
| 323 |
#define tzname _tzname |
| 324 |
|
| 325 |
#define _PIPE_BUFFER_SZ 8192 |
| 326 |
#define pipe(fds) _pipe((fds), _PIPE_BUFFER_SZ, O_BINARY); |
| 327 |
|
| 328 |
#define ftruncate(fd, sz) _chsize((fd), (sz)) |
| 329 |
|
| 330 |
#if !defined(HAVE_UCRT) |
| 331 |
#define snprintf rk_snprintf |
| 332 |
#define vsnprintf rk_vsnprintf |
| 333 |
#define vasnprintf rk_vasnprintf |
| 334 |
#define vasprintf rk_vasprintf |
| 335 |
#define asnprintf rk_asnprintf |
| 336 |
#define asprintf rk_asprintf |
| 337 |
|
| 338 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 339 |
rk_snprintf (char *str, size_t sz, const char *format, ...); |
| 340 |
|
| 341 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 342 |
rk_asprintf (char **ret, const char *format, ...); |
| 343 |
|
| 344 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 345 |
rk_asnprintf (char **ret, size_t max_sz, const char *format, ...); |
| 346 |
|
| 347 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 348 |
rk_vasprintf (char **ret, const char *format, va_list args); |
| 349 |
|
| 350 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 351 |
rk_vasnprintf (char **ret, size_t max_sz, const char *format, va_list args); |
| 352 |
|
| 353 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 354 |
rk_vsnprintf (char *str, size_t sz, const char *format, va_list args); |
| 355 |
#endif /* !defined(HAVE_UCRT) */ |
| 356 |
|
| 357 |
/* missing stat.h predicates */ |
| 358 |
|
| 359 |
#define S_ISREG(m) (((m) & _S_IFREG) == _S_IFREG) |
| 360 |
|
| 361 |
#define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR) |
| 362 |
|
| 363 |
#define S_ISCHR(m) (((m) & _S_IFCHR) == _S_IFCHR) |
| 364 |
|
| 365 |
#define S_ISFIFO(m) (((m) & _S_IFIFO) == _S_IFIFO) |
| 366 |
|
| 367 |
/* The following are not implemented: |
| 368 |
|
| 369 |
S_ISLNK(m) |
| 370 |
S_ISSOCK(m) |
| 371 |
S_ISBLK(m) |
| 372 |
*/ |
| 373 |
|
| 374 |
/* The following symbolic constants are provided for rk_mkdir mode */ |
| 375 |
|
| 376 |
#define S_IRWXU 00700 /* user (file owner) has read, write and execute permission */ |
| 377 |
#define S_IRUSR 00400 /* user has read permission */ |
| 378 |
#define S_IWUSR 00200 /* user has write permission */ |
| 379 |
#define S_IXUSR 00100 /* user has execute permission */ |
| 380 |
#define S_IRWXG 00070 /* group has read, write and execute permission */ |
| 381 |
#define S_IRGRP 00040 /* group has read permission */ |
| 382 |
#define S_IWGRP 00020 /* group has write permission */ |
| 383 |
#define S_IXGRP 00010 /* group has execute permission */ |
| 384 |
#define S_IRWXO 00007 /* others have read, write and execute permission */ |
| 385 |
#define S_IROTH 00004 /* others have read permission */ |
| 386 |
#define S_IWOTH 00002 /* others have write permission */ |
| 387 |
#define S_IXOTH 00001 /* others have execute permission */ |
| 388 |
|
| 389 |
#if !defined(ROKEN_NO_DEFINE_ALLOCATORS) |
| 390 |
/* Ensure that a common memory allocator is used by all */ |
| 391 |
#define calloc rk_calloc |
| 392 |
#define free rk_free |
| 393 |
#define malloc rk_malloc |
| 394 |
#define realloc rk_realloc |
| 395 |
#define strdup rk_strdup |
| 396 |
#define wcsdup rk_wcsdup |
| 397 |
#endif |
| 398 |
|
| 399 |
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL |
| 400 |
rk_calloc(size_t, size_t); |
| 401 |
|
| 402 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL |
| 403 |
rk_free(void *); |
| 404 |
|
| 405 |
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL |
| 406 |
rk_malloc(size_t); |
| 407 |
|
| 408 |
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL |
| 409 |
rk_realloc(void *, size_t); |
| 410 |
|
| 411 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL |
| 412 |
rk_strdup(const char *); |
| 413 |
|
| 414 |
ROKEN_LIB_FUNCTION unsigned short * ROKEN_LIB_CALL |
| 415 |
rk_wcsdup(const unsigned short *); |
| 416 |
|
| 417 |
#endif /* _MSC_VER */ |
| 418 |
|
| 419 |
#ifdef HAVE_WINSOCK |
| 420 |
|
| 421 |
/* While we are at it, define WinSock specific scatter gather socket |
| 422 |
I/O. */ |
| 423 |
|
| 424 |
#define iovec _WSABUF |
| 425 |
#define iov_base buf |
| 426 |
#define iov_len len |
| 427 |
|
| 428 |
struct msghdr { |
| 429 |
void *msg_name; |
| 430 |
socklen_t msg_namelen; |
| 431 |
struct iovec *msg_iov; |
| 432 |
size_t msg_iovlen; |
| 433 |
void *msg_control; |
| 434 |
socklen_t msg_controllen; |
| 435 |
int msg_flags; |
| 436 |
}; |
| 437 |
|
| 438 |
#define sendmsg sendmsg_w32 |
| 439 |
|
| 440 |
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL |
| 441 |
sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags); |
| 442 |
|
| 443 |
#endif /* HAVE_WINSOCK */ |
| 444 |
|
| 445 |
#ifndef HAVE_PUTENV |
| 446 |
#define putenv rk_putenv |
| 447 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL putenv(const char *); |
| 448 |
#endif |
| 449 |
|
| 450 |
#if !defined(HAVE_SETENV) || defined(NEED_SETENV_PROTO) |
| 451 |
#ifndef HAVE_SETENV |
| 452 |
#define setenv rk_setenv |
| 453 |
#endif |
| 454 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setenv(const char *, const char *, int); |
| 455 |
#endif |
| 456 |
|
| 457 |
#if !defined(HAVE_UNSETENV) || defined(NEED_UNSETENV_PROTO) |
| 458 |
#ifndef HAVE_UNSETENV |
| 459 |
#define unsetenv rk_unsetenv |
| 460 |
#endif |
| 461 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL unsetenv(const char *); |
| 462 |
#endif |
| 463 |
|
| 464 |
#if !defined(HAVE_GETUSERSHELL) || defined(NEED_GETUSERSHELL_PROTO) |
| 465 |
#ifndef HAVE_GETUSERSHELL |
| 466 |
#define getusershell rk_getusershell |
| 467 |
#define endusershell rk_endusershell |
| 468 |
#endif |
| 469 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL getusershell(void); |
| 470 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL endusershell(void); |
| 471 |
#endif |
| 472 |
|
| 473 |
#if !defined(HAVE_SNPRINTF) || defined(NEED_SNPRINTF_PROTO) |
| 474 |
#ifndef HAVE_SNPRINTF |
| 475 |
#define snprintf rk_snprintf |
| 476 |
#endif |
| 477 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 478 |
rk_snprintf (char *, size_t, const char *, ...) |
| 479 |
__attribute__ ((__format__ (__printf__, 3, 4))); |
| 480 |
#endif |
| 481 |
|
| 482 |
#if !defined(HAVE_VSNPRINTF) || defined(NEED_VSNPRINTF_PROTO) |
| 483 |
#ifndef HAVE_VSNPRINTF |
| 484 |
#define vsnprintf rk_vsnprintf |
| 485 |
#endif |
| 486 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 487 |
rk_vsnprintf (char *, size_t, const char *, va_list) |
| 488 |
__attribute__ ((__format__ (__printf__, 3, 0))); |
| 489 |
#endif |
| 490 |
|
| 491 |
#if !defined(HAVE_ASPRINTF) || defined(NEED_ASPRINTF_PROTO) |
| 492 |
#ifndef HAVE_ASPRINTF |
| 493 |
#define asprintf rk_asprintf |
| 494 |
#endif |
| 495 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 496 |
rk_asprintf (char **, const char *, ...) |
| 497 |
__attribute__ ((__format__ (__printf__, 2, 3))); |
| 498 |
#endif |
| 499 |
|
| 500 |
#if !defined(HAVE_VASPRINTF) || defined(NEED_VASPRINTF_PROTO) |
| 501 |
#ifndef HAVE_VASPRINTF |
| 502 |
#define vasprintf rk_vasprintf |
| 503 |
#endif |
| 504 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 505 |
rk_vasprintf (char **, const char *, va_list) |
| 506 |
__attribute__ ((__format__ (__printf__, 2, 0))); |
| 507 |
#endif |
| 508 |
|
| 509 |
#if !defined(HAVE_ASNPRINTF) || defined(NEED_ASNPRINTF_PROTO) |
| 510 |
#ifndef HAVE_ASNPRINTF |
| 511 |
#define asnprintf rk_asnprintf |
| 512 |
#endif |
| 513 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 514 |
rk_asnprintf (char **, size_t, const char *, ...) |
| 515 |
__attribute__ ((__format__ (__printf__, 3, 4))); |
| 516 |
#endif |
| 517 |
|
| 518 |
#if !defined(HAVE_VASNPRINTF) || defined(NEED_VASNPRINTF_PROTO) |
| 519 |
#ifndef HAVE_VASNPRINTF |
| 520 |
#define vasnprintf rk_vasnprintf |
| 521 |
#endif |
| 522 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 523 |
vasnprintf (char **, size_t, const char *, va_list) |
| 524 |
__attribute__ ((__format__ (__printf__, 3, 0))); |
| 525 |
#endif |
| 526 |
|
| 527 |
#ifndef HAVE_STRDUP |
| 528 |
#define strdup rk_strdup |
| 529 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strdup(const char *); |
| 530 |
#endif |
| 531 |
|
| 532 |
#if !defined(HAVE_STRNDUP) || defined(NEED_STRNDUP_PROTO) |
| 533 |
#ifndef HAVE_STRNDUP |
| 534 |
#define strndup rk_strndup |
| 535 |
#endif |
| 536 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strndup(const char *, size_t); |
| 537 |
#endif |
| 538 |
|
| 539 |
#ifndef HAVE_STRLWR |
| 540 |
#define strlwr rk_strlwr |
| 541 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strlwr(char *); |
| 542 |
#endif |
| 543 |
|
| 544 |
#ifndef HAVE_STRNLEN |
| 545 |
#define strnlen rk_strnlen |
| 546 |
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strnlen(const char*, size_t); |
| 547 |
#endif |
| 548 |
|
| 549 |
#if !defined(HAVE_STRSEP) || defined(NEED_STRSEP_PROTO) |
| 550 |
#ifndef HAVE_STRSEP |
| 551 |
#define strsep rk_strsep |
| 552 |
#endif |
| 553 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strsep(char**, const char*); |
| 554 |
#endif |
| 555 |
|
| 556 |
#if !defined(HAVE_STRSEP_COPY) || defined(NEED_STRSEP_COPY_PROTO) |
| 557 |
#ifndef HAVE_STRSEP_COPY |
| 558 |
#define strsep_copy rk_strsep_copy |
| 559 |
#endif |
| 560 |
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL strsep_copy(const char**, const char*, char*, size_t); |
| 561 |
#endif |
| 562 |
|
| 563 |
#ifndef HAVE_STRCASECMP |
| 564 |
#define strcasecmp rk_strcasecmp |
| 565 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL strcasecmp(const char *, const char *); |
| 566 |
#endif |
| 567 |
|
| 568 |
#ifdef NEED_FCLOSE_PROTO |
| 569 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fclose(FILE *); |
| 570 |
#endif |
| 571 |
|
| 572 |
#ifdef NEED_STRTOK_R_PROTO |
| 573 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strtok_r(char *, const char *, char **); |
| 574 |
#endif |
| 575 |
|
| 576 |
#ifndef HAVE_STRUPR |
| 577 |
#define strupr rk_strupr |
| 578 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strupr(char *); |
| 579 |
#endif |
| 580 |
|
| 581 |
#ifndef HAVE_STRLCPY |
| 582 |
#define strlcpy rk_strlcpy |
| 583 |
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcpy (char *, const char *, size_t); |
| 584 |
#endif |
| 585 |
|
| 586 |
#ifndef HAVE_STRLCAT |
| 587 |
#define strlcat rk_strlcat |
| 588 |
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL strlcat (char *, const char *, size_t); |
| 589 |
#endif |
| 590 |
|
| 591 |
#ifndef HAVE_GETDTABLESIZE |
| 592 |
#define getdtablesize rk_getdtablesize |
| 593 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL getdtablesize(void); |
| 594 |
#endif |
| 595 |
|
| 596 |
#if !defined(HAVE_STRERROR) && !defined(strerror) |
| 597 |
#define strerror rk_strerror |
| 598 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL strerror(int); |
| 599 |
#endif |
| 600 |
|
| 601 |
#if (!defined(HAVE_STRERROR_R) && !defined(strerror_r)) || (!defined(STRERROR_R_PROTO_COMPATIBLE) && defined(HAVE_STRERROR_R)) |
| 602 |
int ROKEN_LIB_FUNCTION rk_strerror_r(int, char *, size_t); |
| 603 |
#else |
| 604 |
#define rk_strerror_r strerror_r |
| 605 |
#endif |
| 606 |
|
| 607 |
#if !defined(HAVE_HSTRERROR) || defined(NEED_HSTRERROR_PROTO) |
| 608 |
#ifndef HAVE_HSTRERROR |
| 609 |
#define hstrerror rk_hstrerror |
| 610 |
#endif |
| 611 |
/* This causes a fatal error under Psoriasis */ |
| 612 |
#ifndef SunOS |
| 613 |
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL hstrerror(int); |
| 614 |
#endif |
| 615 |
#endif |
| 616 |
|
| 617 |
#if !HAVE_DECL_H_ERRNO |
| 618 |
extern int h_errno; |
| 619 |
#endif |
| 620 |
|
| 621 |
#if !defined(HAVE_INET_ATON) || defined(NEED_INET_ATON_PROTO) |
| 622 |
#ifndef HAVE_INET_ATON |
| 623 |
#define inet_aton rk_inet_aton |
| 624 |
#endif |
| 625 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL inet_aton(const char *, struct in_addr *); |
| 626 |
#endif |
| 627 |
|
| 628 |
#ifndef HAVE_INET_NTOP |
| 629 |
#define inet_ntop rk_inet_ntop |
| 630 |
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL |
| 631 |
inet_ntop(int af, const void *src, char *dst, size_t size); |
| 632 |
#endif |
| 633 |
|
| 634 |
#ifndef HAVE_INET_PTON |
| 635 |
#define inet_pton rk_inet_pton |
| 636 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 637 |
inet_pton(int, const char *, void *); |
| 638 |
#endif |
| 639 |
|
| 640 |
#ifndef HAVE_GETCWD |
| 641 |
#define getcwd rk_getcwd |
| 642 |
ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL getcwd(char *, size_t); |
| 643 |
#endif |
| 644 |
|
| 645 |
#ifdef HAVE_PWD_H |
| 646 |
#include <pwd.h> |
| 647 |
ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwnam (const char *); |
| 648 |
ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL k_getpwuid (uid_t); |
| 649 |
#endif |
| 650 |
|
| 651 |
#ifdef POSIX_GETPWNAM_R |
| 652 |
#define rk_getpwnam_r(_n, _pw, _b, _sz, _pwd) getpwnam_r(_n, _pw, _b, _sz, _pwd) |
| 653 |
#else |
| 654 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 655 |
rk_getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); |
| 656 |
#endif |
| 657 |
|
| 658 |
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL get_default_username (void); |
| 659 |
|
| 660 |
#ifndef HAVE_SETEUID |
| 661 |
#define seteuid rk_seteuid |
| 662 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL seteuid(uid_t); |
| 663 |
#endif |
| 664 |
|
| 665 |
#ifndef HAVE_SETEGID |
| 666 |
#define setegid rk_setegid |
| 667 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL setegid(gid_t); |
| 668 |
#endif |
| 669 |
|
| 670 |
#ifndef HAVE_LSTAT |
| 671 |
#define lstat rk_lstat |
| 672 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL lstat(const char *, struct stat *); |
| 673 |
#endif |
| 674 |
|
| 675 |
#if !defined(HAVE_MKSTEMP) || defined(NEED_MKSTEMP_PROTO) |
| 676 |
#ifndef HAVE_MKSTEMP |
| 677 |
#define mkstemp rk_mkstemp |
| 678 |
#endif |
| 679 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL mkstemp(char *); |
| 680 |
#endif |
| 681 |
|
| 682 |
#ifndef HAVE_CGETENT |
| 683 |
#define cgetent rk_cgetent |
| 684 |
#define cgetstr rk_cgetstr |
| 685 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **, char **, const char *); |
| 686 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *, const char *, char **); |
| 687 |
#endif |
| 688 |
|
| 689 |
#ifndef HAVE_INITGROUPS |
| 690 |
#define initgroups rk_initgroups |
| 691 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL initgroups(const char *, gid_t); |
| 692 |
#endif |
| 693 |
|
| 694 |
#ifndef HAVE_FCHOWN |
| 695 |
#define fchown rk_fchown |
| 696 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL fchown(int, uid_t, gid_t); |
| 697 |
#endif |
| 698 |
|
| 699 |
#ifdef RENAME_DOES_NOT_UNLINK |
| 700 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_rename(const char *, const char *); |
| 701 |
#else |
| 702 |
#define rk_rename(__rk_rn_from,__rk_rn_to) rename(__rk_rn_from,__rk_rn_to) |
| 703 |
#endif |
| 704 |
|
| 705 |
#ifdef MKDIR_DOES_NOT_HAVE_MODE |
| 706 |
#define mkdir rk_mkdir |
| 707 |
#else |
| 708 |
#define rk_mkdir(__rk_rn_name, __rk_rn_mode) mkdir(__rk_rn_name,__rk_rn_mode) |
| 709 |
#endif |
| 710 |
|
| 711 |
|
| 712 |
#if !defined(HAVE_DAEMON) || defined(NEED_DAEMON_PROTO) |
| 713 |
#ifndef HAVE_DAEMON |
| 714 |
#define daemon rk_daemon |
| 715 |
#endif |
| 716 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL daemon(int, int); |
| 717 |
#endif |
| 718 |
|
| 719 |
#ifndef HAVE_CHOWN |
| 720 |
#define chown rk_chown |
| 721 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL chown(const char *, uid_t, gid_t); |
| 722 |
#endif |
| 723 |
|
| 724 |
#ifndef HAVE_RCMD |
| 725 |
#define rcmd rk_rcmd |
| 726 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 727 |
rcmd(char **, unsigned short, const char *, |
| 728 |
const char *, const char *, int *); |
| 729 |
#endif |
| 730 |
|
| 731 |
#if !defined(HAVE_INNETGR) || defined(NEED_INNETGR_PROTO) |
| 732 |
#ifndef HAVE_INNETGR |
| 733 |
#define innetgr rk_innetgr |
| 734 |
#endif |
| 735 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL innetgr(const char*, const char*, |
| 736 |
const char*, const char*); |
| 737 |
#endif |
| 738 |
|
| 739 |
#ifndef HAVE_IRUSEROK |
| 740 |
#define iruserok rk_iruserok |
| 741 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL iruserok(unsigned, int, |
| 742 |
const char *, const char *); |
| 743 |
#endif |
| 744 |
|
| 745 |
#if !defined(HAVE_GETHOSTNAME) || defined(NEED_GETHOSTNAME_PROTO) |
| 746 |
#ifndef HAVE_GETHOSTNAME |
| 747 |
#define gethostname rk_gethostname |
| 748 |
#endif |
| 749 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL gethostname(char *, int); |
| 750 |
#endif |
| 751 |
|
| 752 |
#ifndef HAVE_WRITEV |
| 753 |
#define writev rk_writev |
| 754 |
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL |
| 755 |
writev(int, const struct iovec *, int); |
| 756 |
#endif |
| 757 |
|
| 758 |
#ifndef HAVE_READV |
| 759 |
#define readv rk_readv |
| 760 |
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL |
| 761 |
readv(int, const struct iovec *, int); |
| 762 |
#endif |
| 763 |
|
| 764 |
#ifdef NO_PIDFILES |
| 765 |
#define rk_pidfile(x) ((void) 0) |
| 766 |
#else |
| 767 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rk_pidfile (const char*); |
| 768 |
#endif |
| 769 |
|
| 770 |
#ifndef HAVE_BSWAP64 |
| 771 |
#define bswap64 rk_bswap64 |
| 772 |
ROKEN_LIB_FUNCTION uint64_t ROKEN_LIB_CALL bswap64(uint64_t); |
| 773 |
#endif |
| 774 |
|
| 775 |
#ifndef HAVE_BSWAP32 |
| 776 |
#define bswap32 rk_bswap32 |
| 777 |
ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL bswap32(unsigned int); |
| 778 |
#endif |
| 779 |
|
| 780 |
#ifndef HAVE_BSWAP16 |
| 781 |
#define bswap16 rk_bswap16 |
| 782 |
ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL bswap16(unsigned short); |
| 783 |
#endif |
| 784 |
|
| 785 |
#ifndef HAVE_FLOCK |
| 786 |
#ifndef LOCK_SH |
| 787 |
#define LOCK_SH 1 /* Shared lock */ |
| 788 |
#endif |
| 789 |
#ifndef LOCK_EX |
| 790 |
#define LOCK_EX 2 /* Exclusive lock */ |
| 791 |
#endif |
| 792 |
#ifndef LOCK_NB |
| 793 |
#define LOCK_NB 4 /* Don't block when locking */ |
| 794 |
#endif |
| 795 |
#ifndef LOCK_UN |
| 796 |
#define LOCK_UN 8 /* Unlock */ |
| 797 |
#endif |
| 798 |
|
| 799 |
#define flock(_x,_y) rk_flock(_x,_y) |
| 800 |
int rk_flock(int fd, int operation); |
| 801 |
#endif /* HAVE_FLOCK */ |
| 802 |
|
| 803 |
#ifndef HAVE_DIRFD |
| 804 |
#ifdef HAVE_DIR_DD_FD |
| 805 |
#define dirfd(x) ((x)->dd_fd) |
| 806 |
#else |
| 807 |
#ifndef _WIN32 /* Windows code never calls dirfd */ |
| 808 |
#error Missing dirfd() and ->dd_fd |
| 809 |
#endif |
| 810 |
#endif |
| 811 |
#endif |
| 812 |
|
| 813 |
ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL tm2time (struct tm, int); |
| 814 |
|
| 815 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unix_verify_user(char *, char *); |
| 816 |
|
| 817 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_concat (char *, size_t, ...); |
| 818 |
|
| 819 |
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL roken_mconcat (char **, size_t, ...); |
| 820 |
|
| 821 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list); |
| 822 |
|
| 823 |
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL |
| 824 |
roken_vmconcat (char **, size_t, va_list); |
| 825 |
|
| 826 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_prep(int, char **, char *); |
| 827 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL roken_detach_finish(const char *, int); |
| 828 |
|
| 829 |
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL |
| 830 |
net_write (rk_socket_t, const void *, size_t); |
| 831 |
|
| 832 |
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL |
| 833 |
net_read (rk_socket_t, void *, size_t); |
| 834 |
|
| 835 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 836 |
issuid(void); |
| 837 |
|
| 838 |
#ifndef HAVE_STRUCT_WINSIZE |
| 839 |
struct winsize { |
| 840 |
unsigned short ws_row, ws_col; |
| 841 |
unsigned short ws_xpixel, ws_ypixel; |
| 842 |
}; |
| 843 |
#endif |
| 844 |
|
| 845 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL get_window_size(int fd, int *, int *); |
| 846 |
|
| 847 |
#ifndef HAVE_VSYSLOG |
| 848 |
#define vsyslog rk_vsyslog |
| 849 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL vsyslog(int, const char *, va_list); |
| 850 |
#endif |
| 851 |
|
| 852 |
#ifndef HAVE_GETOPT |
| 853 |
#define getopt rk_getopt |
| 854 |
#define optarg rk_optarg |
| 855 |
#define optind rk_optind |
| 856 |
#define opterr rk_opterr |
| 857 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 858 |
getopt(int nargc, char * const *nargv, const char *ostr); |
| 859 |
#endif |
| 860 |
|
| 861 |
#if !HAVE_DECL_OPTARG |
| 862 |
ROKEN_LIB_VARIABLE extern char *optarg; |
| 863 |
#endif |
| 864 |
#if !HAVE_DECL_OPTIND |
| 865 |
ROKEN_LIB_VARIABLE extern int optind; |
| 866 |
#endif |
| 867 |
#if !HAVE_DECL_OPTERR |
| 868 |
ROKEN_LIB_VARIABLE extern int opterr; |
| 869 |
#endif |
| 870 |
|
| 871 |
#ifndef HAVE_GETIPNODEBYNAME |
| 872 |
#define getipnodebyname rk_getipnodebyname |
| 873 |
ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL |
| 874 |
getipnodebyname (const char *, int, int, int *); |
| 875 |
#endif |
| 876 |
|
| 877 |
#ifndef HAVE_GETIPNODEBYADDR |
| 878 |
#define getipnodebyaddr rk_getipnodebyaddr |
| 879 |
ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL |
| 880 |
getipnodebyaddr (const void *, size_t, int, int *); |
| 881 |
#endif |
| 882 |
|
| 883 |
#ifndef HAVE_FREEHOSTENT |
| 884 |
#define freehostent rk_freehostent |
| 885 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL |
| 886 |
freehostent (struct hostent *); |
| 887 |
#endif |
| 888 |
|
| 889 |
#ifndef HAVE_COPYHOSTENT |
| 890 |
#define copyhostent rk_copyhostent |
| 891 |
ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL |
| 892 |
copyhostent (const struct hostent *); |
| 893 |
#endif |
| 894 |
|
| 895 |
#ifndef HAVE_SOCKLEN_T |
| 896 |
typedef int socklen_t; |
| 897 |
#endif |
| 898 |
|
| 899 |
#ifndef HAVE_STRUCT_SOCKADDR_STORAGE |
| 900 |
|
| 901 |
#ifndef HAVE_SA_FAMILY_T |
| 902 |
typedef unsigned short sa_family_t; |
| 903 |
#endif |
| 904 |
|
| 905 |
#ifdef HAVE_IPV6 |
| 906 |
#define _SS_MAXSIZE sizeof(struct sockaddr_in6) |
| 907 |
#else |
| 908 |
#define _SS_MAXSIZE sizeof(struct sockaddr_in) |
| 909 |
#endif |
| 910 |
|
| 911 |
#define _SS_ALIGNSIZE sizeof(unsigned long) |
| 912 |
|
| 913 |
#if HAVE_STRUCT_SOCKADDR_SA_LEN |
| 914 |
|
| 915 |
typedef unsigned char roken_sa_family_t; |
| 916 |
|
| 917 |
#define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t) - sizeof(unsigned char)) % _SS_ALIGNSIZE) |
| 918 |
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + sizeof(unsigned char) + _SS_PAD1SIZE + _SS_ALIGNSIZE)) |
| 919 |
|
| 920 |
struct sockaddr_storage { |
| 921 |
unsigned char ss_len; |
| 922 |
roken_sa_family_t ss_family; |
| 923 |
char __ss_pad1[_SS_PAD1SIZE]; |
| 924 |
unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1]; |
| 925 |
}; |
| 926 |
|
| 927 |
#else /* !HAVE_STRUCT_SOCKADDR_SA_LEN */ |
| 928 |
|
| 929 |
typedef unsigned short roken_sa_family_t; |
| 930 |
|
| 931 |
#define _SS_PAD1SIZE ((2 * _SS_ALIGNSIZE - sizeof (roken_sa_family_t)) % _SS_ALIGNSIZE) |
| 932 |
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (roken_sa_family_t) + _SS_PAD1SIZE + _SS_ALIGNSIZE)) |
| 933 |
|
| 934 |
struct sockaddr_storage { |
| 935 |
roken_sa_family_t ss_family; |
| 936 |
char __ss_pad1[_SS_PAD1SIZE]; |
| 937 |
unsigned long __ss_align[_SS_PAD2SIZE / sizeof(unsigned long) + 1]; |
| 938 |
}; |
| 939 |
|
| 940 |
#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ |
| 941 |
|
| 942 |
#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */ |
| 943 |
|
| 944 |
#ifndef HAVE_STRUCT_ADDRINFO |
| 945 |
struct addrinfo { |
| 946 |
int ai_flags; |
| 947 |
int ai_family; |
| 948 |
int ai_socktype; |
| 949 |
int ai_protocol; |
| 950 |
size_t ai_addrlen; |
| 951 |
char *ai_canonname; |
| 952 |
struct sockaddr *ai_addr; |
| 953 |
struct addrinfo *ai_next; |
| 954 |
}; |
| 955 |
#endif |
| 956 |
|
| 957 |
#ifndef HAVE_GETADDRINFO |
| 958 |
#define getaddrinfo rk_getaddrinfo |
| 959 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 960 |
getaddrinfo(const char *, |
| 961 |
const char *, |
| 962 |
const struct addrinfo *, |
| 963 |
struct addrinfo **); |
| 964 |
#endif |
| 965 |
|
| 966 |
#ifndef HAVE_GETNAMEINFO |
| 967 |
#define getnameinfo rk_getnameinfo |
| 968 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 969 |
getnameinfo(const struct sockaddr *, socklen_t, |
| 970 |
char *, size_t, |
| 971 |
char *, size_t, |
| 972 |
int); |
| 973 |
#endif |
| 974 |
|
| 975 |
#ifndef HAVE_FREEADDRINFO |
| 976 |
#define freeaddrinfo rk_freeaddrinfo |
| 977 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL |
| 978 |
freeaddrinfo(struct addrinfo *); |
| 979 |
#endif |
| 980 |
|
| 981 |
#ifndef HAVE_GAI_STRERROR |
| 982 |
#define gai_strerror rk_gai_strerror |
| 983 |
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL |
| 984 |
gai_strerror(int); |
| 985 |
#endif |
| 986 |
|
| 987 |
#ifdef NO_SLEEP |
| 988 |
|
| 989 |
ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL |
| 990 |
sleep(unsigned int seconds); |
| 991 |
|
| 992 |
ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL |
| 993 |
usleep(unsigned int useconds); |
| 994 |
|
| 995 |
#endif |
| 996 |
|
| 997 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 998 |
getnameinfo_verified(const struct sockaddr *, socklen_t, |
| 999 |
char *, size_t, |
| 1000 |
char *, size_t, |
| 1001 |
int); |
| 1002 |
|
| 1003 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1004 |
roken_getaddrinfo_hostspec(const char *, int, struct addrinfo **); |
| 1005 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1006 |
roken_getaddrinfo_hostspec2(const char *, int, int, struct addrinfo **); |
| 1007 |
|
| 1008 |
#ifndef HAVE_STRFTIME |
| 1009 |
#define strftime rk_strftime |
| 1010 |
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL |
| 1011 |
strftime (char *, size_t, const char *, const struct tm *); |
| 1012 |
#endif |
| 1013 |
|
| 1014 |
#ifndef HAVE_STRPTIME |
| 1015 |
#define strptime rk_strptime |
| 1016 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL |
| 1017 |
strptime (const char *, const char *, struct tm *); |
| 1018 |
#endif |
| 1019 |
|
| 1020 |
#ifndef HAVE_GETTIMEOFDAY |
| 1021 |
#define gettimeofday rk_gettimeofday |
| 1022 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1023 |
gettimeofday (struct timeval *, void *); |
| 1024 |
#endif |
| 1025 |
|
| 1026 |
#ifndef HAVE_EMALLOC |
| 1027 |
#define emalloc rk_emalloc |
| 1028 |
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL emalloc (size_t); |
| 1029 |
#endif |
| 1030 |
#ifndef HAVE_ECALLOC |
| 1031 |
#define ecalloc rk_ecalloc |
| 1032 |
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL ecalloc(size_t, size_t); |
| 1033 |
#endif |
| 1034 |
#ifndef HAVE_EREALLOC |
| 1035 |
#define erealloc rk_erealloc |
| 1036 |
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL erealloc (void *, size_t); |
| 1037 |
#endif |
| 1038 |
#ifndef HAVE_ESTRDUP |
| 1039 |
#define estrdup rk_estrdup |
| 1040 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL estrdup (const char *); |
| 1041 |
#endif |
| 1042 |
|
| 1043 |
/* |
| 1044 |
* kludges and such |
| 1045 |
*/ |
| 1046 |
|
| 1047 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1048 |
roken_gethostby_setup(const char*, const char*); |
| 1049 |
ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL |
| 1050 |
roken_gethostbyname(const char*); |
| 1051 |
ROKEN_LIB_FUNCTION struct hostent* ROKEN_LIB_CALL |
| 1052 |
roken_gethostbyaddr(const void*, size_t, int); |
| 1053 |
|
| 1054 |
#ifdef GETSERVBYNAME_PROTO_COMPATIBLE |
| 1055 |
#define roken_getservbyname(x,y) getservbyname(x,y) |
| 1056 |
#else |
| 1057 |
#define roken_getservbyname(x,y) getservbyname((char *)x, (char *)y) |
| 1058 |
#endif |
| 1059 |
|
| 1060 |
#ifdef OPENLOG_PROTO_COMPATIBLE |
| 1061 |
#define roken_openlog(a,b,c) openlog(a,b,c) |
| 1062 |
#else |
| 1063 |
#define roken_openlog(a,b,c) openlog((char *)a,b,c) |
| 1064 |
#endif |
| 1065 |
|
| 1066 |
#ifdef GETSOCKNAME_PROTO_COMPATIBLE |
| 1067 |
#define roken_getsockname(a,b,c) getsockname(a,b,c) |
| 1068 |
#else |
| 1069 |
#define roken_getsockname(a,b,c) getsockname(a, b, (void*)c) |
| 1070 |
#endif |
| 1071 |
|
| 1072 |
#ifndef HAVE_SETPROGNAME |
| 1073 |
#define setprogname rk_setprogname |
| 1074 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL setprogname(const char *); |
| 1075 |
#endif |
| 1076 |
|
| 1077 |
#ifndef HAVE_GETPROGNAME |
| 1078 |
#define getprogname rk_getprogname |
| 1079 |
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL getprogname(void); |
| 1080 |
#endif |
| 1081 |
|
| 1082 |
#if !defined(HAVE_SETPROGNAME) && !defined(HAVE_GETPROGNAME) && !HAVE_DECL___PROGNAME |
| 1083 |
extern const char *__progname; |
| 1084 |
#endif |
| 1085 |
|
| 1086 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL |
| 1087 |
mini_inetd_addrinfo (struct addrinfo*, rk_socket_t *); |
| 1088 |
|
| 1089 |
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL |
| 1090 |
mini_inetd (int, rk_socket_t *); |
| 1091 |
|
| 1092 |
#ifndef HAVE_LOCALTIME_R |
| 1093 |
#define localtime_r rk_localtime_r |
| 1094 |
ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL |
| 1095 |
localtime_r(const time_t *, struct tm *); |
| 1096 |
#endif |
| 1097 |
|
| 1098 |
#if !defined(HAVE_STRTOLL) || defined(NEED_STRTOLL_PROTO) |
| 1099 |
#ifndef HAVE_STRTOLL |
| 1100 |
#define strtoll rk_strtoll |
| 1101 |
#endif |
| 1102 |
ROKEN_LIB_FUNCTION long long ROKEN_LIB_CALL |
| 1103 |
strtoll(const char * nptr, char ** endptr, int base); |
| 1104 |
#endif |
| 1105 |
|
| 1106 |
#if !defined(HAVE_STRTOULL) || defined(NEED_STRTOULL_PROTO) |
| 1107 |
#ifndef HAVE_STRTOULL |
| 1108 |
#define strtoull rk_strtoull |
| 1109 |
#endif |
| 1110 |
ROKEN_LIB_FUNCTION unsigned long long ROKEN_LIB_CALL |
| 1111 |
strtoull(const char * nptr, char ** endptr, int base); |
| 1112 |
#endif |
| 1113 |
|
| 1114 |
#if !defined(HAVE_STRSVIS) || defined(NEED_STRSVIS_PROTO) |
| 1115 |
#ifndef HAVE_STRSVIS |
| 1116 |
#define strsvis rk_strsvis |
| 1117 |
#endif |
| 1118 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1119 |
strsvis(char *, const char *, int, const char *); |
| 1120 |
#endif |
| 1121 |
|
| 1122 |
#if !defined(HAVE_STRSVISX) || defined(NEED_STRSVISX_PROTO) |
| 1123 |
#ifndef HAVE_STRSVISX |
| 1124 |
#define strsvisx rk_strsvisx |
| 1125 |
#endif |
| 1126 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1127 |
strsvisx(char *, const char *, size_t, int, const char *); |
| 1128 |
#endif |
| 1129 |
|
| 1130 |
#if !defined(HAVE_STRUNVIS) || defined(NEED_STRUNVIS_PROTO) |
| 1131 |
#ifndef HAVE_STRUNVIS |
| 1132 |
#define strunvis rk_strunvis |
| 1133 |
#endif |
| 1134 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1135 |
strunvis(char *, const char *); |
| 1136 |
#endif |
| 1137 |
|
| 1138 |
#if !defined(HAVE_STRVIS) || defined(NEED_STRVIS_PROTO) |
| 1139 |
#ifndef HAVE_STRVIS |
| 1140 |
#define strvis rk_strvis |
| 1141 |
#endif |
| 1142 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1143 |
strvis(char *, const char *, int); |
| 1144 |
#endif |
| 1145 |
|
| 1146 |
#if !defined(HAVE_STRVISX) || defined(NEED_STRVISX_PROTO) |
| 1147 |
#ifndef HAVE_STRVISX |
| 1148 |
#define strvisx rk_strvisx |
| 1149 |
#endif |
| 1150 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1151 |
strvisx(char *, const char *, size_t, int); |
| 1152 |
#endif |
| 1153 |
|
| 1154 |
#if !defined(HAVE_SVIS) || defined(NEED_SVIS_PROTO) |
| 1155 |
#ifndef HAVE_SVIS |
| 1156 |
#define svis rk_svis |
| 1157 |
#endif |
| 1158 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL |
| 1159 |
svis(char *, int, int, int, const char *); |
| 1160 |
#endif |
| 1161 |
|
| 1162 |
#if !defined(HAVE_UNVIS) || defined(NEED_UNVIS_PROTO) |
| 1163 |
#ifndef HAVE_UNVIS |
| 1164 |
#define unvis rk_unvis |
| 1165 |
#endif |
| 1166 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1167 |
unvis(char *, int, int *, int); |
| 1168 |
#endif |
| 1169 |
|
| 1170 |
#if !defined(HAVE_VIS) || defined(NEED_VIS_PROTO) |
| 1171 |
#ifndef HAVE_VIS |
| 1172 |
#define vis rk_vis |
| 1173 |
#endif |
| 1174 |
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL |
| 1175 |
vis(char *, int, int, int); |
| 1176 |
#endif |
| 1177 |
|
| 1178 |
#if !defined(HAVE_CLOSEFROM) |
| 1179 |
#define closefrom rk_closefrom |
| 1180 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL |
| 1181 |
closefrom(int); |
| 1182 |
#endif |
| 1183 |
|
| 1184 |
#if !defined(HAVE_TIMEGM) |
| 1185 |
#define timegm rk_timegm |
| 1186 |
ROKEN_LIB_FUNCTION time_t ROKEN_LIB_CALL |
| 1187 |
rk_timegm(struct tm *tm); |
| 1188 |
#endif |
| 1189 |
|
| 1190 |
#ifdef NEED_QSORT |
| 1191 |
#define qsort rk_qsort |
| 1192 |
void |
| 1193 |
rk_qsort(void *, size_t, size_t, int (*)(const void *, const void *)); |
| 1194 |
#endif |
| 1195 |
|
| 1196 |
#ifndef HAVE_MEMSET_S |
| 1197 |
#define memset_s rk_memset_s |
| 1198 |
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL memset_s(void *s, size_t smax, |
| 1199 |
int c, size_t n); |
| 1200 |
#endif |
| 1201 |
|
| 1202 |
#if defined(HAVE_ARC4RANDOM) |
| 1203 |
# define rk_random() arc4random() |
| 1204 |
#elif defined(HAVE_RANDOM) |
| 1205 |
# define rk_random() random() |
| 1206 |
#else |
| 1207 |
# ifdef HAVE_WIN32_RAND_S |
| 1208 |
ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL |
| 1209 |
rk_random(void); |
| 1210 |
# else |
| 1211 |
# define rk_random() rand() |
| 1212 |
# endif |
| 1213 |
#endif |
| 1214 |
|
| 1215 |
#ifndef HAVE_TDELETE |
| 1216 |
#define tdelete(a,b,c) rk_tdelete(a,b,c) |
| 1217 |
#endif |
| 1218 |
#ifndef HAVE_TFIND |
| 1219 |
#define tfind(a,b,c) rk_tfind(a,b,c) |
| 1220 |
#endif |
| 1221 |
#ifndef HAVE_TSEARCH |
| 1222 |
#define tsearch(a,b,c) rk_tsearch(a,b,c) |
| 1223 |
#endif |
| 1224 |
#ifndef HAVE_TWALK |
| 1225 |
#define twalk(a,b) rk_twalk(a,b) |
| 1226 |
#endif |
| 1227 |
|
| 1228 |
#if defined(__linux__) && defined(SOCK_CLOEXEC) && !defined(SOCKET_WRAPPER_REPLACE) && !defined(__SOCKET_WRAPPER_H__) |
| 1229 |
#undef socket |
| 1230 |
#define socket(_fam,_type,_prot) rk_socket(_fam,_type,_prot) |
| 1231 |
int ROKEN_LIB_FUNCTION rk_socket(int, int, int); |
| 1232 |
#endif |
| 1233 |
|
| 1234 |
/* Microsoft VC 2010 POSIX definitions */ |
| 1235 |
#ifndef EAFNOSUPPORT |
| 1236 |
#define EAFNOSUPPORT 102 |
| 1237 |
#endif |
| 1238 |
#ifndef EINPROGRESS |
| 1239 |
#define EINPROGRESS 112 |
| 1240 |
#endif |
| 1241 |
#ifndef ELOOP |
| 1242 |
#define ELOOP 114 |
| 1243 |
#endif |
| 1244 |
#ifndef ENOTSOCK |
| 1245 |
#define ENOTSOCK 128 |
| 1246 |
#endif |
| 1247 |
#ifndef ENOTSUP |
| 1248 |
#define ENOTSUP 129 |
| 1249 |
#endif |
| 1250 |
#ifndef EOVERFLOW |
| 1251 |
#define EOVERFLOW 132 |
| 1252 |
#endif |
| 1253 |
#ifndef ETIMEDOUT |
| 1254 |
#define ETIMEDOUT 138 |
| 1255 |
#endif |
| 1256 |
#ifndef EWOULDBLOCK |
| 1257 |
#define EWOULDBLOCK 140 |
| 1258 |
#endif |
| 1259 |
|
| 1260 |
|
| 1261 |
#ifdef SOCKET_WRAPPER_REPLACE |
| 1262 |
#include <socket_wrapper.h> |
| 1263 |
#endif |
| 1264 |
|
| 1265 |
ROKEN_CPP_END |