|
Apache Portable Runtime
|
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef APR_GENERAL_H 00018 #define APR_GENERAL_H 00019 00020 /** 00021 * @file apr_general.h 00022 * This is collection of oddballs that didn't fit anywhere else, 00023 * and might move to more appropriate headers with the release 00024 * of APR 1.0. 00025 * @brief APR Miscellaneous library routines 00026 */ 00027 00028 #include "apr.h" 00029 #include "apr_pools.h" 00030 #include "apr_errno.h" 00031 00032 #if APR_HAVE_SIGNAL_H 00033 #include <signal.h> 00034 #endif 00035 00036 #ifdef __cplusplus 00037 extern "C" { 00038 #endif /* __cplusplus */ 00039 00040 /** 00041 * @defgroup apr_general Miscellaneous library routines 00042 * @ingroup APR 00043 * This is collection of oddballs that didn't fit anywhere else, 00044 * and might move to more appropriate headers with the release 00045 * of APR 1.0. 00046 * @{ 00047 */ 00048 00049 /** FALSE */ 00050 #ifndef FALSE 00051 #define FALSE 0 00052 #endif 00053 /** TRUE */ 00054 #ifndef TRUE 00055 #define TRUE (!FALSE) 00056 #endif 00057 00058 /** a space */ 00059 #define APR_ASCII_BLANK '\040' 00060 /** a carrige return */ 00061 #define APR_ASCII_CR '\015' 00062 /** a line feed */ 00063 #define APR_ASCII_LF '\012' 00064 /** a tab */ 00065 #define APR_ASCII_TAB '\011' 00066 00067 /** signal numbers typedef */ 00068 typedef int apr_signum_t; 00069 00070 /* Type of I/O to wait for */ 00071 typedef enum { APR_WAIT_READ, APR_WAIT_WRITE } apr_wait_type_t; 00072 00073 /** 00074 * Finding offsets of elements within structures. 00075 * Taken from the X code... they've sweated portability of this stuff 00076 * so we don't have to. Sigh... 00077 * @param p_type pointer type name 00078 * @param field data field within the structure pointed to 00079 * @return offset 00080 */ 00081 00082 #if defined(CRAY) || (defined(__arm) && !defined(LINUX)) 00083 #ifdef __STDC__ 00084 #define APR_OFFSET(p_type,field) _Offsetof(p_type,field) 00085 #else 00086 #ifdef CRAY2 00087 #define APR_OFFSET(p_type,field) \ 00088 (sizeof(int)*((unsigned int)&(((p_type)NULL)->field))) 00089 00090 #else /* !CRAY2 */ 00091 00092 #define APR_OFFSET(p_type,field) ((unsigned int)&(((p_type)NULL)->field)) 00093 00094 #endif /* !CRAY2 */ 00095 #endif /* __STDC__ */ 00096 #else /* ! (CRAY || __arm) */ 00097 00098 #define APR_OFFSET(p_type,field) \ 00099 ((long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL))) 00100 00101 #endif /* !CRAY */ 00102 00103 /** 00104 * Finding offsets of elements within structures. 00105 * @param s_type structure type name 00106 * @param field data field within the structure 00107 * @return offset 00108 */ 00109 #if defined(offsetof) && !defined(__cplusplus) 00110 #define APR_OFFSETOF(s_type,field) offsetof(s_type,field) 00111 #else 00112 #define APR_OFFSETOF(s_type,field) APR_OFFSET(s_type*,field) 00113 #endif 00114 00115 #ifndef DOXYGEN 00116 00117 /* A couple of prototypes for functions in case some platform doesn't 00118 * have it 00119 */ 00120 #if (!APR_HAVE_STRCASECMP) && (APR_HAVE_STRICMP) 00121 #define strcasecmp(s1, s2) stricmp(s1, s2) 00122 #elif (!APR_HAVE_STRCASECMP) 00123 int strcasecmp(const char *a, const char *b); 00124 #endif 00125 00126 #if (!APR_HAVE_STRNCASECMP) && (APR_HAVE_STRNICMP) 00127 #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n) 00128 #elif (!APR_HAVE_STRNCASECMP) 00129 int strncasecmp(const char *a, const char *b, size_t n); 00130 #endif 00131 00132 #endif 00133 00134 /** 00135 * Alignment macros 00136 */ 00137 00138 /* APR_ALIGN() is only to be used to align on a power of 2 boundary */ 00139 #define APR_ALIGN(size, boundary) \ 00140 (((size) + ((boundary) - 1)) & ~((boundary) - 1)) 00141 00142 /** Default alignment */ 00143 #define APR_ALIGN_DEFAULT(size) APR_ALIGN(size, 8) 00144 00145 00146 /** 00147 * String and memory functions 00148 */ 00149 00150 /* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */ 00151 #ifndef APR_STRINGIFY 00152 /** Properly quote a value as a string in the C preprocessor */ 00153 #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n) 00154 /** Helper macro for APR_STRINGIFY */ 00155 #define APR_STRINGIFY_HELPER(n) #n 00156 #endif 00157 00158 #if (!APR_HAVE_MEMMOVE) 00159 #define memmove(a,b,c) bcopy(b,a,c) 00160 #endif 00161 00162 #if (!APR_HAVE_MEMCHR) 00163 void *memchr(const void *s, int c, size_t n); 00164 #endif 00165 00166 /** 00167 * Macro to provide a way to turn an incomplete type into a complete 00168 * type containing common pointers for a provider. 00169 */ 00170 #define APR_TYPEDEF_STRUCT(type, incompletion) \ 00171 struct type { \ 00172 incompletion \ 00173 void *unk[]; \ 00174 }; 00175 00176 /** @} */ 00177 00178 /** 00179 * @defgroup apr_library Library initialization and termination 00180 * @{ 00181 */ 00182 00183 /** 00184 * Setup any APR internal data structures. This MUST be the first function 00185 * called for any APR library. It is safe to call apr_initialize several 00186 * times as long as apr_terminate is called the same number of times. 00187 * @remark See apr_app_initialize if this is an application, rather than 00188 * a library consumer of apr. 00189 */ 00190 APR_DECLARE(apr_status_t) apr_initialize(void); 00191 00192 /** 00193 * Set up an application with normalized argc, argv (and optionally env) in 00194 * order to deal with platform-specific oddities, such as Win32 services, 00195 * code pages and signals. This must be the first function called for any 00196 * APR program. 00197 * @param argc Pointer to the argc that may be corrected 00198 * @param argv Pointer to the argv that may be corrected 00199 * @param env Pointer to the env that may be corrected, may be NULL 00200 * @remark See apr_initialize if this is a library consumer of apr. 00201 * Otherwise, this call is identical to apr_initialize, and must be closed 00202 * with a call to apr_terminate at the end of program execution. 00203 */ 00204 APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, 00205 char const * const * *argv, 00206 char const * const * *env); 00207 00208 /** 00209 * Tear down any APR internal data structures which aren't torn down 00210 * automatically. apr_terminate must be called once for every call to 00211 * apr_initialize() or apr_app_initialize(). 00212 * @remark An APR program must call this function at termination once it 00213 * has stopped using APR services. The APR developers suggest using 00214 * atexit to ensure this is called. When using APR from a language 00215 * other than C that has problems with the calling convention, use 00216 * apr_terminate2() instead. 00217 */ 00218 APR_DECLARE_NONSTD(void) apr_terminate(void); 00219 00220 /** 00221 * Tear down any APR internal data structures which aren't torn down 00222 * automatically, same as apr_terminate 00223 * @remark An APR program must call either the apr_terminate or apr_terminate2 00224 * function once it it has finished using APR services. The APR 00225 * developers suggest using atexit(apr_terminate) to ensure this is done. 00226 * apr_terminate2 exists to allow non-c language apps to tear down apr, 00227 * while apr_terminate is recommended from c language applications. 00228 */ 00229 APR_DECLARE(void) apr_terminate2(void); 00230 00231 /** @} */ 00232 00233 /** 00234 * @defgroup apr_random Random Functions 00235 * @{ 00236 */ 00237 00238 #if APR_HAS_RANDOM || defined(DOXYGEN) 00239 00240 /* TODO: I'm not sure this is the best place to put this prototype...*/ 00241 /** 00242 * Generate random bytes. 00243 * @param buf Buffer to fill with random bytes 00244 * @param length Length of buffer in bytes 00245 */ 00246 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, 00247 apr_size_t length); 00248 00249 #endif 00250 /** @} */ 00251 00252 #ifdef __cplusplus 00253 } 00254 #endif 00255 00256 #endif /* ! APR_GENERAL_H */
1.7.5