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