roken-common.h revision 8707f886593c300d83c76654e92ec76bcea9b858
1/*
2 * Copyright (c) 1995 - 2002 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.51 2002/09/09 13:41:12 joda Exp $ */
35
36#ifndef __ROKEN_COMMON_H__
37#define __ROKEN_COMMON_H__
38
39#ifdef __cplusplus
40#define ROKEN_CPP_START	extern "C" {
41#define ROKEN_CPP_END	}
42#else
43#define ROKEN_CPP_START
44#define ROKEN_CPP_END
45#endif
46
47#ifndef INADDR_NONE
48#define INADDR_NONE 0xffffffff
49#endif
50
51#ifndef INADDR_LOOPBACK
52#define INADDR_LOOPBACK 0x7f000001
53#endif
54
55#ifndef SOMAXCONN
56#define SOMAXCONN 5
57#endif
58
59#ifndef STDIN_FILENO
60#define STDIN_FILENO 0
61#endif
62
63#ifndef STDOUT_FILENO
64#define STDOUT_FILENO 1
65#endif
66
67#ifndef STDERR_FILENO
68#define STDERR_FILENO 2
69#endif
70
71#ifndef max
72#define max(a,b) (((a)>(b))?(a):(b))
73#endif
74
75#ifndef min
76#define min(a,b) (((a)<(b))?(a):(b))
77#endif
78
79#ifndef TRUE
80#define TRUE 1
81#endif
82
83#ifndef FALSE
84#define FALSE 0
85#endif
86
87#ifndef LOG_DAEMON
88#define openlog(id,option,facility) openlog((id),(option))
89#define	LOG_DAEMON	0
90#endif
91#ifndef LOG_ODELAY
92#define LOG_ODELAY 0
93#endif
94#ifndef LOG_NDELAY
95#define LOG_NDELAY 0x08
96#endif
97#ifndef LOG_CONS
98#define LOG_CONS 0
99#endif
100#ifndef LOG_AUTH
101#define LOG_AUTH 0
102#endif
103#ifndef LOG_AUTHPRIV
104#define LOG_AUTHPRIV LOG_AUTH
105#endif
106
107#ifndef F_OK
108#define F_OK 0
109#endif
110
111#ifndef O_ACCMODE
112#define O_ACCMODE	003
113#endif
114
115#ifndef _PATH_DEV
116#define _PATH_DEV "/dev/"
117#endif
118
119#ifndef _PATH_DEVNULL
120#define _PATH_DEVNULL "/dev/null"
121#endif
122
123#ifndef _PATH_HEQUIV
124#define _PATH_HEQUIV "/etc/hosts.equiv"
125#endif
126
127#ifndef _PATH_VARRUN
128#define _PATH_VARRUN "/var/run/"
129#endif
130
131#ifndef _PATH_BSHELL
132#define _PATH_BSHELL "/bin/sh"
133#endif
134
135#ifndef MAXPATHLEN
136#define MAXPATHLEN (1024+4)
137#endif
138
139#ifndef SIG_ERR
140#define SIG_ERR ((RETSIGTYPE (*)(int))-1)
141#endif
142
143/*
144 * error code for getipnodeby{name,addr}
145 */
146
147#ifndef HOST_NOT_FOUND
148#define HOST_NOT_FOUND 1
149#endif
150
151#ifndef TRY_AGAIN
152#define TRY_AGAIN 2
153#endif
154
155#ifndef NO_RECOVERY
156#define NO_RECOVERY 3
157#endif
158
159#ifndef NO_DATA
160#define NO_DATA 4
161#endif
162
163#ifndef NO_ADDRESS
164#define NO_ADDRESS NO_DATA
165#endif
166
167/*
168 * error code for getaddrinfo
169 */
170
171#ifndef EAI_NOERROR
172#define EAI_NOERROR	0	/* no error */
173#endif
174
175#ifndef EAI_ADDRFAMILY
176
177#define EAI_ADDRFAMILY	1	/* address family for nodename not supported */
178#define EAI_AGAIN	2	/* temporary failure in name resolution */
179#define EAI_BADFLAGS	3	/* invalid value for ai_flags */
180#define EAI_FAIL	4	/* non-recoverable failure in name resolution */
181#define EAI_FAMILY	5	/* ai_family not supported */
182#define EAI_MEMORY	6	/* memory allocation failure */
183#define EAI_NODATA	7	/* no address associated with nodename */
184#define EAI_NONAME	8	/* nodename nor servname provided, or not known */
185#define EAI_SERVICE	9	/* servname not supported for ai_socktype */
186#define EAI_SOCKTYPE   10	/* ai_socktype not supported */
187#define EAI_SYSTEM     11	/* system error returned in errno */
188
189#endif /* EAI_ADDRFAMILY */
190
191/* flags for getaddrinfo() */
192
193#ifndef AI_PASSIVE
194#define AI_PASSIVE	0x01
195#define AI_CANONNAME	0x02
196#endif /* AI_PASSIVE */
197
198#ifndef AI_NUMERICHOST
199#define AI_NUMERICHOST	0x04
200#endif
201
202/* flags for getnameinfo() */
203
204#ifndef NI_DGRAM
205#define NI_DGRAM	0x01
206#define NI_NAMEREQD	0x02
207#define NI_NOFQDN	0x04
208#define NI_NUMERICHOST	0x08
209#define NI_NUMERICSERV	0x10
210#endif
211
212/*
213 * constants for getnameinfo
214 */
215
216#ifndef NI_MAXHOST
217#define NI_MAXHOST  1025
218#define NI_MAXSERV    32
219#endif
220
221/*
222 * constants for inet_ntop
223 */
224
225#ifndef INET_ADDRSTRLEN
226#define INET_ADDRSTRLEN    16
227#endif
228
229#ifndef INET6_ADDRSTRLEN
230#define INET6_ADDRSTRLEN   46
231#endif
232
233/*
234 * for shutdown(2)
235 */
236
237#ifndef SHUT_RD
238#define SHUT_RD 0
239#endif
240
241#ifndef SHUT_WR
242#define SHUT_WR 1
243#endif
244
245#ifndef SHUT_RDWR
246#define SHUT_RDWR 2
247#endif
248
249#ifndef HAVE___ATTRIBUTE__
250#define __attribute__(x)
251#endif
252
253ROKEN_CPP_START
254
255#ifndef IRIX4 /* fix for compiler bug */
256#ifdef RETSIGTYPE
257typedef RETSIGTYPE (*SigAction)(int);
258SigAction signal(int iSig, SigAction pAction); /* BSD compatible */
259#endif
260#endif
261
262int ROKEN_LIB_FUNCTION simple_execve(const char*, char*const[], char*const[]);
263int ROKEN_LIB_FUNCTION simple_execvp(const char*, char *const[]);
264int ROKEN_LIB_FUNCTION simple_execlp(const char*, ...);
265int ROKEN_LIB_FUNCTION simple_execle(const char*, ...);
266int ROKEN_LIB_FUNCTION simple_execl(const char *file, ...);
267
268int ROKEN_LIB_FUNCTION wait_for_process(pid_t);
269int ROKEN_LIB_FUNCTION pipe_execv(FILE**, FILE**, FILE**, const char*, ...);
270
271void ROKEN_LIB_FUNCTION print_version(const char *);
272
273ssize_t ROKEN_LIB_FUNCTION eread (int fd, void *buf, size_t nbytes);
274ssize_t ROKEN_LIB_FUNCTION ewrite (int fd, const void *buf, size_t nbytes);
275
276struct hostent;
277
278const char *
279hostent_find_fqdn (const struct hostent *he);
280
281void
282esetenv(const char *var, const char *val, int rewrite);
283
284void
285socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port);
286
287size_t
288socket_addr_size (const struct sockaddr *sa);
289
290void
291socket_set_any (struct sockaddr *sa, int af);
292
293size_t
294socket_sockaddr_size (const struct sockaddr *sa);
295
296void *
297socket_get_address (struct sockaddr *sa);
298
299int
300socket_get_port (const struct sockaddr *sa);
301
302void
303socket_set_port (struct sockaddr *sa, int port);
304
305void
306socket_set_portrange (int sock, int restr, int af);
307
308void
309socket_set_debug (int sock);
310
311void
312socket_set_tos (int sock, int tos);
313
314void
315socket_set_reuseaddr (int sock, int val);
316
317char **
318vstrcollect(va_list *ap);
319
320char **
321strcollect(char *first, ...);
322
323void timevalfix(struct timeval *t1);
324void timevaladd(struct timeval *t1, const struct timeval *t2);
325void timevalsub(struct timeval *t1, const struct timeval *t2);
326
327char *pid_file_write (const char *progname);
328void pid_file_delete (char **);
329
330int
331read_environment(const char *file, char ***env);
332
333void warnerr(int doerrno, const char *fmt, va_list ap)
334    __attribute__ ((format (printf, 2, 0)));
335
336ROKEN_CPP_END
337
338#endif /* __ROKEN_COMMON_H__ */
339