fix possible crash on user deletion
[srvx.git] / src / compat.h
1 #ifndef COMPAT_H
2 #define COMPAT_H
3
4 #include "config.h"
5
6 /* AIX's compiler requires this to be the first thing in the compiled
7  * files.  Yay for braindead compilers. */
8 #if defined(__GNUC__) && !defined(HAVE_ALLOCA_H)
9 # define alloca __builtin_alloca
10 #else
11 # if defined(HAVE_ALLOCA_H)
12 #  include <alloca.h>
13 # else
14 #  ifdef _AIX
15 #   pragma alloca
16 #  else
17 #   ifndef alloca
18 char *alloca();
19 #   endif
20 #  endif
21 # endif
22 #endif
23
24 /* These are ANSI C89 headers, so everybody should have them.  If
25  * they're missing, we probably don't care much about the platform.
26  * If we do, we can add an autoconf test and try to patch around;
27  * this is the right file for that, after all :)
28  */
29 #include <assert.h>
30 #include <ctype.h>
31 #include <errno.h>
32 #include <limits.h>
33 #include <setjmp.h>
34 #include <signal.h>
35 #include <stdarg.h>
36 #include <stddef.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40
41 #ifdef TIME_WITH_SYS_TIME
42 # include <sys/time.h>
43 # include <time.h>
44 #else
45 # ifdef HAVE_SYS_TIME_H
46 #  include <sys/time.h>
47 # else
48 #  include <time.h>
49 # endif
50 #endif
51
52 #ifdef HAVE_SYS_TYPES_H
53 #include <sys/types.h>
54 #endif
55
56 #ifdef HAVE_SYS_SOCKET_H
57 #include <sys/socket.h>
58 #endif
59
60 #ifdef HAVE_STDINT_H
61 #include <stdint.h>
62 #endif
63
64 #ifdef HAVE_NETDB_H
65 #include <netdb.h>
66 #endif
67
68 #ifdef HAVE_WINSOCK2_H
69 /* Windows XP+ only -- older versions lack getaddrinfo() etc. */
70 # define _WIN32_WINNT 0x0501
71 # include <winsock2.h>
72 #endif
73
74 #ifdef HAVE_WS2TCPIP_H
75 # include <ws2tcpip.h>
76 #endif
77
78 #ifdef HAVE_UNISTD_H
79 #include <unistd.h>
80 #endif
81
82 /* Cygwin (for example) doesn't define LINE_MAX, although mingw does. */
83 #if !defined(LINE_MAX)
84 # define LINE_MAX 2048
85 #endif
86
87 #ifdef HAVE_VA_COPY
88 #define VA_COPY(DEST, SRC) va_copy(DEST, SRC)
89 #elif HAVE___VA_COPY
90 #define VA_COPY(DEST, SRC) __va_copy(DEST, SRC)
91 #else
92 #define VA_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(DEST))
93 #endif
94
95 #ifndef HAVE_GETTIMEOFDAY
96 struct timezone;
97 extern int gettimeofday(struct timeval * tv, struct timezone * tz);
98 #endif
99
100 #ifndef HAVE_LOCALTIME_R
101 extern struct tm *localtime_r(const time_t *timep, struct tm *result);
102 #endif
103
104 #ifndef HAVE_MEMCPY
105 /* this should use size_t, but some systems don't define it */
106 extern void * memcpy(void * dest, void const * src, unsigned long n);
107 #endif
108
109 #ifndef HAVE_MEMSET
110 /* this should use size_t, but some systems don't define it */
111 extern void * memset(void * dest, int c, unsigned long n);
112 #endif
113
114 #ifndef HAVE_STRDUP
115 extern char * strdup(char const * str);
116 #endif
117
118 #ifndef HAVE_STRERROR
119 extern char const * strerror(int errornum);
120 #endif
121
122 #ifndef HAVE_STRUCT_ADDRINFO
123
124 struct addrinfo {
125     int ai_flags;
126     int ai_family;
127     int ai_socktype;
128     int ai_protocol;
129     size_t ai_addrlen;
130     struct sockaddr *ai_addr;
131     char *ai_canonname;
132     struct addrinfo *ai_next;
133 };
134
135 #define AI_PASSIVE 1
136 #define AI_CANONNAME 2
137 #define AI_NUMERICHOST 4
138
139 #endif /* !defined(HAVE_STRUCT_ADDRINFO) */
140
141 #ifndef HAVE_GETADDRINFO
142 int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
143 void freeaddrinfo(struct addrinfo *res);
144 #endif
145
146 #ifndef HAVE_GAI_STRERROR
147 const char *gai_strerror(int errcode);
148 #endif
149
150 #ifndef EAI_FAMILY
151 # define EAI_FAMILY -1
152 # define EAI_NONAME -2
153 # define EAI_OVERFLOW -3
154 # define EAI_FAIL -4
155 # define EAI_AGAIN -5
156 #endif
157
158 #ifndef HAVE_GETNAMEINFO
159
160 #define NI_NUMERICHOST 1
161
162 int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
163
164 #endif
165
166 #ifndef EINPROGRESS
167 # ifdef WSAEINPROGRESS
168 #  define EINPROGRESS WSAEINPROGRESS
169 #  define EHOSTUNREACH WSAEHOSTUNREACH
170 #  define ECONNREFUSED WSAECONNREFUSED
171 #  define ECONNRESET WSAECONNRESET
172 #  define ETIMEDOUT WSAETIMEDOUT
173 # endif
174 #endif
175
176 #ifndef SIGCHLD
177 # define SIGCHLD SIGCLD
178 #endif
179
180 #endif /* COMPAT_H */