chiark / gitweb /
update debian version
[inn-innduct.git] / include / clibrary.h
1 /*  $Id: clibrary.h 6704 2004-05-16 19:46:20Z rra $
2 **
3 **  Here be declarations of routines and variables in the C library.
4 **  Including this file is the equivalent of including all of the following
5 **  headers, portably:
6 **
7 **      #include <sys/types.h>
8 **      #include <stdarg.h>
9 **      #include <stdio.h>
10 **      #include <stdlib.h>
11 **      #include <stddef.h>
12 **      #include <stdint.h>
13 **      #include <string.h>
14 **      #include <unistd.h>
15 **
16 **  Missing functions are provided via #define or prototyped if we'll be
17 **  adding them to INN's library.  If the system doesn't define a SUN_LEN
18 **  macro, one will be provided.  Also provides some standard #defines.
19 */
20
21 #ifndef CLIBRARY_H
22 #define CLIBRARY_H 1
23
24 /* Make sure we have our configuration information. */
25 #include "config.h"
26
27 /* Assume stdarg is available; don't bother with varargs support any more.
28    We need this to be able to declare vsnprintf. */
29 #include <stdarg.h>
30
31 /* This is the same method used by autoconf as of 2000-07-29 for including
32    the basic system headers with the addition of handling of strchr,
33    strrchr, and memcpy.  Note that we don't attempt to declare any of the
34    functions; the number of systems left without ANSI-compatible function
35    prototypes isn't high enough to be worth the trouble.  */
36 #include <stdio.h>
37 #include <sys/types.h>
38 #if STDC_HEADERS
39 # include <stdlib.h>
40 # include <stddef.h>
41 #else
42 # if HAVE_STDLIB_H
43 #  include <stdlib.h>
44 # endif
45 # if !HAVE_STRCHR
46 #  define strchr index
47 #  define strrchr rindex
48 # endif
49 # if !HAVE_MEMCPY
50 #  define memcpy(d, s, n)  bcopy((s), (d), (n))
51 # endif
52 #endif
53 #if HAVE_STRING_H
54 # if !STDC_HEADERS && HAVE_MEMORY_H
55 #  include <memory.h>
56 # endif
57 # include <string.h>
58 #else
59 # if HAVE_STRINGS_H
60 #  include <strings.h>
61 # endif
62 #endif
63
64 #if HAVE_INTTYPES_H
65 # include <inttypes.h>
66 #endif
67 #if HAVE_STDINT_H
68 # include <stdint.h>
69 #endif
70 #if HAVE_UNISTD_H
71 # include <unistd.h>
72 #endif
73
74 /* SCO OpenServer gets int32_t from here. */
75 #if HAVE_SYS_BITYPES_H
76 # include <sys/bitypes.h>
77 #endif
78
79 BEGIN_DECLS
80
81 /* Provide prototypes for functions not declared in system headers.  Use the
82    NEED_DECLARATION macros for those functions that may be prototyped but
83    implemented incorrectly. */
84 #if !HAVE_FSEEKO
85 extern int              fseeko(FILE *, off_t, int);
86 #endif
87 #if !HAVE_FTELLO
88 extern off_t            ftello(FILE *);
89 #endif
90 #if !HAVE_HSTRERROR
91 extern const char *     hstrerror(int);
92 #endif
93 #if !HAVE_MKSTEMP
94 extern int              mkstemp(char *);
95 #endif
96 #if !HAVE_PREAD
97 extern ssize_t          pread(int, void *, size_t, off_t);
98 #endif
99 #if !HAVE_PWRITE
100 extern ssize_t          pwrite(int, const void *, size_t, off_t);
101 #endif
102 #if !HAVE_SETENV
103 extern int              setenv(const char *, const char *, int);
104 #endif
105 #if !HAVE_SETEUID
106 extern int              seteuid(uid_t);
107 #endif
108 #if NEED_DECLARATION_SNPRINTF
109 extern int              snprintf(char *, size_t, const char *, ...)
110     __attribute__((__format__(printf, 3, 4)));
111 #endif
112 #if !HAVE_STRERROR
113 extern const char *     strerror(int);
114 #endif
115 #if !HAVE_STRLCAT
116 extern size_t           strlcat(char *, const char *, size_t);
117 #endif
118 #if !HAVE_STRLCPY
119 extern size_t           strlcpy(char *, const char *, size_t);
120 #endif
121 #if NEED_DECLARATION_VSNPRINTF
122 extern int              vsnprintf(char *, size_t, const char *, va_list);
123 #endif
124
125 END_DECLS
126
127 /* "Good enough" replacements for standard functions. */
128 #if !HAVE_ATEXIT
129 # define atexit(arg) on_exit((arg), 0)
130 #endif
131 #if !HAVE_STRTOUL
132 # define strtoul(a, b, c) (unsigned long) strtol((a), (b), (c))
133 #endif
134
135 /* This almost certainly isn't necessary, but it's not hurting anything.
136    gcc assumes that if SEEK_SET isn't defined none of the rest are either,
137    so we certainly can as well. */
138 #ifndef SEEK_SET
139 # define SEEK_SET 0
140 # define SEEK_CUR 1
141 # define SEEK_END 2
142 #endif
143
144 /* POSIX requires that these be defined in <unistd.h>.  If one of them has
145    been defined, all the rest almost certainly have. */
146 #ifndef STDIN_FILENO
147 # define STDIN_FILENO   0
148 # define STDOUT_FILENO  1
149 # define STDERR_FILENO  2
150 #endif
151
152 /* On some systems, the macros defined by <ctype.h> are only vaild on ASCII
153    characters (those characters that isascii() says are ASCII).  This comes
154    into play when applying <ctype.h> macros to eight-bit data.  autoconf
155    checks for this with as part of AC_HEADER_STDC, so if autoconf doesn't
156    think our headers are standard, check isascii() first. */
157 #if STDC_HEADERS
158 # define CTYPE(isXXXXX, c) (isXXXXX((unsigned char)(c)))
159 #else
160 # define CTYPE(isXXXXX, c) \
161     (isascii((unsigned char)(c)) && isXXXXX((unsigned char)(c)))
162 #endif
163
164 /* POSIX.1g requires <sys/un.h> to define a SUN_LEN macro for determining
165    the real length of a struct sockaddr_un, but it's not available
166    everywhere yet.  If autoconf couldn't find it, define our own.  This
167    definition is from 4.4BSD by way of Stevens, Unix Network Programming
168    (2nd edition), vol. 1, pg. 917. */
169 #if !HAVE_SUN_LEN
170 # define SUN_LEN(sun) \
171     (sizeof(*(sun)) - sizeof((sun)->sun_path) + strlen((sun)->sun_path))
172 #endif
173
174 /* Used to name the elements of the array passed to pipe(). */
175 #define PIPE_READ       0
176 #define PIPE_WRITE      1
177
178 /* Used for iterating through arrays.  ARRAY_SIZE returns the number of
179    elements in the array (useful for a < upper bound in a for loop) and
180    ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
181    legal to refer to such a pointer as long as it's never dereferenced). */
182 #define ARRAY_SIZE(array)       (sizeof(array) / sizeof((array)[0]))
183 #define ARRAY_END(array)        (&(array)[ARRAY_SIZE(array)])
184
185
186 #endif /* !CLIBRARY_H */