Apache Portable Runtime
apr_general.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef APR_GENERAL_H
18 #define APR_GENERAL_H
19 
20 /**
21  * @file apr_general.h
22  * This is collection of oddballs that didn't fit anywhere else,
23  * and might move to more appropriate headers with the release
24  * of APR 1.0.
25  * @brief APR Miscellaneous library routines
26  */
27 
28 #include "apr.h"
29 #include "apr_pools.h"
30 #include "apr_errno.h"
31 
32 #if APR_HAVE_SIGNAL_H
33 #include <signal.h>
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39 
40 /**
41  * @defgroup apr_general Miscellaneous library routines
42  * @ingroup APR
43  * This is collection of oddballs that didn't fit anywhere else,
44  * and might move to more appropriate headers with the release
45  * of APR 1.0.
46  * @{
47  */
48 
49 /** FALSE */
50 #ifndef FALSE
51 #define FALSE 0
52 #endif
53 /** TRUE */
54 #ifndef TRUE
55 #define TRUE (!FALSE)
56 #endif
57 
58 /** a space */
59 #define APR_ASCII_BLANK '\040'
60 /** a carrige return */
61 #define APR_ASCII_CR '\015'
62 /** a line feed */
63 #define APR_ASCII_LF '\012'
64 /** a tab */
65 #define APR_ASCII_TAB '\011'
66 
67 /** signal numbers typedef */
68 typedef int apr_signum_t;
69 
70 /* Type of I/O to wait for */
71 typedef enum { APR_WAIT_READ, APR_WAIT_WRITE } apr_wait_type_t;
72 
73 /**
74  * Finding offsets of elements within structures.
75  * Taken from the X code... they've sweated portability of this stuff
76  * so we don't have to. Sigh...
77  * @param p_type pointer type name
78  * @param field data field within the structure pointed to
79  * @return offset
80  */
81 
82 #if defined(CRAY) || (defined(__arm) && !(defined(LINUX) || defined(__FreeBSD__)))
83 #ifdef __STDC__
84 #define APR_OFFSET(p_type,field) _Offsetof(p_type,field)
85 #else
86 #ifdef CRAY2
87 #define APR_OFFSET(p_type,field) \
88  (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
89 
90 #else /* !CRAY2 */
91 
92 #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
93 
94 #endif /* !CRAY2 */
95 #endif /* __STDC__ */
96 #else /* ! (CRAY || __arm) */
97 
98 #define APR_OFFSET(p_type,field) \
99  ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
100 
101 #endif /* !CRAY */
102 
103 /**
104  * Finding offsets of elements within structures.
105  * @param s_type structure type name
106  * @param field data field within the structure
107  * @return offset
108  */
109 #if defined(__has_builtin)
110 #if __has_builtin(__builtin_offsetof)
111 #define APR_OFFSETOF(s_type,field) __builtin_offsetof(s_type,field)
112 #endif
113 #endif /* __has_builtin */
114 #ifndef APR_OFFSETOF
115 #if defined(offsetof) && !defined(__cplusplus)
116 #define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
117 #else
118 #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
119 #endif
120 #endif /* ndef APR_OFFSETOF */
121 
122 #ifndef DOXYGEN
123 
124 /* A couple of prototypes for functions in case some platform doesn't
125  * have it
126  */
127 #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
128 #define strcasecmp(s1, s2) stricmp(s1, s2)
129 #elif (!APR_HAVE_STRCASECMP)
130 int strcasecmp(const char *a, const char *b);
131 #endif
132 
133 #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
134 #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
135 #elif (!APR_HAVE_STRNCASECMP)
136 int strncasecmp(const char *a, const char *b, size_t n);
137 #endif
138 
139 #endif
140 
141 /**
142  * Alignment macros
143  */
144 
145 /* APR_ALIGN() is only to be used to align on a power of 2 boundary */
146 #define APR_ALIGN(size, boundary) \
147  (((size) + ((boundary) - 1)) & ~((boundary) - 1))
148 
149 /** Default alignment */
150 #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
151 
152 
153 /**
154  * String and memory functions
155  */
156 
157 /* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */
158 #ifndef APR_STRINGIFY
159 /** Properly quote a value as a string in the C preprocessor */
160 #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
161 /** Helper macro for APR_STRINGIFY */
162 #define APR_STRINGIFY_HELPER(n) #n
163 #endif
164 
165 #if (!APR_HAVE_MEMMOVE)
166 #define memmove(a,b,c) bcopy(b,a,c)
167 #endif
168 
169 #if (!APR_HAVE_MEMCHR)
170 void *memchr(const void *s, int c, size_t n);
171 #endif
172 
173 /**
174  * Macro to provide a way to turn an incomplete type into a complete
175  * type containing common pointers for a provider.
176  */
177 #define APR_TYPEDEF_STRUCT(type, incompletion) \
178 struct type { \
179  incompletion \
180  void *unk[]; \
181 };
182 
183 /** @} */
184 
185 /**
186  * @defgroup apr_library Library initialization and termination
187  * @{
188  */
189 
190 /**
191  * Setup any APR internal data structures. This MUST be the first function
192  * called for any APR library. It is safe to call apr_initialize several
193  * times as long as apr_terminate() is called the same number of times.
194  * @remark See apr_app_initialize() if this is an application, rather than
195  * a library consumer of apr.
196  */
198 
199 /**
200  * Set up an application with normalized argc, argv (and optionally env) in
201  * order to deal with platform-specific oddities, such as Win32 services,
202  * code pages and signals. This must be the first function called for any
203  * APR program.
204  * @param argc Pointer to the argc that may be corrected
205  * @param argv Pointer to the argv that may be corrected
206  * @param env Pointer to the env that may be corrected, may be NULL
207  * @remark See apr_initialize() if this is a library consumer of apr.
208  * Otherwise, this call is identical to apr_initialize(), and must be closed
209  * with a call to apr_terminate() at the end of program execution.
210  */
212  char const * const * *argv,
213  char const * const * *env);
214 
215 /**
216  * Tear down any APR internal data structures which aren't torn down
217  * automatically. apr_terminate must be called once for every call to
218  * apr_initialize() or apr_app_initialize().
219  * @remark An APR program must call this function at termination once it
220  * has stopped using APR services. The APR developers suggest using
221  * @c atexit(apr_terminate) to ensure this is called. When using APR
222  * from a language other than C that has problems with the calling
223  * convention, use apr_terminate2() instead.
224  * @see apr_terminate2
225  */
227 
228 /**
229  * Tear down any APR internal data structures which aren't torn down
230  * automatically, same as apr_terminate()
231  * @remark An APR program must call either the apr_terminate() or apr_terminate2
232  * function once it it has finished using APR services. The APR
233  * developers suggest using @c atexit(apr_terminate) to ensure this is done.
234  * apr_terminate2 exists to allow non-c language apps to tear down apr,
235  * while apr_terminate() is recommended from c language applications.
236  */
238 
239 /** @} */
240 
241 /**
242  * @defgroup apr_random Random Functions
243  * @{
244  */
245 
246 #if APR_HAS_RANDOM || defined(DOXYGEN)
247 
248 /* TODO: I'm not sure this is the best place to put this prototype...*/
249 /**
250  * Generate random bytes.
251  * @param buf Buffer to fill with random bytes
252  * @param length Length of buffer in bytes
253  */
255  apr_size_t length);
256 
257 #endif
258 /** @} */
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 
264 #endif /* ! APR_GENERAL_H */
APR Platform Definitions.
APR Error Codes.
APR memory allocation.
int apr_status_t
Definition: apr_errno.h:44
int apr_signum_t
Definition: apr_general.h:68
void apr_terminate2(void)
apr_status_t apr_initialize(void)
void apr_terminate(void)
apr_status_t apr_app_initialize(int *argc, char const *const **argv, char const *const **env)
#define APR_DECLARE_NONSTD(type)
Definition: apr.h:529
#define APR_DECLARE(type)
Definition: apr.h:516
apr_status_t apr_generate_random_bytes(unsigned char *buf, apr_size_t length)