INN commit: branches/2.5/lib (asprintf.c)

INN Commit rra at isc.org
Sun Nov 3 19:18:12 UTC 2013


    Date: Sunday, November 3, 2013 @ 11:18:12
  Author: iulius
Revision: 9554

asprintf.c: synchronize with rra-c-util

In the vasprintf replacement, preserve errno if snprintf fails when
formatting the string into the newly-allocated buffer.

Modified:
  branches/2.5/lib/asprintf.c

------------+
 asprintf.c |   44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)

Modified: asprintf.c
===================================================================
--- asprintf.c	2013-11-03 19:16:22 UTC (rev 9553)
+++ asprintf.c	2013-11-03 19:18:12 UTC (rev 9554)
@@ -1,19 +1,33 @@
-/*  $Id$
-**
-**  Replacement for a missing asprintf and vasprintf.
-**
-**  Written by Russ Allbery <rra at stanford.edu>
-**  This work is hereby placed in the public domain by its author.
-**
-**  Provides the same functionality as the standard GNU library routines
-**  asprintf and vasprintf for those platforms that don't have them.
-*/
+/* $Id$
+ *
+ * Replacement for a missing asprintf and vasprintf.
+ *
+ * Provides the same functionality as the standard GNU library routines
+ * asprintf and vasprintf for those platforms that don't have them.
+ *
+ * The canonical version of this file is maintained in the rra-c-util package,
+ * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+ *
+ * Written by Russ Allbery <rra at stanford.edu>
+ *
+ * The authors hereby relinquish any claim to any copyright that they may have
+ * in this work, whether granted under contract or by operation of law or
+ * international treaty, and hereby commit to the public, at large, that they
+ * shall not, at any time in the future, seek to enforce any copyright in this
+ * work against any person or entity, or prevent any person or entity from
+ * copying, publishing, distributing or creating derivative works of this
+ * work.
+ */
 
 #include "config.h"
 #include "clibrary.h"
 
-/* If we're running the test suite, rename the functions to avoid conflicts
-   with the system versions. */
+#include <errno.h>
+
+/*
+ * If we're running the test suite, rename the functions to avoid conflicts
+ * with the system versions.
+ */
 #if TESTING
 # define asprintf test_asprintf
 # define vasprintf test_vasprintf
@@ -22,6 +36,7 @@
 int test_vasprintf(char **, const char *, va_list);
 #endif
 
+
 int
 asprintf(char **strp, const char *fmt, ...)
 {
@@ -34,11 +49,12 @@
     return status;
 }
 
+
 int
 vasprintf(char **strp, const char *fmt, va_list args)
 {
     va_list args_copy;
-    int status, needed;
+    int status, needed, oerrno;
 
     va_copy(args_copy, args);
     needed = vsnprintf(NULL, 0, fmt, args_copy);
@@ -54,8 +70,10 @@
     if (status >= 0)
         return status;
     else {
+        oerrno = errno;
         free(*strp);
         *strp = NULL;
+        errno = oerrno;
         return status;
     }
 }



More information about the inn-committers mailing list