You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mi...@apache.org on 2018/08/19 11:44:44 UTC

svn commit: r1838376 - in /apr/apr-util/branches/1.7.x: CHANGES include/apu_errno.h misc/apr_error.c

Author: minfrin
Date: Sun Aug 19 11:44:44 2018
New Revision: 1838376

URL: http://svn.apache.org/viewvc?rev=1838376&view=rev
Log:
Backport r1838375

Add apr_errprintf() as a convenience function to create and
populate apu_err_t.

Added:
    apr/apr-util/branches/1.7.x/misc/apr_error.c   (with props)
Modified:
    apr/apr-util/branches/1.7.x/CHANGES
    apr/apr-util/branches/1.7.x/include/apu_errno.h

Modified: apr/apr-util/branches/1.7.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/CHANGES?rev=1838376&r1=1838375&r2=1838376&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/CHANGES [utf-8] (original)
+++ apr/apr-util/branches/1.7.x/CHANGES [utf-8] Sun Aug 19 11:44:44 2018
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes with APR-util 1.7.0
 
+  *) Add apr_errprintf() as a convenience function to create and
+     populate apu_err_t. [Graham Leggett]
+
   *) apr_crypto: Add support for digest functions, with hashing, signing
      and verifying. [Graham Leggett]
 

Modified: apr/apr-util/branches/1.7.x/include/apu_errno.h
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/include/apu_errno.h?rev=1838376&r1=1838375&r2=1838376&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/include/apu_errno.h (original)
+++ apr/apr-util/branches/1.7.x/include/apu_errno.h Sun Aug 19 11:44:44 2018
@@ -23,7 +23,9 @@
  */
 
 #include "apr.h"
+#include "apu.h"
 #include "apr_errno.h"
+#include "apr_pools.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -171,6 +173,27 @@ typedef struct apu_err_t {
     int rc;
 } apu_err_t;
 
+/**
+ * Populate a apu_err_t structure with the given error, allocated
+ * from the given pool.
+ *
+ * If the result parameter points at a NULL pointer, a apu_err_t
+ * structure will be allocated, otherwise the apu_err_t structure
+ * will be reused.
+ * @param result If points to NULL, the apu_err_t structure is
+ *   allocated and returned, otherwise the existing apu_err_t is used.
+ * @param p The pool to use.
+ * @param reason The reason string, may be NULL.
+ * @param rc The underlying result code.
+ * @param fmt The format of the string
+ * @param ... The arguments to use while printing the data
+ * @return APR_SUCCESS on success, APR_ENOMEM if out of memory.
+ */
+APU_DECLARE_NONSTD(apr_status_t) apr_errprintf(apu_err_t **result,
+        apr_pool_t *p, const char *reason, int rc, const char *fmt, ...)
+        __attribute__((format(printf,5,6)))
+        __attribute__((nonnull(1,2)));
+
 /** @} */
 
 #ifdef __cplusplus

Added: apr/apr-util/branches/1.7.x/misc/apr_error.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/misc/apr_error.c?rev=1838376&view=auto
==============================================================================
--- apr/apr-util/branches/1.7.x/misc/apr_error.c (added)
+++ apr/apr-util/branches/1.7.x/misc/apr_error.c Sun Aug 19 11:44:44 2018
@@ -0,0 +1,45 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * levelations under the License.
+ */
+
+#include "apu.h"
+#include "apr_strings.h"
+#include "apr_pools.h"
+#include "apu_errno.h"
+
+APU_DECLARE_NONSTD(apr_status_t) apr_errprintf(apu_err_t **result,
+        apr_pool_t *p, const char *reason, int rc, const char *fmt, ...)
+{
+    va_list ap;
+    apu_err_t *res;
+
+    res = *result;
+    if (!res) {
+        res = *result = apr_pcalloc(p, sizeof(apu_err_t));
+        if (!res) {
+            return APR_ENOMEM;
+        }
+    }
+
+    va_start(ap, fmt);
+    res->msg = apr_pvsprintf(p, fmt, ap);
+    va_end(ap);
+
+    res->reason = reason;
+    res->rc = rc;
+
+    return APR_SUCCESS;
+}
+

Propchange: apr/apr-util/branches/1.7.x/misc/apr_error.c
------------------------------------------------------------------------------
    svn:eol-style = native