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 _stdcall
43 #define ROKEN_LIB_FUNCTION
48 #define ROKEN_CPP_START extern "C" {
49 #define ROKEN_CPP_END }
51 #define ROKEN_CPP_START
56 #define INADDR_NONE 0xffffffff
59 #ifndef INADDR_LOOPBACK
60 #define INADDR_LOOPBACK 0x7f000001
68 #define STDIN_FILENO 0
72 #define STDOUT_FILENO 1
76 #define STDERR_FILENO 2
80 #define max(a,b) (((a)>(b))?(a):(b))
84 #define min(a,b) (((a)<(b))?(a):(b))
96 #define openlog(id,option,facility) openlog((id),(option))
103 #define LOG_NDELAY 0x08
112 #define LOG_AUTHPRIV LOG_AUTH
120 #define O_ACCMODE 003
124 #define _PATH_DEV "/dev/"
127 #ifndef _PATH_DEVNULL
128 #define _PATH_DEVNULL "/dev/null"
132 #define _PATH_HEQUIV "/etc/hosts.equiv"
136 #define _PATH_VARRUN "/var/run/"
140 #define _PATH_BSHELL "/bin/sh"
144 #define MAXPATHLEN (1024+4)
148 #define SIG_ERR ((RETSIGTYPE (*)(int))-1)
152 * error code for getipnodeby{name,addr}
155 #ifndef HOST_NOT_FOUND
156 #define HOST_NOT_FOUND 1
164 #define NO_RECOVERY 3
172 #define NO_ADDRESS NO_DATA
176 * error code for getaddrinfo
180 #define EAI_NOERROR 0 /* no error */
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 */
197 #endif /* EAI_NONAME */
199 /* flags for getaddrinfo() */
202 #define AI_PASSIVE 0x01
203 #define AI_CANONNAME 0x02
204 #endif /* AI_PASSIVE */
206 #ifndef AI_NUMERICHOST
207 #define AI_NUMERICHOST 0x04
210 /* flags for getnameinfo() */
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
221 * constants for getnameinfo
225 #define NI_MAXHOST 1025
226 #define NI_MAXSERV 32
230 * constants for inet_ntop
233 #ifndef INET_ADDRSTRLEN
234 #define INET_ADDRSTRLEN 16
237 #ifndef INET6_ADDRSTRLEN
238 #define INET6_ADDRSTRLEN 46
257 #ifndef HAVE___ATTRIBUTE__
258 #define __attribute__(x)
263 #ifndef IRIX4 /* fix for compiler bug */
265 typedef RETSIGTYPE (*SigAction
)(int);
266 SigAction
signal(int iSig
, SigAction pAction
); /* BSD compatible */
270 #define simple_execve rk_simple_execve
271 int ROKEN_LIB_FUNCTION
272 simple_execve(const char*, char*const[], char*const[]);
274 #define simple_execve_timed rk_simple_execve_timed
275 int ROKEN_LIB_FUNCTION
276 simple_execve_timed(const char *, char *const[],
277 char *const [], time_t (*)(void *),
280 #define simple_execvp rk_simple_execvp
281 int ROKEN_LIB_FUNCTION
282 simple_execvp(const char*, char *const[]);
284 #define simple_execvp_timed rk_simple_execvp_timed
285 int ROKEN_LIB_FUNCTION
286 simple_execvp_timed(const char *, char *const[],
287 time_t (*)(void *), void *, time_t);
289 #define simple_execlp rk_simple_execlp
290 int ROKEN_LIB_FUNCTION
291 simple_execlp(const char*, ...);
293 #define simple_execle rk_simple_execle
294 int ROKEN_LIB_FUNCTION
295 simple_execle(const char*, ...);
297 #define wait_for_process rk_wait_for_process
298 int ROKEN_LIB_FUNCTION
299 wait_for_process(pid_t
);
301 #define wait_for_process_timed rk_wait_for_process_timed
302 int ROKEN_LIB_FUNCTION
303 wait_for_process_timed(pid_t
, time_t (*)(void *),
305 #define pipe_execv rk_pipe_execv
306 int ROKEN_LIB_FUNCTION
307 pipe_execv(FILE**, FILE**, FILE**, const char*, ...);
309 #define print_version rk_print_version
310 void ROKEN_LIB_FUNCTION
311 print_version(const char *);
313 #define eread rk_eread
314 ssize_t ROKEN_LIB_FUNCTION
315 eread (int fd
, void *buf
, size_t nbytes
);
317 #define ewrite rk_ewrite
318 ssize_t ROKEN_LIB_FUNCTION
319 ewrite (int fd
, const void *buf
, size_t nbytes
);
323 #define hostent_find_fqdn rk_hostent_find_fqdn
324 const char * ROKEN_LIB_FUNCTION
325 hostent_find_fqdn (const struct hostent
*);
327 #define esetenv rk_esetenv
328 void ROKEN_LIB_FUNCTION
329 esetenv(const char *, const char *, int);
331 #define socket_set_address_and_port rk_socket_set_address_and_port
332 void ROKEN_LIB_FUNCTION
333 socket_set_address_and_port (struct sockaddr
*, const void *, int);
335 #define socket_addr_size rk_socket_addr_size
336 size_t ROKEN_LIB_FUNCTION
337 socket_addr_size (const struct sockaddr
*);
339 #define socket_set_any rk_socket_set_any
340 void ROKEN_LIB_FUNCTION
341 socket_set_any (struct sockaddr
*, int);
343 #define socket_sockaddr_size rk_socket_sockaddr_size
344 size_t ROKEN_LIB_FUNCTION
345 socket_sockaddr_size (const struct sockaddr
*);
347 #define socket_get_address rk_socket_get_address
348 void * ROKEN_LIB_FUNCTION
349 socket_get_address (const struct sockaddr
*);
351 #define socket_get_port rk_socket_get_port
352 int ROKEN_LIB_FUNCTION
353 socket_get_port (const struct sockaddr
*);
355 #define socket_set_port rk_socket_set_port
356 void ROKEN_LIB_FUNCTION
357 socket_set_port (struct sockaddr
*, int);
359 #define socket_set_portrange rk_socket_set_portrange
360 void ROKEN_LIB_FUNCTION
361 socket_set_portrange (int, int, int);
363 #define socket_set_debug rk_socket_set_debug
364 void ROKEN_LIB_FUNCTION
365 socket_set_debug (int);
367 #define socket_set_tos rk_socket_set_tos
368 void ROKEN_LIB_FUNCTION
369 socket_set_tos (int, int);
371 #define socket_set_reuseaddr rk_socket_set_reuseaddr
372 void ROKEN_LIB_FUNCTION
373 socket_set_reuseaddr (int, int);
375 #define socket_set_ipv6only rk_socket_set_ipv6only
376 void ROKEN_LIB_FUNCTION
377 socket_set_ipv6only (int, int);
379 #define vstrcollect rk_vstrcollect
380 char ** ROKEN_LIB_FUNCTION
381 vstrcollect(va_list *ap
);
383 #define strcollect rk_strcollect
384 char ** ROKEN_LIB_FUNCTION
385 strcollect(char *first
, ...);
387 #define timevalfix rk_timevalfix
388 void ROKEN_LIB_FUNCTION
389 timevalfix(struct timeval
*t1
);
391 #define timevaladd rk_timevaladd
392 void ROKEN_LIB_FUNCTION
393 timevaladd(struct timeval
*t1
, const struct timeval
*t2
);
395 #define timevalsub rk_timevalsub
396 void ROKEN_LIB_FUNCTION
397 timevalsub(struct timeval
*t1
, const struct timeval
*t2
);
399 #define pid_file_write rk_pid_file_write
400 char *ROKEN_LIB_FUNCTION
401 pid_file_write (const char *progname
);
403 #define pid_file_delete rk_pid_file_delete
404 void ROKEN_LIB_FUNCTION
405 pid_file_delete (char **);
407 #define read_environment rk_read_environment
408 int ROKEN_LIB_FUNCTION
409 read_environment(const char *file
, char ***env
);
411 #define free_environment rk_free_environment
412 void ROKEN_LIB_FUNCTION
413 free_environment(char **);
415 #define warnerr rk_warnerr
416 void ROKEN_LIB_FUNCTION
417 rk_warnerr(int doerrno
, const char *fmt
, va_list ap
)
418 __attribute__ ((format (printf
, 2, 0)));
420 void * ROKEN_LIB_FUNCTION
421 rk_realloc(void *, size_t);
425 char * ROKEN_LIB_FUNCTION
426 rk_strpoolcollect(struct rk_strpool
*);
428 struct rk_strpool
* ROKEN_LIB_FUNCTION
429 rk_strpoolprintf(struct rk_strpool
*, const char *, ...)
430 __attribute__ ((format (printf
, 2, 3)));
432 void ROKEN_LIB_FUNCTION
433 rk_strpoolfree(struct rk_strpool
*);
435 void ROKEN_LIB_FUNCTION
436 rk_dumpdata (const char *, const void *, size_t);
438 int ROKEN_LIB_FUNCTION
439 rk_undumpdata (const char *, void **, size_t *);
441 void ROKEN_LIB_FUNCTION
444 void ROKEN_LIB_FUNCTION
447 void ROKEN_LIB_FUNCTION
448 rk_cloexec_file(FILE *);
453 #endif /* __ROKEN_COMMON_H__ */