1 /* $Id: clibrary.h 6704 2004-05-16 19:46:20Z rra $
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
7 ** #include <sys/types.h>
10 ** #include <stdlib.h>
11 ** #include <stddef.h>
12 ** #include <stdint.h>
13 ** #include <string.h>
14 ** #include <unistd.h>
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.
24 /* Make sure we have our configuration information. */
27 /* Assume stdarg is available; don't bother with varargs support any more.
28 We need this to be able to declare vsnprintf. */
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. */
37 #include <sys/types.h>
47 # define strrchr rindex
50 # define memcpy(d, s, n) bcopy((s), (d), (n))
54 # if !STDC_HEADERS && HAVE_MEMORY_H
65 # include <inttypes.h>
74 /* SCO OpenServer gets int32_t from here. */
75 #if HAVE_SYS_BITYPES_H
76 # include <sys/bitypes.h>
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. */
85 extern int fseeko(FILE *, off_t, int);
88 extern off_t ftello(FILE *);
91 extern const char * hstrerror(int);
94 extern int mkstemp(char *);
97 extern ssize_t pread(int, void *, size_t, off_t);
100 extern ssize_t pwrite(int, const void *, size_t, off_t);
103 extern int setenv(const char *, const char *, int);
106 extern int seteuid(uid_t);
108 #if NEED_DECLARATION_SNPRINTF
109 extern int snprintf(char *, size_t, const char *, ...)
110 __attribute__((__format__(printf, 3, 4)));
113 extern const char * strerror(int);
116 extern size_t strlcat(char *, const char *, size_t);
119 extern size_t strlcpy(char *, const char *, size_t);
121 #if NEED_DECLARATION_VSNPRINTF
122 extern int vsnprintf(char *, size_t, const char *, va_list);
127 /* "Good enough" replacements for standard functions. */
129 # define atexit(arg) on_exit((arg), 0)
132 # define strtoul(a, b, c) (unsigned long) strtol((a), (b), (c))
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. */
144 /* POSIX requires that these be defined in <unistd.h>. If one of them has
145 been defined, all the rest almost certainly have. */
147 # define STDIN_FILENO 0
148 # define STDOUT_FILENO 1
149 # define STDERR_FILENO 2
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. */
158 # define CTYPE(isXXXXX, c) (isXXXXX((unsigned char)(c)))
160 # define CTYPE(isXXXXX, c) \
161 (isascii((unsigned char)(c)) && isXXXXX((unsigned char)(c)))
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. */
170 # define SUN_LEN(sun) \
171 (sizeof(*(sun)) - sizeof((sun)->sun_path) + strlen((sun)->sun_path))
174 /* Used to name the elements of the array passed to pipe(). */
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)])
186 #endif /* !CLIBRARY_H */