[augeas-devel] augeas: master - Utility function xasprintf

David Lutterkort lutter at fedoraproject.org
Tue Sep 1 18:09:00 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=ce53f22cb0f7737b584fdbc2801d1f810e48a6fc
Commit:        ce53f22cb0f7737b584fdbc2801d1f810e48a6fc
Parent:        23e95600b3cc67323691cfc8e5a4f74d218c3011
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Tue Aug 25 15:37:31 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Mon Aug 31 14:10:11 2009 -0700

Utility function xasprintf

Like asprintf, but don't leave first arg in limbo on error

*  src/internal.h (xasprintf): new prototype
*  src/internal.c (xasprintf): new function
---
 src/internal.c |   12 ++++++++++++
 src/internal.h |    3 +++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/internal.c b/src/internal.c
index 86e64c2..4f0b779 100644
--- a/src/internal.c
+++ b/src/internal.c
@@ -377,6 +377,18 @@ const char *xstrerror(int errnum, char *buf, size_t len) {
 #endif
 }
 
+int xasprintf(char **strp, const char *format, ...) {
+  va_list args;
+  int result;
+
+  va_start (args, format);
+  result = vasprintf (strp, format, args);
+  va_end (args);
+  if (result < 0)
+      *strp = NULL;
+  return result;
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/src/internal.h b/src/internal.h
index 5a0c64c..fcc3982 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -263,6 +263,9 @@ char* read_file(const char *path);
  */
 const char *xstrerror(int errnum, char *buf, size_t len);
 
+/* Like asprintf, but set *STRP to NULL on error */
+int xasprintf(char **strp, const char *format, ...);
+
 /* Struct: augeas
  * The data structure representing a connection to Augeas. */
 struct augeas {




More information about the augeas-devel mailing list