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