Apache Portable Runtime
apr_lib.h
Go to the documentation of this file.
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements. See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef APR_LIB_H
18 #define APR_LIB_H
19 
20 /**
21  * @file apr_lib.h
22  * This is collection of oddballs that didn't fit anywhere else,
23  * and might move to more appropriate headers with the release
24  * of APR 1.0.
25  * @brief APR general purpose library routines
26  */
27 
28 #include "apr.h"
29 #include "apr_errno.h"
30 
31 #if APR_HAVE_CTYPE_H
32 #include <ctype.h>
33 #endif
34 #if APR_HAVE_STDARG_H
35 #include <stdarg.h>
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 
42 /**
43  * @defgroup apr_lib General Purpose Library Routines
44  * @ingroup APR
45  * This is collection of oddballs that didn't fit anywhere else,
46  * and might move to more appropriate headers with the release
47  * of APR 1.0.
48  * @{
49  */
50 
51 /** A constant representing a 'large' string. */
52 #define HUGE_STRING_LEN 8192
53 
54 /*
55  * Define the structures used by the APR general-purpose library.
56  */
57 
58 /** @see apr_vformatter_buff_t */
60 
61 /**
62  * Structure used by the variable-formatter routines.
63  */
65  /** The current position */
66  char *curpos;
67  /** The end position of the format string */
68  char *endpos;
69 };
70 
71 /**
72  * return the final element of the pathname
73  * @param pathname The path to get the final element of
74  * @return the final element of the path
75  * @remark
76  * <PRE>
77  * For example:
78  * "/foo/bar/gum" -> "gum"
79  * "/foo/bar/gum/" -> ""
80  * "gum" -> "gum"
81  * "bs\\path\\stuff" -> "stuff"
82  * </PRE>
83  */
84 APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname);
85 
86 /**
87  * apr_killpg
88  * Small utility macros to make things easier to read. Not usually a
89  * goal, to be sure..
90  */
91 
92 #ifdef WIN32
93 #define apr_killpg(x, y)
94 #else /* WIN32 */
95 #ifdef NO_KILLPG
96 #define apr_killpg(x, y) (kill (-(x), (y)))
97 #else /* NO_KILLPG */
98 #define apr_killpg(x, y) (killpg ((x), (y)))
99 #endif /* NO_KILLPG */
100 #endif /* WIN32 */
101 
102 /**
103  * apr_vformatter() is a generic printf-style formatting routine
104  * with some extensions.
105  * @param flush_func The function to call when the buffer is full
106  * @param c The buffer to write to
107  * @param fmt The format string
108  * @param ap The arguments to use to fill out the format string.
109  *
110  * @remark
111  * <PRE>
112  * The extensions are:
113  *
114  * - %%pA takes a struct in_addr *, and prints it as a.b.c.d
115  * - %%pI takes an apr_sockaddr_t * and prints it as a.b.c.d:port or
116  * \[ipv6-address\]:port
117  * - %%pT takes an apr_os_thread_t * and prints it in decimal
118  * ('0' is printed if !APR_HAS_THREADS)
119  * - %%pt takes an apr_os_thread_t * and prints it in hexadecimal
120  * ('0' is printed if !APR_HAS_THREADS)
121  * - %%pm takes an apr_status_t * and prints the appropriate error
122  * string (from apr_strerror) corresponding to that error code.
123  * - %%pp takes a void * and outputs it in hex
124  * - %%pB takes a apr_uint32_t * as bytes and outputs it's apr_strfsize
125  * - %%pF same as above, but takes a apr_off_t *
126  * - %%pS same as above, but takes a apr_size_t *
127  *
128  * %%pA, %%pI, %%pT, %%pp are available from APR 1.0.0 onwards (and in 0.9.x).
129  * %%pt is only available from APR 1.2.0 onwards.
130  * %%pm, %%pB, %%pF and %%pS are only available from APR 1.3.0 onwards.
131  *
132  * The %%p hacks are to force gcc's printf warning code to skip
133  * over a pointer argument without complaining. This does
134  * mean that the ANSI-style %%p (output a void * in hex format) won't
135  * work as expected at all, but that seems to be a fair trade-off
136  * for the increased robustness of having printf-warnings work.
137  *
138  * Additionally, apr_vformatter allows for arbitrary output methods
139  * using the apr_vformatter_buff and flush_func.
140  *
141  * The apr_vformatter_buff has two elements curpos and endpos.
142  * curpos is where apr_vformatter will write the next byte of output.
143  * It proceeds writing output to curpos, and updating curpos, until
144  * either the end of output is reached, or curpos == endpos (i.e. the
145  * buffer is full).
146  *
147  * If the end of output is reached, apr_vformatter returns the
148  * number of bytes written.
149  *
150  * When the buffer is full, the flush_func is called. The flush_func
151  * can return -1 to indicate that no further output should be attempted,
152  * and apr_vformatter will return immediately with -1. Otherwise
153  * the flush_func should flush the buffer in whatever manner is
154  * appropriate, re apr_pool_t nitialize curpos and endpos, and return 0.
155  *
156  * Note that flush_func is only invoked as a result of attempting to
157  * write another byte at curpos when curpos >= endpos. So for
158  * example, it's possible when the output exactly matches the buffer
159  * space available that curpos == endpos will be true when
160  * apr_vformatter returns.
161  *
162  * apr_vformatter does not call out to any other code, it is entirely
163  * self-contained. This allows the callers to do things which are
164  * otherwise "unsafe". For example, apr_psprintf uses the "scratch"
165  * space at the unallocated end of a block, and doesn't actually
166  * complete the allocation until apr_vformatter returns. apr_psprintf
167  * would be completely broken if apr_vformatter were to call anything
168  * that used this same pool. Similarly http_bprintf() uses the "scratch"
169  * space at the end of its output buffer, and doesn't actually note
170  * that the space is in use until it either has to flush the buffer
171  * or until apr_vformatter returns.
172  * </PRE>
173  */
174 APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b),
175  apr_vformatter_buff_t *c, const char *fmt,
176  va_list ap);
177 
178 /**
179  * Display a prompt and read in the password from stdin.
180  * @param prompt The prompt to display
181  * @param pwbuf Buffer to store the password
182  * @param bufsize The length of the password buffer.
183  * @remark If the password entered must be truncated to fit in
184  * the provided buffer, APR_ENAMETOOLONG will be returned.
185  * Note that the bufsize paramater is passed by reference for no
186  * reason; its value will never be modified by the apr_password_get()
187  * function.
188  */
189 APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf,
190  apr_size_t *bufsize);
191 
192 /** @} */
193 
194 /**
195  * @defgroup apr_ctype ctype functions
196  * These macros allow correct support of 8-bit characters on systems which
197  * support 8-bit characters. Pretty dumb how the cast is required, but
198  * that's legacy libc for ya. These new macros do not support EOF like
199  * the standard macros do. Tough.
200  * @{
201  */
202 /** @see isalnum */
203 #define apr_isalnum(c) (isalnum(((unsigned char)(c))))
204 /** @see isalpha */
205 #define apr_isalpha(c) (isalpha(((unsigned char)(c))))
206 /** @see iscntrl */
207 #define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
208 /** @see isdigit */
209 #define apr_isdigit(c) (isdigit(((unsigned char)(c))))
210 /** @see isgraph */
211 #define apr_isgraph(c) (isgraph(((unsigned char)(c))))
212 /** @see islower*/
213 #define apr_islower(c) (islower(((unsigned char)(c))))
214 /** @see isascii */
215 #ifdef isascii
216 #define apr_isascii(c) (isascii(((unsigned char)(c))))
217 #else
218 #define apr_isascii(c) (((c) & ~0x7f)==0)
219 #endif
220 /** @see isprint */
221 #define apr_isprint(c) (isprint(((unsigned char)(c))))
222 /** @see ispunct */
223 #define apr_ispunct(c) (ispunct(((unsigned char)(c))))
224 /** @see isspace */
225 #define apr_isspace(c) (isspace(((unsigned char)(c))))
226 /** @see isupper */
227 #define apr_isupper(c) (isupper(((unsigned char)(c))))
228 /** @see isxdigit */
229 #define apr_isxdigit(c) (isxdigit(((unsigned char)(c))))
230 /** @see tolower */
231 #define apr_tolower(c) (tolower(((unsigned char)(c))))
232 /** @see toupper */
233 #define apr_toupper(c) (toupper(((unsigned char)(c))))
234 
235 /** @} */
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #endif /* ! APR_LIB_H */
char * curpos
Definition: apr_lib.h:66
#define APR_DECLARE(type)
Definition: apr.h:498
APR Error Codes.
Definition: apr_lib.h:64
APR Platform Definitions.
char * endpos
Definition: apr_lib.h:68
int apr_vformatter(int(*flush_func)(apr_vformatter_buff_t *b), apr_vformatter_buff_t *c, const char *fmt, va_list ap)
const char * apr_filepath_name_get(const char *pathname)
int apr_status_t
Definition: apr_errno.h:44
apr_status_t apr_password_get(const char *prompt, char *pwbuf, apr_size_t *bufsize)