* Fix some compiler warnings for bad casting in some functions in the file
[alpine.git] / include / system.h
blobef84c60c3ecfa0ceea2e5397bf30d02457a3740e
1 /*----------------------------------------------------------------------
2 $Id: system.h 776 2007-10-24 23:14:26Z hubert@u.washington.edu $
3 ----------------------------------------------------------------------*/
5 /* ========================================================================
6 * Copyright 2006-2007 University of Washington
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * ========================================================================
18 * System-Specific includes, macros and prototypes based on config.h definitions
22 #ifndef _SYSTEM_INCLUDED
23 #define _SYSTEM_INCLUDED
25 #ifndef _WINDOWS
26 #include "config.h"
27 #else
28 #include "config.wnt.h"
29 #endif
31 #include <stdio.h>
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
37 #ifdef HAVE_CTYPE_H
38 # include <ctype.h>
39 #endif
41 #ifdef STDC_HEADERS
42 # include <stdlib.h>
44 # if HAVE_STRING_H
45 # include <string.h>
46 # endif
48 # if HAVE_STRINGS_H
49 # include <strings.h>
50 # endif
52 # if HAVE_WCHAR_H
53 # include <wchar.h>
54 # endif
56 # include <stdarg.h>
58 #else
59 void *malloc (size_t);
60 void *realloc (void *, size_t);
61 void free (void *);
62 size_t strlen (const char *);
63 int strcmp (const char *, const char *);
64 char *strcpy (char *, const char *);
65 char *strcat (char *, const char *);
66 char *strtok (char *, const char *);
67 # ifndef HAVE_STRCHR
68 # warn "No strchr(); trying to use index() instead."
69 # define strchr index
70 # define strrchr rindex
71 # endif
72 # ifndef HAVE_STRDUP
73 # error "C library missing strdup()!"
74 # endif
75 char *strdup (const char *);
76 char *strstr (const char *, const char *);
77 # ifdef HAVE_MEMORY_H
78 # include <memory.h>
79 # else
80 # ifdef HAVE_MEMCPY
81 void *memcpy(void *, const void *, size_t);
82 void *memmove(void *, const void *, size_t);
83 void *memset(void *, int, size_t);
84 # else
85 # define memcpy(d, s, n) bcopy ((s), (d), (n))
86 # define memmove(d, s, n) bcopy ((s), (d), (n))
87 # define memset(d, c, n) bzero ((d), (n))
88 # endif
89 # endif
90 #endif
92 /* Set System Collator */
93 #if HAVE_STRCOLL
94 # define collator strcoll
95 #else
96 # define collator strucmp
97 #endif
99 #if defined(CODESET) && !defined(_WINDOWS)
100 #define PREREQ_FOR_SYS_TRANSLATION (HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_WCWIDTH && HAVE_MBSTOWCS && HAVE_LANGINFO_H)
101 #else
102 #define PREREQ_FOR_SYS_TRANSLATION (0)
103 #endif
105 /* System uin32 definition */
106 #if HAVE_STDINT_H
107 # include <stdint.h>
108 #endif
110 #if HAVE_INTTYPES_H
111 # include <inttypes.h>
112 #endif
114 #if HAVE_SYS_TYPES_H
115 # include <sys/types.h>
116 #endif
118 #if HAVE_SYS_WAIT_H
119 # include <sys/wait.h>
120 #endif
122 /* set MAXPATH based on what's available */
124 #if HAVE_LIMITS_H
125 # include <limits.h>
126 #endif
128 #ifdef PATH_MAX
129 # define MAXPATH PATH_MAX
130 #else
131 # if HAVE_SYS_PARAM_H
132 # include <sys/param.h>
133 # endif
134 # if MAXPATHLEN
135 # define MAXPATH MAXPATHLEN
136 # else
137 # define MAXPATH (512)
138 # endif
139 #endif
141 #if TIME_WITH_SYS_TIME
142 # include <sys/time.h>
143 # include <time.h>
144 #else
145 # if HAVE_SYS_TIME_H
146 # include <sys/time.h>
147 # else
148 # include <time.h>
149 # endif
150 #endif
152 #if HAVE_UTIME_H
153 # include <utime.h>
154 #elif HAVE_SYS_UTIME_H
155 # include <sys/utime.h>
156 #endif
158 #if HAVE_ERRNO_H
159 #include <errno.h>
160 #endif
162 #if HAVE_SYS_STAT_H
163 #include <sys/stat.h>
164 #endif
166 #if HAVE_FCNTL_H
167 #include <fcntl.h>
168 #endif
170 #if defined(O_NONBLOCK)
171 # define NON_BLOCKING_IO O_NONBLOCK
172 #elif defined(FNDELAY)
173 # define NON_BLOCKING_IO FNDELAY
174 #endif
176 #if HAVE_PWD_H
177 # include <pwd.h>
178 #endif
180 #if HAVE_SIGNAL_H
181 # include <signal.h>
182 #endif
184 #if HAVE_SETJMP_H
185 # include <setjmp.h>
186 #endif
188 #if HAS_TERMIOS
189 # include <termios.h>
190 #endif
192 #if HAS_TERMIO
193 # include <termio.h>
194 #endif
196 #if HAS_SGTTY
197 # include <sgtty.h>
198 #endif
200 #if HAVE_NETDB_H
201 # include <netdb.h>
202 #endif
204 #if defined(GWINSZ_IN_SYS_IOCTL) || defined(HAVE_SYS_IOCTL_H)
205 # include <sys/ioctl.h>
206 #endif
208 #if HAVE_SYS_SOCKET_H
209 #include <sys/socket.h>
210 #endif
212 #if HAVE_SYS_UIO_H
213 #include <sys/uio.h>
214 #endif
216 #if HAVE_SYS_UN_H
217 #include <sys/un.h>
218 #else
219 struct sockaddr_un {
220 short sun_family; /* AF_UNIX */
221 char sun_path[108]; /* path name (gag) */
223 #endif
225 #if HAVE_PTHREAD_H
226 # include <pthread.h>
227 #endif
229 #if HAVE_ASSERT_H
230 # include <assert.h>
231 #endif
233 #if HAVE_LOCALE_H
234 # include <locale.h>
235 #endif
237 #if HAVE_LANGINFO_H
238 # include <langinfo.h>
239 #endif
241 #if HAVE_REGEX_H
242 # include <regex.h>
243 #endif
245 #ifdef ENABLE_NLS
247 # include <libintl.h>
249 # define _(String) gettext (String)
250 # define N_(String) String
252 #else /* !ENABLE_NLS */
254 # define _(String) String
255 # define N_(String) String
257 #endif /* !ENABLE_NLS */
260 #ifdef ENABLE_LDAP
262 # include <lber.h>
263 # include <ldap.h>
265 # ifndef LDAPAPI
266 # if defined(LDAP_API_VERSION) /* draft-ietf-ldapext-ldap-c-api-04 */
267 # define LDAPAPI LDAP_API_VERSION
268 # elif defined(LDAP_OPT_SIZELIMIT)
269 # define LDAPAPI 15 /* Netscape SDK */
270 # elif defined(LDAP_BEGIN_DECL)
271 # define LDAPAPI 11 /* OpenLDAP 1.x */
272 # else /* older version */
273 # define LDAPAPI 10 /* Umich */
274 # endif
276 # ifndef LDAP_OPT_ON
277 # define LDAP_OPT_ON ((void *)1)
278 # endif
279 # ifndef LDAP_OPT_OFF
280 # define LDAP_OPT_OFF ((void *)0)
281 # endif
282 # ifndef LDAP_OPT_SIZELIMIT
283 # define LDAP_OPT_SIZELIMIT 1134 /* we're hacking now! */
284 # endif
285 # ifndef LDAP_OPT_TIMELIMIT
286 # define LDAP_OPT_TIMELIMIT 1135
287 # endif
288 # ifndef LDAP_OPT_PROTOCOL_VERSION
289 # define LDAP_OPT_PROTOCOL_VERSION 1136
290 # endif
292 # ifndef LDAP_MSG_ONE
293 # define LDAP_MSG_ONE (0x00)
294 # define LDAP_MSG_ALL (0x01)
295 # define LDAP_MSG_RECEIVED (0x02)
296 # endif
297 # endif
298 #endif /* ENABLE_LDAP */
301 #if defined(DOS) || defined(OS2)
302 # define NEWLINE "\r\n" /* local EOL convention... */
303 #else
304 # define NEWLINE "\n" /* necessary for gf_* funcs */
305 #endif
307 #if OSX_TARGET
308 # include <Carbon/Carbon.h>
309 # include <ApplicationServices/ApplicationServices.h>
311 /* Avoid OSX Conflicts */
312 #define Fixed PineFixed
313 #define Handle PineHandle
314 #define Comment PineComment
315 #define normal PineNormal
316 #endif
318 #if HAVE_SYSLOG_H
319 # include <syslog.h>
320 #elif HAVE_SYS_SYSLOG_H
321 # include <sys/syslog.h>
322 #endif
324 #ifdef ENABLE_DMALLOC
325 # include <dmalloc.h>
326 #endif
328 #ifdef _WINDOWS
331 * Defining these turns generic data types and function calls
332 * into their unicode (wide) versions. Not defining it will
333 * break the code, so leave it defined.
335 #ifndef _UNICODE
336 # define _UNICODE
337 #endif
338 #ifndef UNICODE
339 # define UNICODE
340 #endif
342 #define _WIN32_WINNT WINVER
344 /*-------- Standard windows defines and then our window module defines. */
345 #include <dos.h>
346 #include <direct.h>
347 #include <search.h>
348 #undef CTRL
349 #include <io.h>
350 #include <windows.h>
351 #include <commdlg.h>
352 #include <cderr.h>
353 #include <winsock.h>
354 #include <shellapi.h>
355 #include <sys/timeb.h>
356 #include <tchar.h>
357 #include <wchar.h>
358 #include <assert.h>
360 #if defined(WINVER) && WINVER >= 0x0501
361 # define WINCRED 1 /* WINCRED will work */
362 #else
363 # define WINCRED 0 /* too old for WINCRED to work */
364 #endif
366 #undef ERROR
368 typedef int mode_t;
369 typedef int uid_t;
370 typedef int gid_t;
372 #undef snprintf
373 #define snprintf _snprintf
374 #undef CM_NONE
376 #undef utimbuf
377 #define utimbuf _utimbuf
379 #endif /* _WINDOWS */
382 #if defined(PASSFILE) && defined(APPLEKEYCHAIN)
383 # error "Cannot define both PASSFILE and APPLEKEYCHAIN"
384 #endif
385 #if defined(PASSFILE) && defined(WINCRED)
386 # error "Cannot define both PASSFILE and WINCRED"
387 #endif
388 #if defined(APPLEKEYCHAIN) && defined(WINCRED)
389 # error "Cannot define both APPLEKEYCHAIN and WINCRED"
390 #endif
392 #if defined(PASSFILE) || defined(APPLEKEYCHAIN) || defined(WINCRED)
393 # define LOCAL_PASSWD_CACHE
394 #endif
396 #endif /* _SYSTEM_INCLUDED */