1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
22
* This is collection of oddballs that didn't fit anywhere else,
23
* and might move to more appropriate headers with the release
25
* @brief APR general purpose library routines
29
#include "apr_errno.h"
40
#endif /* __cplusplus */
43
* @defgroup apr_lib General Purpose Library Routines
45
* This is collection of oddballs that didn't fit anywhere else,
46
* and might move to more appropriate headers with the release
51
/** A constant representing a 'large' string. */
52
#define HUGE_STRING_LEN 8192
55
* Define the structures used by the APR general-purpose library.
58
/** @see apr_vformatter_buff_t */
59
typedef struct apr_vformatter_buff_t apr_vformatter_buff_t;
62
* Structure used by the variable-formatter routines.
64
struct apr_vformatter_buff_t {
65
/** The current position */
67
/** The end position of the format string */
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
78
* "/foo/bar/gum" -> "gum"
79
* "/foo/bar/gum/" -> ""
81
* "bs\\path\\stuff" -> "stuff"
84
APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname);
88
* Small utility macros to make things easier to read. Not usually a
93
#define apr_killpg(x, y)
96
#define apr_killpg(x, y) (kill (-(x), (y)))
98
#define apr_killpg(x, y) (killpg ((x), (y)))
99
#endif /* NO_KILLPG */
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.
112
* The extensions are:
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
* %%pp takes a void * and outputs it in hex
123
* The %%p hacks are to force gcc's printf warning code to skip
124
* over a pointer argument without complaining. This does
125
* mean that the ANSI-style %%p (output a void * in hex format) won't
126
* work as expected at all, but that seems to be a fair trade-off
127
* for the increased robustness of having printf-warnings work.
129
* Additionally, apr_vformatter allows for arbitrary output methods
130
* using the apr_vformatter_buff and flush_func.
132
* The apr_vformatter_buff has two elements curpos and endpos.
133
* curpos is where apr_vformatter will write the next byte of output.
134
* It proceeds writing output to curpos, and updating curpos, until
135
* either the end of output is reached, or curpos == endpos (i.e. the
138
* If the end of output is reached, apr_vformatter returns the
139
* number of bytes written.
141
* When the buffer is full, the flush_func is called. The flush_func
142
* can return -1 to indicate that no further output should be attempted,
143
* and apr_vformatter will return immediately with -1. Otherwise
144
* the flush_func should flush the buffer in whatever manner is
145
* appropriate, re apr_pool_t nitialize curpos and endpos, and return 0.
147
* Note that flush_func is only invoked as a result of attempting to
148
* write another byte at curpos when curpos >= endpos. So for
149
* example, it's possible when the output exactly matches the buffer
150
* space available that curpos == endpos will be true when
151
* apr_vformatter returns.
153
* apr_vformatter does not call out to any other code, it is entirely
154
* self-contained. This allows the callers to do things which are
155
* otherwise "unsafe". For example, apr_psprintf uses the "scratch"
156
* space at the unallocated end of a block, and doesn't actually
157
* complete the allocation until apr_vformatter returns. apr_psprintf
158
* would be completely broken if apr_vformatter were to call anything
159
* that used this same pool. Similarly http_bprintf() uses the "scratch"
160
* space at the end of its output buffer, and doesn't actually note
161
* that the space is in use until it either has to flush the buffer
162
* or until apr_vformatter returns.
165
APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *b),
166
apr_vformatter_buff_t *c, const char *fmt,
170
* Display a prompt and read in the password from stdin.
171
* @param prompt The prompt to display
172
* @param pwbuf Buffer to store the password
173
* @param bufsize The length of the password buffer.
174
* @remark If the password entered must be truncated to fit in
175
* the provided buffer, APR_ENAMETOOLONG will be returned.
176
* Note that the bufsize paramater is passed by reference for no
177
* reason; its value will never be modified by the apr_password_get()
180
APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf,
181
apr_size_t *bufsize);
186
* @defgroup apr_ctype ctype functions
187
* These macros allow correct support of 8-bit characters on systems which
188
* support 8-bit characters. Pretty dumb how the cast is required, but
189
* that's legacy libc for ya. These new macros do not support EOF like
190
* the standard macros do. Tough.
194
#define apr_isalnum(c) (isalnum(((unsigned char)(c))))
196
#define apr_isalpha(c) (isalpha(((unsigned char)(c))))
198
#define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
200
#define apr_isdigit(c) (isdigit(((unsigned char)(c))))
202
#define apr_isgraph(c) (isgraph(((unsigned char)(c))))
204
#define apr_islower(c) (islower(((unsigned char)(c))))
207
#define apr_isascii(c) (isascii(((unsigned char)(c))))
209
#define apr_isascii(c) (((c) & ~0x7f)==0)
212
#define apr_isprint(c) (isprint(((unsigned char)(c))))
214
#define apr_ispunct(c) (ispunct(((unsigned char)(c))))
216
#define apr_isspace(c) (isspace(((unsigned char)(c))))
218
#define apr_isupper(c) (isupper(((unsigned char)(c))))
220
#define apr_isxdigit(c) (isxdigit(((unsigned char)(c))))
222
#define apr_tolower(c) (tolower(((unsigned char)(c))))
224
#define apr_toupper(c) (toupper(((unsigned char)(c))))
232
#endif /* ! APR_LIB_H */