Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_general.h

Go to the documentation of this file.
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 /* APR_STRINGIFY is defined here, and also in apr_release.h, so wrap it */
00147 #ifndef APR_STRINGIFY
00148 /** Properly quote a value as a string in the C preprocessor */
00149 #define APR_STRINGIFY(n) APR_STRINGIFY_HELPER(n)
00150 /** Helper macro for APR_STRINGIFY */
00151 #define APR_STRINGIFY_HELPER(n) #n
00152 #endif
00153 
00154 #if (!APR_HAVE_MEMMOVE)
00155 #define memmove(a,b,c) bcopy(b,a,c)
00156 #endif
00157 
00158 #if (!APR_HAVE_MEMCHR)
00159 void *memchr(const void *s, int c, size_t n);
00160 #endif
00161 
00162 /** @} */
00163 
00164 /**
00165  * @defgroup apr_library Library initialization and termination
00166  * @{
00167  */
00168 
00169 /**
00170  * Setup any APR internal data structures.  This MUST be the first function 
00171  * called for any APR library.
00172  * @remark See apr_app_initialize if this is an application, rather than
00173  * a library consumer of apr.
00174  */
00175 APR_DECLARE(apr_status_t) apr_initialize(void);
00176 
00177 /**
00178  * Set up an application with normalized argc, argv (and optionally env) in
00179  * order to deal with platform-specific oddities, such as Win32 services,
00180  * code pages and signals.  This must be the first function called for any
00181  * APR program.
00182  * @param argc Pointer to the argc that may be corrected
00183  * @param argv Pointer to the argv that may be corrected
00184  * @param env Pointer to the env that may be corrected, may be NULL
00185  * @remark See apr_initialize if this is a library consumer of apr.
00186  * Otherwise, this call is identical to apr_initialize, and must be closed
00187  * with a call to apr_terminate at the end of program execution.
00188  */
00189 APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, 
00190                                              char const * const * *argv, 
00191                                              char const * const * *env);
00192 
00193 /**
00194  * Tear down any APR internal data structures which aren't torn down 
00195  * automatically.
00196  * @remark An APR program must call this function at termination once it 
00197  *         has stopped using APR services.  The APR developers suggest using
00198  *         atexit to ensure this is called.  When using APR from a language
00199  *         other than C that has problems with the calling convention, use
00200  *         apr_terminate2() instead.
00201  */
00202 APR_DECLARE_NONSTD(void) apr_terminate(void);
00203 
00204 /**
00205  * Tear down any APR internal data structures which aren't torn down 
00206  * automatically, same as apr_terminate
00207  * @remark An APR program must call either the apr_terminate or apr_terminate2 
00208  *         function once it it has finished using APR services.  The APR 
00209  *         developers suggest using atexit(apr_terminate) to ensure this is done.
00210  *         apr_terminate2 exists to allow non-c language apps to tear down apr, 
00211  *         while apr_terminate is recommended from c language applications.
00212  */
00213 APR_DECLARE(void) apr_terminate2(void);
00214 
00215 /** @} */
00216 
00217 /**
00218  * @defgroup apr_random Random Functions
00219  * @{
00220  */
00221 
00222 #if APR_HAS_RANDOM || defined(DOXYGEN)
00223 
00224 /* TODO: I'm not sure this is the best place to put this prototype...*/
00225 /**
00226  * Generate random bytes.
00227  * @param buf Buffer to fill with random bytes
00228  * @param length Length of buffer in bytes
00229  */
00230 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, 
00231                                                     apr_size_t length);
00232 
00233 #endif
00234 /** @} */
00235 
00236 #ifdef __cplusplus
00237 }
00238 #endif
00239 
00240 #endif  /* ! APR_GENERAL_H */

Generated on Sun Mar 20 19:52:26 2005 for Apache Portable Runtime by  doxygen 1.3.9.1