roken-common.h revision 72445
1/*
2 * Copyright (c) 1995 - 2001 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.42 2001/01/29 02:09:09 assar 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
195#define AI_PASSIVE	0x01
196#define AI_CANONNAME	0x02
197#define AI_NUMERICHOST	0x04
198
199#endif /* AI_PASSIVE */
200
201/* flags for getnameinfo() */
202
203#ifndef NI_DGRAM
204#define NI_DGRAM	0x01
205#define NI_NAMEREQD	0x02
206#define NI_NOFQDN	0x04
207#define NI_NUMERICHOST	0x08
208#define NI_NUMERICSERV	0x10
209#endif
210
211/*
212 * constants for getnameinfo
213 */
214
215#ifndef NI_MAXHOST
216#define NI_MAXHOST  1025
217#define NI_MAXSERV    32
218#endif
219
220/*
221 * constants for inet_ntop
222 */
223
224#ifndef INET_ADDRSTRLEN
225#define INET_ADDRSTRLEN    16
226#endif
227
228#ifndef INET6_ADDRSTRLEN
229#define INET6_ADDRSTRLEN   46
230#endif
231
232/*
233 * for shutdown(2)
234 */
235
236#ifndef SHUT_RD
237#define SHUT_RD 0
238#endif
239
240#ifndef SHUT_WR
241#define SHUT_WR 1
242#endif
243
244#ifndef SHUT_RDWR
245#define SHUT_RDWR 2
246#endif
247
248#ifndef HAVE___ATTRIBUTE__
249#define __attribute__(x)
250#endif
251
252ROKEN_CPP_START
253
254#if IRIX != 4 /* fix for compiler bug */
255#ifdef RETSIGTYPE
256typedef RETSIGTYPE (*SigAction)(int);
257SigAction signal(int iSig, SigAction pAction); /* BSD compatible */
258#endif
259#endif
260
261int ROKEN_LIB_FUNCTION simple_execve(const char*, char*const[], char*const[]);
262int ROKEN_LIB_FUNCTION simple_execvp(const char*, char *const[]);
263int ROKEN_LIB_FUNCTION simple_execlp(const char*, ...);
264int ROKEN_LIB_FUNCTION simple_execle(const char*, ...);
265int ROKEN_LIB_FUNCTION simple_execl(const char *file, ...);
266
267void ROKEN_LIB_FUNCTION print_version(const char *);
268
269void *ROKEN_LIB_FUNCTION emalloc (size_t);
270void *ROKEN_LIB_FUNCTION erealloc (void *, size_t);
271char *ROKEN_LIB_FUNCTION estrdup (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
276void
277esetenv(const char *var, const char *val, int rewrite);
278
279void
280socket_set_address_and_port (struct sockaddr *sa, const void *ptr, int port);
281
282size_t
283socket_addr_size (const struct sockaddr *sa);
284
285void
286socket_set_any (struct sockaddr *sa, int af);
287
288size_t
289socket_sockaddr_size (const struct sockaddr *sa);
290
291void *
292socket_get_address (struct sockaddr *sa);
293
294int
295socket_get_port (const struct sockaddr *sa);
296
297void
298socket_set_port (struct sockaddr *sa, int port);
299
300void
301socket_set_debug (int sock);
302
303void
304socket_set_tos (int sock, int tos);
305
306void
307socket_set_reuseaddr (int sock, int val);
308
309char **
310vstrcollect(va_list *ap);
311
312char **
313strcollect(char *first, ...);
314
315void timevalfix(struct timeval *t1);
316void timevaladd(struct timeval *t1, const struct timeval *t2);
317void timevalsub(struct timeval *t1, const struct timeval *t2);
318
319char *pid_file_write (const char *progname);
320void pid_file_delete (char **);
321
322int
323read_environment(const char *file, char ***env);
324
325void warnerr(int doerrno, const char *fmt, va_list ap)
326    __attribute__ ((format (printf, 2, 0)));
327
328ROKEN_CPP_END
329
330#endif /* __ROKEN_COMMON_H__ */
331