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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * This is collection of oddballs that didn't fit anywhere else,
23 * and might move to more appropriate headers with the release
25 * @brief APR Miscellaneous library routines
29 #include "apr_pools.h"
30 #include "apr_errno.h"
38 #endif /* __cplusplus */
41 * @defgroup apr_general Miscellaneous library routines
43 * This is collection of oddballs that didn't fit anywhere else,
44 * and might move to more appropriate headers with the release
59 #define APR_ASCII_BLANK '\040'
60 /** a carrige return */
61 #define APR_ASCII_CR '\015'
63 #define APR_ASCII_LF '\012'
65 #define APR_ASCII_TAB '\011'
67 /** signal numbers typedef */
68 typedef int apr_signum_t;
71 * Finding offsets of elements within structures.
72 * Taken from the X code... they've sweated portability of this stuff
73 * so we don't have to. Sigh...
74 * @param p_type pointer type name
75 * @param field data field within the structure pointed to
79 #if defined(CRAY) || (defined(__arm) && !defined(LINUX))
81 #define APR_OFFSET(p_type,field) _Offsetof(p_type,field)
84 #define APR_OFFSET(p_type,field) \
85 (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
89 #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field))
93 #else /* ! (CRAY || __arm) */
95 #define APR_OFFSET(p_type,field) \
96 ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
101 * Finding offsets of elements within structures.
102 * @param s_type structure type name
103 * @param field data field within the structure
106 #if defined(offsetof) && !defined(__cplusplus)
107 #define APR_OFFSETOF(s_type,field) offsetof(s_type,field)
109 #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field)
112 /** @deprecated @see APR_OFFSET */
113 #define APR_XtOffset APR_OFFSET
115 /** @deprecated @see APR_OFFSETOF */
116 #define APR_XtOffsetOf APR_OFFSETOF
120 /* A couple of prototypes for functions in case some platform doesn't
123 #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP)
124 #define strcasecmp(s1, s2) stricmp(s1, s2)
125 #elif (!APR_HAVE_STRCASECMP)
126 int strcasecmp(const char *a, const char *b);
129 #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP)
130 #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
131 #elif (!APR_HAVE_STRNCASECMP)
132 int strncasecmp(const char *a, const char *b, size_t n);
141 /* APR_ALIGN() is only to be used to align on a power of 2 boundary */
142 #define APR_ALIGN(size, boundary) \
143 (((size) + ((boundary) - 1)) & ~((boundary) - 1))
145 /** Default alignment */
146 #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8)
150 * String and memory functions
153 /** Properly quote a value as a string in the C preprocessor */
154 #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
155 /** Helper macro for APR_STRINGIFY */
156 #define APR_STRINGIFY_HELPER(n) #n
158 #if (!APR_HAVE_MEMMOVE)
159 #define memmove(a,b,c) bcopy(b,a,c)
162 #if (!APR_HAVE_MEMCHR)
163 void *memchr(const void *s, int c, size_t n);
169 * @defgroup apr_library Library initialization and termination
174 * Setup any APR internal data structures. This MUST be the first function
175 * called for any APR library.
176 * @remark See apr_app_initialize if this is an application, rather than
177 * a library consumer of apr.
179 APR_DECLARE(apr_status_t) apr_initialize(void);
182 * Set up an application with normalized argc, argv (and optionally env) in
183 * order to deal with platform-specific oddities, such as Win32 services,
184 * code pages and signals. This must be the first function called for any
186 * @param argc Pointer to the argc that may be corrected
187 * @param argv Pointer to the argv that may be corrected
188 * @param env Pointer to the env that may be corrected, may be NULL
189 * @remark See apr_initialize if this is a library consumer of apr.
190 * Otherwise, this call is identical to apr_initialize, and must be closed
191 * with a call to apr_terminate at the end of program execution.
193 APR_DECLARE(apr_status_t) apr_app_initialize(int *argc,
194 char const * const * *argv,
195 char const * const * *env);
198 * Tear down any APR internal data structures which aren't torn down
200 * @remark An APR program must call this function at termination once it
201 * has stopped using APR services. The APR developers suggest using
202 * atexit to ensure this is called. When using APR from a language
203 * other than C that has problems with the calling convention, use
204 * apr_terminate2() instead.
206 APR_DECLARE_NONSTD(void) apr_terminate(void);
209 * Tear down any APR internal data structures which aren't torn down
210 * automatically, same as apr_terminate
211 * @remark An APR program must call either the apr_terminate or apr_terminate2
212 * function once it it has finished using APR services. The APR
213 * developers suggest using atexit(apr_terminate) to ensure this is done.
214 * apr_terminate2 exists to allow non-c language apps to tear down apr,
215 * while apr_terminate is recommended from c language applications.
217 APR_DECLARE(void) apr_terminate2(void);
222 * @defgroup apr_random Random Functions
226 #if APR_HAS_RANDOM || defined(DOXYGEN)
228 /* TODO: I'm not sure this is the best place to put this prototype...*/
230 * Generate random bytes.
231 * @param buf Buffer to fill with random bytes
232 * @param length Length of buffer in bytes (becomes apr_size_t in APR 1.0)
234 #ifdef APR_ENABLE_FOR_1_0
235 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
238 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf,
249 #endif /* ! APR_GENERAL_H */