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$ */
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
42#define ROKEN_LIB_CALL     __cdecl
43#else
44#define ROKEN_LIB_FUNCTION
45#define ROKEN_LIB_CALL
46#endif
47#endif
48
49#ifdef __cplusplus
50#define ROKEN_CPP_START	extern "C" {
51#define ROKEN_CPP_END	}
52#else
53#define ROKEN_CPP_START
54#define ROKEN_CPP_END
55#endif
56
57#ifndef INADDR_NONE
58#define INADDR_NONE 0xffffffff
59#endif
60
61#ifndef INADDR_LOOPBACK
62#define INADDR_LOOPBACK 0x7f000001
63#endif
64
65#ifndef SOMAXCONN
66#define SOMAXCONN 5
67#endif
68
69#ifndef STDIN_FILENO
70#define STDIN_FILENO 0
71#endif
72
73#ifndef STDOUT_FILENO
74#define STDOUT_FILENO 1
75#endif
76
77#ifndef STDERR_FILENO
78#define STDERR_FILENO 2
79#endif
80
81#ifndef max
82#define max(a,b) (((a)>(b))?(a):(b))
83#endif
84
85#ifndef min
86#define min(a,b) (((a)<(b))?(a):(b))
87#endif
88
89#ifndef TRUE
90#define TRUE 1
91#endif
92
93#ifndef FALSE
94#define FALSE 0
95#endif
96
97#ifndef LOG_DAEMON
98#define openlog(id,option,facility) openlog((id),(option))
99#define	LOG_DAEMON	0
100#endif
101#ifndef LOG_ODELAY
102#define LOG_ODELAY 0
103#endif
104#ifndef LOG_NDELAY
105#define LOG_NDELAY 0x08
106#endif
107#ifndef LOG_CONS
108#define LOG_CONS 0
109#endif
110#ifndef LOG_AUTH
111#define LOG_AUTH 0
112#endif
113#ifndef LOG_AUTHPRIV
114#define LOG_AUTHPRIV LOG_AUTH
115#endif
116
117#ifndef F_OK
118#define F_OK 0
119#endif
120
121#ifndef O_ACCMODE
122#define O_ACCMODE	003
123#endif
124
125#ifndef _WIN32
126
127#ifndef _PATH_DEV
128#define _PATH_DEV "/dev/"
129#endif
130
131#ifndef _PATH_DEVNULL
132#define _PATH_DEVNULL "/dev/null"
133#endif
134
135#ifndef _PATH_HEQUIV
136#define _PATH_HEQUIV "/etc/hosts.equiv"
137#endif
138
139#ifndef _PATH_VARRUN
140#define _PATH_VARRUN "/var/run/"
141#endif
142
143#ifndef _PATH_BSHELL
144#define _PATH_BSHELL "/bin/sh"
145#endif
146
147#ifndef MAXPATHLEN
148#define MAXPATHLEN (1024+4)
149#endif
150
151#endif	/* !_WIN32 */
152
153#ifndef PATH_MAX
154#define PATH_MAX MAX_PATH
155#endif
156
157#ifndef RETSIGTYPE
158#define RETSIGTYPE void
159#endif
160
161#ifndef SIG_ERR
162#define SIG_ERR ((RETSIGTYPE (*)(int))-1)
163#endif
164
165/*
166 * error code for getipnodeby{name,addr}
167 */
168
169#ifndef HOST_NOT_FOUND
170#define HOST_NOT_FOUND 1
171#endif
172
173#ifndef TRY_AGAIN
174#define TRY_AGAIN 2
175#endif
176
177#ifndef NO_RECOVERY
178#define NO_RECOVERY 3
179#endif
180
181#ifndef NO_DATA
182#define NO_DATA 4
183#endif
184
185#ifndef NO_ADDRESS
186#define NO_ADDRESS NO_DATA
187#endif
188
189/*
190 * error code for getaddrinfo
191 */
192
193#ifndef EAI_NOERROR
194#define EAI_NOERROR	0	/* no error */
195#endif
196
197#ifndef EAI_NONAME
198
199#define EAI_ADDRFAMILY	1	/* address family for nodename not supported */
200#define EAI_AGAIN	2	/* temporary failure in name resolution */
201#define EAI_BADFLAGS	3	/* invalid value for ai_flags */
202#define EAI_FAIL	4	/* non-recoverable failure in name resolution */
203#define EAI_FAMILY	5	/* ai_family not supported */
204#define EAI_MEMORY	6	/* memory allocation failure */
205#define EAI_NODATA	7	/* no address associated with nodename */
206#define EAI_NONAME	8	/* nodename nor servname provided, or not known */
207#define EAI_SERVICE	9	/* servname not supported for ai_socktype */
208#define EAI_SOCKTYPE   10	/* ai_socktype not supported */
209#define EAI_SYSTEM     11	/* system error returned in errno */
210
211#endif /* EAI_NONAME */
212
213/* flags for getaddrinfo() */
214
215#ifndef AI_PASSIVE
216#define AI_PASSIVE	0x01
217#define AI_CANONNAME	0x02
218#endif /* AI_PASSIVE */
219
220#ifndef AI_NUMERICHOST
221#define AI_NUMERICHOST	0x04
222#endif
223
224#ifndef AI_NUMERICSERV
225#define AI_NUMERICSERV  0x08
226#endif
227
228/* flags for getnameinfo() */
229
230#ifndef NI_DGRAM
231#define NI_DGRAM	0x01
232#define NI_NAMEREQD	0x02
233#define NI_NOFQDN	0x04
234#define NI_NUMERICHOST	0x08
235#define NI_NUMERICSERV	0x10
236#endif
237
238/*
239 * constants for getnameinfo
240 */
241
242#ifndef NI_MAXHOST
243#define NI_MAXHOST  1025
244#define NI_MAXSERV    32
245#endif
246
247/*
248 * constants for inet_ntop
249 */
250
251#ifndef INET_ADDRSTRLEN
252#define INET_ADDRSTRLEN    16
253#endif
254
255#ifndef INET6_ADDRSTRLEN
256#define INET6_ADDRSTRLEN   46
257#endif
258
259/*
260 * for shutdown(2)
261 */
262
263#ifndef SHUT_RD
264#define SHUT_RD 0
265#endif
266
267#ifndef SHUT_WR
268#define SHUT_WR 1
269#endif
270
271#ifndef SHUT_RDWR
272#define SHUT_RDWR 2
273#endif
274
275ROKEN_CPP_START
276
277#ifndef IRIX4 /* fix for compiler bug */
278#ifndef _WIN32
279#ifdef RETSIGTYPE
280typedef RETSIGTYPE (*SigAction)(int);
281SigAction signal(int iSig, SigAction pAction); /* BSD compatible */
282#endif
283#endif
284#endif
285
286#define SE_E_UNSPECIFIED (-1)
287#define SE_E_FORKFAILED  (-2)
288#define SE_E_WAITPIDFAILED (-3)
289#define SE_E_EXECTIMEOUT (-4)
290#define SE_E_NOEXEC   126
291#define SE_E_NOTFOUND 127
292
293#define SE_PROCSTATUS(st) (((st) >= 0 && (st) < 126)? st: -1)
294#define SE_PROCSIGNAL(st) (((st) >= 128)? (st) - 128: -1)
295#define SE_IS_ERROR(st) ((st) < 0 || (st) >= 126)
296
297
298#define simple_execve rk_simple_execve
299ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
300simple_execve(const char*, char*const[], char*const[]);
301
302#define simple_execve_timed rk_simple_execve_timed
303ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
304simple_execve_timed(const char *, char *const[],
305		    char *const [], time_t (*)(void *),
306		    void *, time_t);
307
308#define simple_execvp rk_simple_execvp
309ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
310simple_execvp(const char*, char *const[]);
311
312#define simple_execvp_timed rk_simple_execvp_timed
313ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
314simple_execvp_timed(const char *, char *const[],
315		    time_t (*)(void *), void *, time_t);
316
317#define simple_execlp rk_simple_execlp
318ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
319simple_execlp(const char*, ...);
320
321#define simple_execle rk_simple_execle
322ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
323simple_execle(const char*, ...);
324
325#define wait_for_process rk_wait_for_process
326ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
327wait_for_process(pid_t);
328
329#define wait_for_process_timed rk_wait_for_process_timed
330ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
331wait_for_process_timed(pid_t, time_t (*)(void *),
332		       void *, time_t);
333
334#define pipe_execv rk_pipe_execv
335ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
336pipe_execv(FILE**, FILE**, FILE**, const char*, ...);
337
338#define print_version rk_print_version
339ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
340print_version(const char *);
341
342#define eread rk_eread
343ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
344eread (int fd, void *buf, size_t nbytes);
345
346#define ewrite rk_ewrite
347ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
348ewrite (int fd, const void *buf, size_t nbytes);
349
350struct hostent;
351
352#define hostent_find_fqdn rk_hostent_find_fqdn
353ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
354hostent_find_fqdn (const struct hostent *);
355
356#define esetenv rk_esetenv
357ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
358esetenv(const char *, const char *, int);
359
360#define socket_set_address_and_port rk_socket_set_address_and_port
361ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
362socket_set_address_and_port (struct sockaddr *, const void *, int);
363
364#define socket_addr_size rk_socket_addr_size
365ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
366socket_addr_size (const struct sockaddr *);
367
368#define socket_set_any rk_socket_set_any
369ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
370socket_set_any (struct sockaddr *, int);
371
372#define socket_sockaddr_size rk_socket_sockaddr_size
373ROKEN_LIB_FUNCTION socklen_t ROKEN_LIB_CALL
374socket_sockaddr_size (const struct sockaddr *);
375
376#define socket_get_address rk_socket_get_address
377ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
378socket_get_address (const struct sockaddr *);
379
380#define socket_get_port rk_socket_get_port
381ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
382socket_get_port (const struct sockaddr *);
383
384#define socket_set_port rk_socket_set_port
385ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
386socket_set_port (struct sockaddr *, int);
387
388#define socket_set_portrange rk_socket_set_portrange
389ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
390socket_set_portrange (rk_socket_t, int, int);
391
392#define socket_set_debug rk_socket_set_debug
393ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
394socket_set_debug (rk_socket_t);
395
396#define socket_set_tos rk_socket_set_tos
397ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
398socket_set_tos (rk_socket_t, int);
399
400#define socket_set_nonblocking rk_socket_set_nonblocking
401ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
402socket_set_nonblocking (rk_socket_t sock, int nonblock);
403
404#define socket_set_nopipe rk_socket_set_nopipe
405ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
406socket_set_nopipe(rk_socket_t sock, int nopipe);
407
408#define socket_set_reuseaddr rk_socket_set_reuseaddr
409ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
410socket_set_reuseaddr (rk_socket_t, int);
411
412#define socket_set_ipv6only rk_socket_set_ipv6only
413ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
414socket_set_ipv6only (rk_socket_t, int);
415
416#define socket_to_fd rk_socket_to_fd
417ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
418socket_to_fd(rk_socket_t, int);
419
420#define vstrcollect rk_vstrcollect
421ROKEN_LIB_FUNCTION char ** ROKEN_LIB_CALL
422vstrcollect(va_list *ap);
423
424#define strcollect rk_strcollect
425ROKEN_LIB_FUNCTION char ** ROKEN_LIB_CALL
426strcollect(char *first, ...);
427
428#define timevalfix rk_timevalfix
429ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
430timevalfix(struct timeval *t1);
431
432#define timevaladd rk_timevaladd
433ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
434timevaladd(struct timeval *t1, const struct timeval *t2);
435
436#define timevalsub rk_timevalsub
437ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
438timevalsub(struct timeval *t1, const struct timeval *t2);
439
440#define pid_file_write rk_pid_file_write
441ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
442pid_file_write (const char *progname);
443
444#define pid_file_delete rk_pid_file_delete
445ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
446pid_file_delete (char **);
447
448#define read_environment rk_read_environment
449ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
450read_environment(const char *file, char ***env);
451
452#define free_environment rk_free_environment
453ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
454free_environment(char **);
455
456#define warnerr rk_warnerr
457ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
458rk_warnerr(int doerrno, const char *fmt, va_list ap)
459    __attribute__ ((format (printf, 2, 0)));
460
461ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
462rk_realloc(void *, size_t);
463
464struct rk_strpool;
465
466ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
467rk_strpoolcollect(struct rk_strpool *);
468
469ROKEN_LIB_FUNCTION struct rk_strpool * ROKEN_LIB_CALL
470rk_strpoolprintf(struct rk_strpool *, const char *, ...)
471    __attribute__ ((format (printf, 2, 3)));
472
473ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
474rk_strpoolfree(struct rk_strpool *);
475
476ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
477rk_dumpdata (const char *, const void *, size_t);
478
479ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
480rk_undumpdata (const char *, void **, size_t *);
481
482ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
483rk_xfree (void *);
484
485ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
486rk_cloexec(int);
487
488ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
489rk_cloexec_file(FILE *);
490
491ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
492rk_cloexec_dir(DIR *);
493
494ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
495ct_memcmp(const void *, const void *, size_t);
496
497ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
498rk_random_init(void);
499
500ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
501rk_get_window_size(int fd, int *, int *);
502
503
504#ifdef __APPLE__
505
506#include <CoreFoundation/CoreFoundation.h>
507
508char * ROKEN_LIB_FUNCTION
509rk_cfstring2cstring(CFStringRef);
510#endif
511
512ROKEN_CPP_END
513
514#endif /* __ROKEN_COMMON_H__ */
515