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(offsetof) && !defined(__cplusplus)
110 #define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
111 #else
112 #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
113 #endif
114 
115 #ifndef DOXYGEN
116 
117 /* A couple of prototypes for functions in case some platform doesn't
118  * have it
119  */
120 #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
121 #define strcasecmp(s1, s2) stricmp(s1, s2)
122 #elif (!APR_HAVE_STRCASECMP)
123 int strcasecmp(const char *a, const char *b);
124 #endif
125 
126 #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
127 #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
128 #elif (!APR_HAVE_STRNCASECMP)
129 int strncasecmp(const char *a, const char *b, size_t n);
130 #endif
131 
132 #endif
133 
134 /**
135  * Alignment macros
136  */
137 
138 /* APR_ALIGN() is only to be used to align on a power of 2 boundary */
139 #define APR_ALIGN(size, boundary) \
140  (((size) + ((boundary) - 1)) & ~((boundary) - 1))
141 
142 /** Default alignment */
143 #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
144 
145 
146 /**
147  * String and memory functions
148  */
149 
150 /* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */
151 #ifndef APR_STRINGIFY
152 /** Properly quote a value as a string in the C preprocessor */
153 #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
154 /** Helper macro for APR_STRINGIFY */
155 #define APR_STRINGIFY_HELPER(n) #n
156 #endif
157 
158 #if (!APR_HAVE_MEMMOVE)
159 #define memmove(a,b,c) bcopy(b,a,c)
160 #endif
161 
162 #if (!APR_HAVE_MEMCHR)
163 void *memchr(const void *s, int c, size_t n);
164 #endif
165 
166 /**
167  * Macro to provide a way to turn an incomplete type into a complete
168  * type containing common pointers for a provider.
169  */
170 #define APR_TYPEDEF_STRUCT(type, incompletion) \
171 struct type { \
172  incompletion \
173  void *unk[]; \
174 };
175 
176 /** @} */
177 
178 /**
179  * @defgroup apr_library Library initialization and termination
180  * @{
181  */
182 
183 /**
184  * Setup any APR internal data structures. This MUST be the first function
185  * called for any APR library. It is safe to call apr_initialize several
186  * times as long as apr_terminate is called the same number of times.
187  * @remark See apr_app_initialize if this is an application, rather than
188  * a library consumer of apr.
189  */
191 
192 /**
193  * Set up an application with normalized argc, argv (and optionally env) in
194  * order to deal with platform-specific oddities, such as Win32 services,
195  * code pages and signals. This must be the first function called for any
196  * APR program.
197  * @param argc Pointer to the argc that may be corrected
198  * @param argv Pointer to the argv that may be corrected
199  * @param env Pointer to the env that may be corrected, may be NULL
200  * @remark See apr_initialize if this is a library consumer of apr.
201  * Otherwise, this call is identical to apr_initialize, and must be closed
202  * with a call to apr_terminate at the end of program execution.
203  */
205  char const * const * *argv,
206  char const * const * *env);
207 
208 /**
209  * Tear down any APR internal data structures which aren't torn down
210  * automatically. apr_terminate must be called once for every call to
211  * apr_initialize() or apr_app_initialize().
212  * @remark An APR program must call this function at termination once it
213  * has stopped using APR services. The APR developers suggest using
214  * atexit to ensure this is called. When using APR from a language
215  * other than C that has problems with the calling convention, use
216  * apr_terminate2() instead.
217  */
219 
220 /**
221  * Tear down any APR internal data structures which aren't torn down
222  * automatically, same as apr_terminate
223  * @remark An APR program must call either the apr_terminate or apr_terminate2
224  * function once it it has finished using APR services. The APR
225  * developers suggest using atexit(apr_terminate) to ensure this is done.
226  * apr_terminate2 exists to allow non-c language apps to tear down apr,
227  * while apr_terminate is recommended from c language applications.
228  */
229 APR_DECLARE(void) apr_terminate2(void);
230 
231 /** @} */
232 
233 /**
234  * @defgroup apr_random Random Functions
235  * @{
236  */
237 
238 #if APR_HAS_RANDOM || defined(DOXYGEN)
239 
240 /* TODO: I'm not sure this is the best place to put this prototype...*/
241 /**
242  * Generate random bytes.
243  * @param buf Buffer to fill with random bytes
244  * @param length Length of buffer in bytes
245  */
247  apr_size_t length);
248 
249 #endif
250 /** @} */
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 
256 #endif /* ! APR_GENERAL_H */
int apr_signum_t
Definition: apr_general.h:68
apr_status_t apr_generate_random_bytes(unsigned char *buf, apr_size_t length)
apr_status_t apr_app_initialize(int *argc, char const *const **argv, char const *const **env)
APR memory allocation.
void apr_terminate2(void)
apr_status_t apr_initialize(void)
APR Error Codes.
#define APR_DECLARE(type)
Definition: apr.h:500
APR Platform Definitions.
#define APR_DECLARE_NONSTD(type)
Definition: apr.h:513
int apr_status_t
Definition: apr_errno.h:44
void apr_terminate(void)