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

apr_lib.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_LIB_H 00017 #define APR_LIB_H 00018 00019 /** 00020 * @file apr_lib.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 general purpose library routines 00025 */ 00026 00027 #include "apr.h" 00028 #include "apr_errno.h" 00029 00030 #if APR_HAVE_CTYPE_H 00031 #include <ctype.h> 00032 #endif 00033 #if APR_HAVE_STDARG_H 00034 #include <stdarg.h> 00035 #endif 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif /* __cplusplus */ 00040 00041 /** 00042 * @defgroup apr_lib General Purpose Library Routines 00043 * @ingroup APR 00044 * This is collection of oddballs that didn't fit anywhere else, 00045 * and might move to more appropriate headers with the release 00046 * of APR 1.0. 00047 * @{ 00048 */ 00049 00050 /** A constant representing a 'large' string. */ 00051 #define HUGE_STRING_LEN 8192 00052 00053 /* 00054 * Define the structures used by the APR general-purpose library. 00055 */ 00056 00057 /** @see apr_vformatter_buff_t */ 00058 typedef struct apr_vformatter_buff_t apr_vformatter_buff_t; 00059 00060 /** 00061 * Structure used by the variable-formatter routines. 00062 */ 00063 struct apr_vformatter_buff_t { 00064 /** The current position */ 00065 char *curpos; 00066 /** The end position of the format string */ 00067 char *endpos; 00068 }; 00069 00070 /** 00071 * return the final element of the pathname 00072 * @param pathname The path to get the final element of 00073 * @return the final element of the path 00074 * @remark 00075 * <PRE> 00076 * For example: 00077 * "/foo/bar/gum" -> "gum" 00078 * "/foo/bar/gum/" -> "" 00079 * "gum" -> "gum" 00080 * "bs\\path\\stuff" -> "stuff" 00081 * </PRE> 00082 */ 00083 APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname); 00084 00085 /** 00086 * apr_killpg 00087 * Small utility macros to make things easier to read. Not usually a 00088 * goal, to be sure.. 00089 */ 00090 00091 #ifdef WIN32 00092 #define apr_killpg(x, y) 00093 #else /* WIN32 */ 00094 #ifdef NO_KILLPG 00095 #define apr_killpg(x, y) (kill (-(x), (y))) 00096 #else /* NO_KILLPG */ 00097 #define apr_killpg(x, y) (killpg ((x), (y))) 00098 #endif /* NO_KILLPG */ 00099 #endif /* WIN32 */ 00100 00101 /** 00102 * apr_vformatter() is a generic printf-style formatting routine 00103 * with some extensions. 00104 * @param flush_func The function to call when the buffer is full 00105 * @param c The buffer to write to 00106 * @param fmt The format string 00107 * @param ap The arguments to use to fill out the format string. 00108 * 00109 * @remark 00110 * <PRE> 00111 * The extensions are: 00112 * 00113 * %%pA takes a struct in_addr *, and prints it as a.b.c.d 00114 * %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or 00115 * [ipv6-address]:port 00116 * %%pT takes an apr_os_thread_t * and prints it in decimal 00117 * ('0' is printed if !APR_HAS_THREADS) 00118 * %%pp takes a void * and outputs it in hex 00119 * 00120 * The %%p hacks are to force gcc's printf warning code to skip 00121 * over a pointer argument without complaining. This does 00122 * mean that the ANSI-style %%p (output a void * in hex format) won't 00123 * work as expected at all, but that seems to be a fair trade-off 00124 * for the increased robustness of having printf-warnings work. 00125 * 00126 * Additionally, apr_vformatter allows for arbitrary output methods 00127 * using the apr_vformatter_buff and flush_func. 00128 * 00129 * The apr_vformatter_buff has two elements curpos and endpos. 00130 * curpos is where apr_vformatter will write the next byte of output. 00131 * It proceeds writing output to curpos, and updating curpos, until 00132 * either the end of output is reached, or curpos == endpos (i.e. the 00133 * buffer is full). 00134 * 00135 * If the end of output is reached, apr_vformatter returns the 00136 * number of bytes written. 00137 * 00138 * When the buffer is full, the flush_func is called. The flush_func 00139 * can return -1 to indicate that no further output should be attempted, 00140 * and apr_vformatter will return immediately with -1. Otherwise 00141 * the flush_func should flush the buffer in whatever manner is 00142 * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0. 00143 * 00144 * Note that flush_func is only invoked as a result of attempting to 00145 * write another byte at curpos when curpos >= endpos. So for 00146 * example, it's possible when the output exactly matches the buffer 00147 * space available that curpos == endpos will be true when 00148 * apr_vformatter returns. 00149 * 00150 * apr_vformatter does not call out to any other code, it is entirely 00151 * self-contained. This allows the callers to do things which are 00152 * otherwise "unsafe". For example, apr_psprintf uses the "scratch" 00153 * space at the unallocated end of a block, and doesn't actually 00154 * complete the allocation until apr_vformatter returns. apr_psprintf 00155 * would be completely broken if apr_vformatter were to call anything 00156 * that used this same pool. Similarly http_bprintf() uses the "scratch" 00157 * space at the end of its output buffer, and doesn't actually note 00158 * that the space is in use until it either has to flush the buffer 00159 * or until apr_vformatter returns. 00160 * </PRE> 00161 */ 00162 APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b), 00163 apr_vformatter_buff_t *c, const char *fmt, 00164 va_list ap); 00165 00166 /** 00167 * Display a prompt and read in the password from stdin. 00168 * @param prompt The prompt to display 00169 * @param pwbuf Buffer to store the password 00170 * @param bufsize The length of the password buffer. 00171 */ 00172 APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, 00173 apr_size_t *bufsize); 00174 00175 /** @} */ 00176 00177 /** 00178 * @defgroup apr_ctype ctype functions 00179 * These macros allow correct support of 8-bit characters on systems which 00180 * support 8-bit characters. Pretty dumb how the cast is required, but 00181 * that's legacy libc for ya. These new macros do not support EOF like 00182 * the standard macros do. Tough. 00183 * @{ 00184 */ 00185 /** @see isalnum */ 00186 #define apr_isalnum(c) (isalnum(((unsigned char)(c)))) 00187 /** @see isalpha */ 00188 #define apr_isalpha(c) (isalpha(((unsigned char)(c)))) 00189 /** @see iscntrl */ 00190 #define apr_iscntrl(c) (iscntrl(((unsigned char)(c)))) 00191 /** @see isdigit */ 00192 #define apr_isdigit(c) (isdigit(((unsigned char)(c)))) 00193 /** @see isgraph */ 00194 #define apr_isgraph(c) (isgraph(((unsigned char)(c)))) 00195 /** @see islower*/ 00196 #define apr_islower(c) (islower(((unsigned char)(c)))) 00197 /** @see isascii */ 00198 #ifdef isascii 00199 #define apr_isascii(c) (isascii(((unsigned char)(c)))) 00200 #else 00201 #define apr_isascii(c) (((c) & ~0x7f)==0) 00202 #endif 00203 /** @see isprint */ 00204 #define apr_isprint(c) (isprint(((unsigned char)(c)))) 00205 /** @see ispunct */ 00206 #define apr_ispunct(c) (ispunct(((unsigned char)(c)))) 00207 /** @see isspace */ 00208 #define apr_isspace(c) (isspace(((unsigned char)(c)))) 00209 /** @see isupper */ 00210 #define apr_isupper(c) (isupper(((unsigned char)(c)))) 00211 /** @see isxdigit */ 00212 #define apr_isxdigit(c) (isxdigit(((unsigned char)(c)))) 00213 /** @see tolower */ 00214 #define apr_tolower(c) (tolower(((unsigned char)(c)))) 00215 /** @see toupper */ 00216 #define apr_toupper(c) (toupper(((unsigned char)(c)))) 00217 00218 /** @} */ 00219 00220 #ifdef __cplusplus 00221 } 00222 #endif 00223 00224 #endif /* ! APR_LIB_H */

Generated on Thu Sep 16 13:47:10 2004 for Apache Portable Runtime by doxygen 1.3.7