2 * Copyright (c) 1995 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
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.
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
36 #ifndef __ROKEN_COMMON_H__
37 #define __ROKEN_COMMON_H__
39 #ifndef ROKEN_LIB_FUNCTION
41 #define ROKEN_LIB_FUNCTION
42 #define ROKEN_LIB_CALL __cdecl
44 #define ROKEN_LIB_FUNCTION
45 #define ROKEN_LIB_CALL
50 #define ROKEN_CPP_START extern "C" {
51 #define ROKEN_CPP_END }
53 #define ROKEN_CPP_START
58 #define INADDR_NONE 0xffffffff
61 #ifndef INADDR_LOOPBACK
62 #define INADDR_LOOPBACK 0x7f000001
70 #define STDIN_FILENO 0
74 #define STDOUT_FILENO 1
78 #define STDERR_FILENO 2
82 #define max(a,b) (((a)>(b))?(a):(b))
86 #define min(a,b) (((a)<(b))?(a):(b))
98 #define openlog(id,option,facility) openlog((id),(option))
105 #define LOG_NDELAY 0x08
114 #define LOG_AUTHPRIV LOG_AUTH
122 #define O_ACCMODE 003
128 #define _PATH_DEV "/dev/"
131 #ifndef _PATH_DEVNULL
132 #define _PATH_DEVNULL "/dev/null"
136 #define _PATH_HEQUIV "/etc/hosts.equiv"
140 #define _PATH_VARRUN "/var/run/"
144 #define _PATH_BSHELL "/bin/sh"
148 #define MAXPATHLEN (1024+4)
155 #define PATH_MAX MAX_PATH
157 #define PATH_MAX 4096
162 #define RETSIGTYPE void
166 #define SIG_ERR ((RETSIGTYPE (*)(int))-1)
170 * error code for getipnodeby{name,addr}
173 #ifndef HOST_NOT_FOUND
174 #define HOST_NOT_FOUND 1
182 #define NO_RECOVERY 3
190 #define NO_ADDRESS NO_DATA
194 * error code for getaddrinfo
198 #define EAI_NOERROR 0 /* no error */
203 #define EAI_ADDRFAMILY 1 /* address family for nodename not supported */
204 #define EAI_AGAIN 2 /* temporary failure in name resolution */
205 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
206 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
207 #define EAI_FAMILY 5 /* ai_family not supported */
208 #define EAI_MEMORY 6 /* memory allocation failure */
209 #define EAI_NODATA 7 /* no address associated with nodename */
210 #define EAI_NONAME 8 /* nodename nor servname provided, or not known */
211 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
212 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
213 #define EAI_SYSTEM 11 /* system error returned in errno */
215 #endif /* EAI_NONAME */
217 /* flags for getaddrinfo() */
220 #define AI_PASSIVE 0x01
221 #define AI_CANONNAME 0x02
222 #endif /* AI_PASSIVE */
224 #ifndef AI_NUMERICHOST
225 #define AI_NUMERICHOST 0x04
228 #ifndef AI_NUMERICSERV
229 #define AI_NUMERICSERV 0x08
232 /* flags for getnameinfo() */
235 #define NI_DGRAM 0x01
236 #define NI_NAMEREQD 0x02
237 #define NI_NOFQDN 0x04
238 #define NI_NUMERICHOST 0x08
239 #define NI_NUMERICSERV 0x10
243 * constants for getnameinfo
247 #define NI_MAXHOST 1025
248 #define NI_MAXSERV 32
252 * constants for inet_ntop
255 #ifndef INET_ADDRSTRLEN
256 #define INET_ADDRSTRLEN 16
259 #ifndef INET6_ADDRSTRLEN
260 #define INET6_ADDRSTRLEN 46
279 #ifndef HAVE___ATTRIBUTE__
280 #define __attribute__(x)
285 #ifndef IRIX4 /* fix for compiler bug */
288 typedef RETSIGTYPE (*SigAction
)(int);
289 SigAction
signal(int iSig
, SigAction pAction
); /* BSD compatible */
294 #define SE_E_UNSPECIFIED (-1)
295 #define SE_E_FORKFAILED (-2)
296 #define SE_E_WAITPIDFAILED (-3)
297 #define SE_E_EXECTIMEOUT (-4)
298 #define SE_E_NOEXEC 126
299 #define SE_E_NOTFOUND 127
301 #define SE_PROCSTATUS(st) (((st) >= 0 && (st) < 126)? st: -1)
302 #define SE_PROCSIGNAL(st) (((st) >= 128)? (st) - 128: -1)
303 #define SE_IS_ERROR(st) ((st) < 0 || (st) >= 126)
306 #define simple_execve rk_simple_execve
307 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
308 simple_execve(const char*, char*const[], char*const[]);
310 #define simple_execve_timed rk_simple_execve_timed
311 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
312 simple_execve_timed(const char *, char *const[],
313 char *const [], time_t (*)(void *),
316 #define simple_execvp rk_simple_execvp
317 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
318 simple_execvp(const char*, char *const[]);
320 #define simple_execvp_timed rk_simple_execvp_timed
321 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
322 simple_execvp_timed(const char *, char *const[],
323 time_t (*)(void *), void *, time_t);
325 #define simple_execlp rk_simple_execlp
326 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
327 simple_execlp(const char*, ...);
329 #define simple_execle rk_simple_execle
330 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
331 simple_execle(const char*, ...);
333 #define wait_for_process rk_wait_for_process
334 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
335 wait_for_process(pid_t
);
337 #define wait_for_process_timed rk_wait_for_process_timed
338 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
339 wait_for_process_timed(pid_t
, time_t (*)(void *),
342 #define pipe_execv rk_pipe_execv
343 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
344 pipe_execv(FILE**, FILE**, FILE**, const char*, ...);
346 #define print_version rk_print_version
347 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
348 print_version(const char *);
350 #define eread rk_eread
351 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
352 eread (int fd
, void *buf
, size_t nbytes
);
354 #define ewrite rk_ewrite
355 ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
356 ewrite (int fd
, const void *buf
, size_t nbytes
);
360 #define hostent_find_fqdn rk_hostent_find_fqdn
361 ROKEN_LIB_FUNCTION
const char * ROKEN_LIB_CALL
362 hostent_find_fqdn (const struct hostent
*);
364 #define esetenv rk_esetenv
365 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
366 esetenv(const char *, const char *, int);
368 #define socket_set_address_and_port rk_socket_set_address_and_port
369 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
370 socket_set_address_and_port (struct sockaddr
*, const void *, int);
372 #define socket_addr_size rk_socket_addr_size
373 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
374 socket_addr_size (const struct sockaddr
*);
376 #define socket_set_any rk_socket_set_any
377 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
378 socket_set_any (struct sockaddr
*, int);
380 #define socket_sockaddr_size rk_socket_sockaddr_size
381 ROKEN_LIB_FUNCTION
size_t ROKEN_LIB_CALL
382 socket_sockaddr_size (const struct sockaddr
*);
384 #define socket_get_address rk_socket_get_address
385 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
386 socket_get_address (const struct sockaddr
*);
388 #define socket_get_port rk_socket_get_port
389 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
390 socket_get_port (const struct sockaddr
*);
392 #define socket_set_port rk_socket_set_port
393 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
394 socket_set_port (struct sockaddr
*, int);
396 #define socket_set_portrange rk_socket_set_portrange
397 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
398 socket_set_portrange (rk_socket_t
, int, int);
400 #define socket_set_debug rk_socket_set_debug
401 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
402 socket_set_debug (rk_socket_t
);
404 #define socket_set_tos rk_socket_set_tos
405 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
406 socket_set_tos (rk_socket_t
, int);
408 #define socket_set_nonblocking rk_socket_set_nonblocking
409 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
410 socket_set_nonblocking(rk_socket_t
, int);
412 #define socket_set_reuseaddr rk_socket_set_reuseaddr
413 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
414 socket_set_reuseaddr (rk_socket_t
, int);
416 #define socket_set_ipv6only rk_socket_set_ipv6only
417 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
418 socket_set_ipv6only (rk_socket_t
, int);
420 #define socket_to_fd rk_socket_to_fd
421 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
422 socket_to_fd(rk_socket_t
, int);
424 #define vstrcollect rk_vstrcollect
425 ROKEN_LIB_FUNCTION
char ** ROKEN_LIB_CALL
426 vstrcollect(va_list *ap
);
428 #define strcollect rk_strcollect
429 ROKEN_LIB_FUNCTION
char ** ROKEN_LIB_CALL
430 strcollect(char *first
, ...);
432 #define timevalfix rk_timevalfix
433 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
434 timevalfix(struct timeval
*t1
);
436 #define timevaladd rk_timevaladd
437 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
438 timevaladd(struct timeval
*t1
, const struct timeval
*t2
);
440 #define timevalsub rk_timevalsub
441 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
442 timevalsub(struct timeval
*t1
, const struct timeval
*t2
);
444 #define pid_file_write rk_pid_file_write
445 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
446 pid_file_write (const char *progname
);
448 #define pid_file_delete rk_pid_file_delete
449 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
450 pid_file_delete (char **);
452 #define read_environment rk_read_environment
453 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
454 read_environment(const char *file
, char ***env
);
456 #define free_environment rk_free_environment
457 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
458 free_environment(char **);
460 #define warnerr rk_warnerr
461 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
462 rk_warnerr(int doerrno
, const char *fmt
, va_list ap
)
463 __attribute__ ((format (printf
, 2, 0)));
465 ROKEN_LIB_FUNCTION
void * ROKEN_LIB_CALL
466 rk_realloc(void *, size_t);
470 ROKEN_LIB_FUNCTION
char * ROKEN_LIB_CALL
471 rk_strpoolcollect(struct rk_strpool
*);
473 ROKEN_LIB_FUNCTION
struct rk_strpool
* ROKEN_LIB_CALL
474 rk_strpoolprintf(struct rk_strpool
*, const char *, ...)
475 __attribute__ ((format (printf
, 2, 3)));
477 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
478 rk_strpoolfree(struct rk_strpool
*);
480 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
481 rk_dumpdata (const char *, const void *, size_t);
483 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
484 rk_undumpdata (const char *, void **, size_t *);
486 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
489 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
492 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
493 rk_cloexec_file(FILE *);
495 ROKEN_LIB_FUNCTION
void ROKEN_LIB_CALL
496 rk_cloexec_dir(DIR *);
498 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
499 ct_memcmp(const void *, const void *, size_t);
501 void ROKEN_LIB_FUNCTION
502 rk_random_init(void);
504 #define mkdir rk_mkdir
505 ROKEN_LIB_FUNCTION
int ROKEN_LIB_CALL
506 rk_mkdir(const char *, mode_t
);
510 #endif /* __ROKEN_COMMON_H__ */