Skip to content

Commit 1b50180

Browse files
committed
Add apr_errprintf() as a convenience function to create and
populate apu_err_t. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1838375 13f79535-47bb-0310-9956-ffa450edef68
1 parent fec2199 commit 1b50180

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
-*- coding: utf-8 -*-
22
Changes for APR 2.0.0
33

4+
*) Add apr_errprintf() as a convenience function to create and
5+
populate apu_err_t. [Graham Leggett]
6+
47
*) apr_crypto: Add support for digest functions, with hashing, signing
58
and verifying. [Graham Leggett]
69

include/apu_errno.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "apr.h"
2626
#include "apr_errno.h"
27+
#include "apr_pools.h"
2728

2829
#ifdef __cplusplus
2930
extern "C" {
@@ -171,6 +172,27 @@ typedef struct apu_err_t {
171172
int rc;
172173
} apu_err_t;
173174

175+
/**
176+
* Populate a apu_err_t structure with the given error, allocated
177+
* from the given pool.
178+
*
179+
* If the result parameter points at a NULL pointer, a apu_err_t
180+
* structure will be allocated, otherwise the apu_err_t structure
181+
* will be reused.
182+
* @param result If points to NULL, the apu_err_t structure is
183+
* allocated and returned, otherwise the existing apu_err_t is used.
184+
* @param p The pool to use.
185+
* @param reason The reason string, may be NULL.
186+
* @param rc The underlying result code.
187+
* @param fmt The format of the string
188+
* @param ... The arguments to use while printing the data
189+
* @return APR_SUCCESS on success, APR_ENOMEM if out of memory.
190+
*/
191+
APR_DECLARE_NONSTD(apr_status_t) apr_errprintf(apu_err_t **result,
192+
apr_pool_t *p, const char *reason, int rc, const char *fmt, ...)
193+
__attribute__((format(printf,5,6)))
194+
__attribute__((nonnull(1,2)));
195+
174196
/** @} */
175197

176198
#ifdef __cplusplus

util-misc/apr_error.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
* levelations under the License.
15+
*/
16+
17+
#include "apu.h"
18+
#include "apr_strings.h"
19+
#include "apr_pools.h"
20+
#include "apu_errno.h"
21+
22+
APR_DECLARE_NONSTD(apr_status_t) apr_errprintf(apu_err_t **result,
23+
apr_pool_t *p, const char *reason, int rc, const char *fmt, ...)
24+
{
25+
va_list ap;
26+
apu_err_t *res;
27+
28+
res = *result;
29+
if (!res) {
30+
res = *result = apr_pcalloc(p, sizeof(apu_err_t));
31+
if (!res) {
32+
return APR_ENOMEM;
33+
}
34+
}
35+
36+
va_start(ap, fmt);
37+
res->msg = apr_pvsprintf(p, fmt, ap);
38+
va_end(ap);
39+
40+
res->reason = reason;
41+
res->rc = rc;
42+
43+
return APR_SUCCESS;
44+
}
45+

0 commit comments

Comments
 (0)