1/* 2 * Copyright (c) 1995 - 2005 Kungliga Tekniska H��gskolan 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of the Institute nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34/* $Id: roken-common.h,v 1.1.1.1 2011/06/10 09:34:42 andrew Exp $ */ 35 36#ifndef __ROKEN_COMMON_H__ 37#define __ROKEN_COMMON_H__ 38 39#ifndef ROKEN_LIB_FUNCTION 40#ifdef _WIN32 41#define ROKEN_LIB_FUNCTION _stdcall 42#else 43#define ROKEN_LIB_FUNCTION 44#endif 45#endif 46 47#ifdef __cplusplus 48#define ROKEN_CPP_START extern "C" { 49#define ROKEN_CPP_END } 50#else 51#define ROKEN_CPP_START 52#define ROKEN_CPP_END 53#endif 54 55#ifndef INADDR_NONE 56#define INADDR_NONE 0xffffffff 57#endif 58 59#ifndef INADDR_LOOPBACK 60#define INADDR_LOOPBACK 0x7f000001 61#endif 62 63#ifndef SOMAXCONN 64#define SOMAXCONN 5 65#endif 66 67#ifndef STDIN_FILENO 68#define STDIN_FILENO 0 69#endif 70 71#ifndef STDOUT_FILENO 72#define STDOUT_FILENO 1 73#endif 74 75#ifndef STDERR_FILENO 76#define STDERR_FILENO 2 77#endif 78 79#ifndef max 80#define max(a,b) (((a)>(b))?(a):(b)) 81#endif 82 83#ifndef min 84#define min(a,b) (((a)<(b))?(a):(b)) 85#endif 86 87#ifndef TRUE 88#define TRUE 1 89#endif 90 91#ifndef FALSE 92#define FALSE 0 93#endif 94 95#ifndef LOG_DAEMON 96#define openlog(id,option,facility) openlog((id),(option)) 97#define LOG_DAEMON 0 98#endif 99#ifndef LOG_ODELAY 100#define LOG_ODELAY 0 101#endif 102#ifndef LOG_NDELAY 103#define LOG_NDELAY 0x08 104#endif 105#ifndef LOG_CONS 106#define LOG_CONS 0 107#endif 108#ifndef LOG_AUTH 109#define LOG_AUTH 0 110#endif 111#ifndef LOG_AUTHPRIV 112#define LOG_AUTHPRIV LOG_AUTH 113#endif 114 115#ifndef F_OK 116#define F_OK 0 117#endif 118 119#ifndef O_ACCMODE 120#define O_ACCMODE 003 121#endif 122 123#ifndef _PATH_DEV 124#define _PATH_DEV "/dev/" 125#endif 126 127#ifndef _PATH_DEVNULL 128#define _PATH_DEVNULL "/dev/null" 129#endif 130 131#ifndef _PATH_HEQUIV 132#define _PATH_HEQUIV "/etc/hosts.equiv" 133#endif 134 135#ifndef _PATH_VARRUN 136#define _PATH_VARRUN "/var/run/" 137#endif 138 139#ifndef _PATH_BSHELL 140#define _PATH_BSHELL "/bin/sh" 141#endif 142 143#ifndef MAXPATHLEN 144#define MAXPATHLEN (1024+4) 145#endif 146 147#ifndef SIG_ERR 148#define SIG_ERR ((RETSIGTYPE (*)(int))-1) 149#endif 150 151/* 152 * error code for getipnodeby{name,addr} 153 */ 154 155#ifndef HOST_NOT_FOUND 156#define HOST_NOT_FOUND 1 157#endif 158 159#ifndef TRY_AGAIN 160#define TRY_AGAIN 2 161#endif 162 163#ifndef NO_RECOVERY 164#define NO_RECOVERY 3 165#endif 166 167#ifndef NO_DATA 168#define NO_DATA 4 169#endif 170 171#ifndef NO_ADDRESS 172#define NO_ADDRESS NO_DATA 173#endif 174 175/* 176 * error code for getaddrinfo 177 */ 178 179#ifndef EAI_NOERROR 180#define EAI_NOERROR 0 /* no error */ 181#endif 182 183#ifndef EAI_NONAME 184 185#define EAI_ADDRFAMILY 1 /* address family for nodename not supported */ 186#define EAI_AGAIN 2 /* temporary failure in name resolution */ 187#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 188#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 189#define EAI_FAMILY 5 /* ai_family not supported */ 190#define EAI_MEMORY 6 /* memory allocation failure */ 191#define EAI_NODATA 7 /* no address associated with nodename */ 192#define EAI_NONAME 8 /* nodename nor servname provided, or not known */ 193#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 194#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 195#define EAI_SYSTEM 11 /* system error returned in errno */ 196 197#endif /* EAI_NONAME */ 198 199/* flags for getaddrinfo() */ 200 201#ifndef AI_PASSIVE 202#define AI_PASSIVE 0x01 203#define AI_CANONNAME 0x02 204#endif /* AI_PASSIVE */ 205 206#ifndef AI_NUMERICHOST 207#define AI_NUMERICHOST 0x04 208#endif 209 210/* flags for getnameinfo() */ 211 212#ifndef NI_DGRAM 213#define NI_DGRAM 0x01 214#define NI_NAMEREQD 0x02 215#define NI_NOFQDN 0x04 216#define NI_NUMERICHOST 0x08 217#define NI_NUMERICSERV 0x10 218#endif 219 220/* 221 * constants for getnameinfo 222 */ 223 224#ifndef NI_MAXHOST 225#define NI_MAXHOST 1025 226#define NI_MAXSERV 32 227#endif 228 229/* 230 * constants for inet_ntop 231 */ 232 233#ifndef INET_ADDRSTRLEN 234#define INET_ADDRSTRLEN 16 235#endif 236 237#ifndef INET6_ADDRSTRLEN 238#define INET6_ADDRSTRLEN 46 239#endif 240 241/* 242 * for shutdown(2) 243 */ 244 245#ifndef SHUT_RD 246#define SHUT_RD 0 247#endif 248 249#ifndef SHUT_WR 250#define SHUT_WR 1 251#endif 252 253#ifndef SHUT_RDWR 254#define SHUT_RDWR 2 255#endif 256 257#ifndef HAVE___ATTRIBUTE__ 258#define __attribute__(x) 259#endif 260 261ROKEN_CPP_START 262 263#ifndef IRIX4 /* fix for compiler bug */ 264#ifdef RETSIGTYPE 265typedef RETSIGTYPE (*SigAction)(int); 266SigAction signal(int iSig, SigAction pAction); /* BSD compatible */ 267#endif 268#endif 269 270#define simple_execve rk_simple_execve 271int ROKEN_LIB_FUNCTION 272simple_execve(const char*, char*const[], char*const[]); 273 274#define simple_execve_timed rk_simple_execve_timed 275int ROKEN_LIB_FUNCTION 276simple_execve_timed(const char *, char *const[], 277 char *const [], time_t (*)(void *), 278 void *, time_t); 279 280#define simple_execvp rk_simple_execvp 281int ROKEN_LIB_FUNCTION 282simple_execvp(const char*, char *const[]); 283 284#define simple_execvp_timed rk_simple_execvp_timed 285int ROKEN_LIB_FUNCTION 286simple_execvp_timed(const char *, char *const[], 287 time_t (*)(void *), void *, time_t); 288 289#define simple_execlp rk_simple_execlp 290int ROKEN_LIB_FUNCTION 291simple_execlp(const char*, ...); 292 293#define simple_execle rk_simple_execle 294int ROKEN_LIB_FUNCTION 295simple_execle(const char*, ...); 296 297#define wait_for_process rk_wait_for_process 298int ROKEN_LIB_FUNCTION 299wait_for_process(pid_t); 300 301#define wait_for_process_timed rk_wait_for_process_timed 302int ROKEN_LIB_FUNCTION 303wait_for_process_timed(pid_t, time_t (*)(void *), 304 void *, time_t); 305#define pipe_execv rk_pipe_execv 306int ROKEN_LIB_FUNCTION 307pipe_execv(FILE**, FILE**, FILE**, const char*, ...); 308 309#define print_version rk_print_version 310void ROKEN_LIB_FUNCTION 311print_version(const char *); 312 313#define eread rk_eread 314ssize_t ROKEN_LIB_FUNCTION 315eread (int fd, void *buf, size_t nbytes); 316 317#define ewrite rk_ewrite 318ssize_t ROKEN_LIB_FUNCTION 319ewrite (int fd, const void *buf, size_t nbytes); 320 321struct hostent; 322 323#define hostent_find_fqdn rk_hostent_find_fqdn 324const char * ROKEN_LIB_FUNCTION 325hostent_find_fqdn (const struct hostent *); 326 327#define esetenv rk_esetenv 328void ROKEN_LIB_FUNCTION 329esetenv(const char *, const char *, int); 330 331#define socket_set_address_and_port rk_socket_set_address_and_port 332void ROKEN_LIB_FUNCTION 333socket_set_address_and_port (struct sockaddr *, const void *, int); 334 335#define socket_addr_size rk_socket_addr_size 336size_t ROKEN_LIB_FUNCTION 337socket_addr_size (const struct sockaddr *); 338 339#define socket_set_any rk_socket_set_any 340void ROKEN_LIB_FUNCTION 341socket_set_any (struct sockaddr *, int); 342 343#define socket_sockaddr_size rk_socket_sockaddr_size 344size_t ROKEN_LIB_FUNCTION 345socket_sockaddr_size (const struct sockaddr *); 346 347#define socket_get_address rk_socket_get_address 348void * ROKEN_LIB_FUNCTION 349socket_get_address (const struct sockaddr *); 350 351#define socket_get_port rk_socket_get_port 352int ROKEN_LIB_FUNCTION 353socket_get_port (const struct sockaddr *); 354 355#define socket_set_port rk_socket_set_port 356void ROKEN_LIB_FUNCTION 357socket_set_port (struct sockaddr *, int); 358 359#define socket_set_portrange rk_socket_set_portrange 360void ROKEN_LIB_FUNCTION 361socket_set_portrange (int, int, int); 362 363#define socket_set_debug rk_socket_set_debug 364void ROKEN_LIB_FUNCTION 365socket_set_debug (int); 366 367#define socket_set_tos rk_socket_set_tos 368void ROKEN_LIB_FUNCTION 369socket_set_tos (int, int); 370 371#define socket_set_reuseaddr rk_socket_set_reuseaddr 372void ROKEN_LIB_FUNCTION 373socket_set_reuseaddr (int, int); 374 375#define socket_set_ipv6only rk_socket_set_ipv6only 376void ROKEN_LIB_FUNCTION 377socket_set_ipv6only (int, int); 378 379#define vstrcollect rk_vstrcollect 380char ** ROKEN_LIB_FUNCTION 381vstrcollect(va_list *ap); 382 383#define strcollect rk_strcollect 384char ** ROKEN_LIB_FUNCTION 385strcollect(char *first, ...); 386 387#define timevalfix rk_timevalfix 388void ROKEN_LIB_FUNCTION 389timevalfix(struct timeval *t1); 390 391#define timevaladd rk_timevaladd 392void ROKEN_LIB_FUNCTION 393timevaladd(struct timeval *t1, const struct timeval *t2); 394 395#define timevalsub rk_timevalsub 396void ROKEN_LIB_FUNCTION 397timevalsub(struct timeval *t1, const struct timeval *t2); 398 399#define pid_file_write rk_pid_file_write 400char *ROKEN_LIB_FUNCTION 401pid_file_write (const char *progname); 402 403#define pid_file_delete rk_pid_file_delete 404void ROKEN_LIB_FUNCTION 405pid_file_delete (char **); 406 407#define read_environment rk_read_environment 408int ROKEN_LIB_FUNCTION 409read_environment(const char *file, char ***env); 410 411#define free_environment rk_free_environment 412void ROKEN_LIB_FUNCTION 413free_environment(char **); 414 415#define warnerr rk_warnerr 416void ROKEN_LIB_FUNCTION 417rk_warnerr(int doerrno, const char *fmt, va_list ap) 418 __attribute__ ((format (printf, 2, 0))); 419 420void * ROKEN_LIB_FUNCTION 421rk_realloc(void *, size_t); 422 423struct rk_strpool; 424 425char * ROKEN_LIB_FUNCTION 426rk_strpoolcollect(struct rk_strpool *); 427 428struct rk_strpool * ROKEN_LIB_FUNCTION 429rk_strpoolprintf(struct rk_strpool *, const char *, ...) 430 __attribute__ ((format (printf, 2, 3))); 431 432void ROKEN_LIB_FUNCTION 433rk_strpoolfree(struct rk_strpool *); 434 435void ROKEN_LIB_FUNCTION 436rk_dumpdata (const char *, const void *, size_t); 437 438int ROKEN_LIB_FUNCTION 439rk_undumpdata (const char *, void **, size_t *); 440 441void ROKEN_LIB_FUNCTION 442rk_xfree (void *); 443 444void ROKEN_LIB_FUNCTION 445rk_cloexec(int); 446 447void ROKEN_LIB_FUNCTION 448rk_cloexec_file(FILE *); 449 450 451ROKEN_CPP_END 452 453#endif /* __ROKEN_COMMON_H__ */ 454