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