summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2005-08-18 21:17:45 +0000
committerjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2005-08-18 21:17:45 +0000
commited9829ff68d33442e1f835fbae13c18846fcf69f (patch)
treead71e0fad38cc74ce29701659f40fca6aa42b748
parent3672c3fea32f6ef79feef57f753a9a149a6203e3 (diff)
downloadlibapr-ed9829ff68d33442e1f835fbae13c18846fcf69f.tar.gz
* strings/apr_snprintf.c (apr_vformatter): Add support for %pm to
print the error string corresponding to an apr_status_t. * test/testfmt.c (error_fmt): New test. * include/apr_lib.h: Document %pm and note the versioning constraint. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@233381 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES8
-rw-r--r--include/apr_lib.h5
-rw-r--r--strings/apr_snprintf.c19
-rw-r--r--test/testfmt.c19
4 files changed, 51 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 2a7d0f6d1..c34f44fd6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+Changes for APR 1.3.0
+
+ *) Add %pm support to apr_snprintf() for printing the error string
+ corresponding to an apr_status_t value. [Joe Orton]
+
+ *) Add APR_ARRAY_IDX() and APR_ARRAY_PUSH() convenience macros to
+ apr_tables.h. [Garrett Rooney]
+
Changes for APR 1.2.1
*) Refactor Win32 condition variables code to address bugs 27654, 34336.
diff --git a/include/apr_lib.h b/include/apr_lib.h
index 738df7a27..802359419 100644
--- a/include/apr_lib.h
+++ b/include/apr_lib.h
@@ -118,8 +118,13 @@ APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname);
* ('0' is printed if !APR_HAS_THREADS)
* %%pt takes an apr_os_thread_t * and prints it in hexadecimal
* ('0' is printed if !APR_HAS_THREADS)
+ * %%pm takes an apr_status_t * and prints the appropriate error
+ * string (from apr_strerror) corresponding to that error code.
* %%pp takes a void * and outputs it in hex
*
+ * %%pt is only available from APR 1.2.0 onwards.
+ * %%pm is only available from APR 1.3.0 onwards.
+ *
* The %%p hacks are to force gcc's printf warning code to skip
* over a pointer argument without complaining. This does
* mean that the ANSI-style %%p (output a void * in hex format) won't
diff --git a/strings/apr_snprintf.c b/strings/apr_snprintf.c
index 313a778cf..e903d2d31 100644
--- a/strings/apr_snprintf.c
+++ b/strings/apr_snprintf.c
@@ -21,6 +21,7 @@
#include "apr_strings.h"
#include "apr_network_io.h"
#include "apr_portable.h"
+#include "apr_errno.h"
#include <math.h>
#if APR_HAVE_CTYPE_H
#include <ctype.h>
@@ -1166,6 +1167,24 @@ APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *),
}
break;
+ /* print the error for an apr_status_t */
+ case 'm':
+ {
+ apr_status_t *mrv;
+
+ mrv = va_arg(ap, apr_status_t *);
+ if (mrv != NULL) {
+ s = apr_strerror(*mrv, num_buf, NUM_BUF_SIZE-1);
+ s_len = strlen(s);
+ }
+ else {
+ s = S_NULL;
+ s_len = S_NULL_LEN;
+ }
+ pad_char = ' ';
+ }
+ break;
+
case 'T':
#if APR_HAS_THREADS
{
diff --git a/test/testfmt.c b/test/testfmt.c
index 6cc2c3db4..f4548be36 100644
--- a/test/testfmt.c
+++ b/test/testfmt.c
@@ -117,6 +117,24 @@ static void more_int64_fmts(abts_case *tc, void *data)
ABTS_STR_EQUAL(tc, buf, "-314159265358979323");
}
+static void error_fmt(abts_case *tc, void *data)
+{
+ char ebuf[150], sbuf[150], *s;
+ apr_status_t rv;
+
+ rv = APR_SUCCESS;
+ apr_strerror(rv, ebuf, sizeof ebuf);
+ apr_snprintf(sbuf, sizeof sbuf, "%pm", &rv);
+ ABTS_STR_EQUAL(tc, sbuf, ebuf);
+
+ rv = APR_ENOTIMPL;
+ s = apr_pstrcat(p, "foo-",
+ apr_strerror(rv, ebuf, sizeof ebuf),
+ "-bar", NULL);
+ apr_snprintf(sbuf, sizeof sbuf, "foo-%pm-bar", &rv);
+ ABTS_STR_EQUAL(tc, sbuf, s);
+}
+
abts_suite *testfmt(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -129,6 +147,7 @@ abts_suite *testfmt(abts_suite *suite)
abts_run_test(suite, uint64_t_fmt, NULL);
abts_run_test(suite, uint64_t_hex_fmt, NULL);
abts_run_test(suite, more_int64_fmts, NULL);
+ abts_run_test(suite, error_fmt, NULL);
return suite;
}