[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - * src/internal.h (xstrerror): new function



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=22cb8ecc61abf08304762fd19bef3cf77207321a
Commit:        22cb8ecc61abf08304762fd19bef3cf77207321a
Parent:        544a86c4691182bd267ef1f17d99a27d83c035f6
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Mon Mar 9 14:59:12 2009 -0700
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Mon Mar 9 15:38:12 2009 -0700

* src/internal.h (xstrerror): new function

---
 configure.ac   |    2 ++
 src/internal.c |   16 ++++++++++++++++
 src/internal.h |    5 +++++
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index e335131..0520f09 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,8 @@ AC_SUBST(VERSION_SCRIPT_FLAGS)
 
 gl_INIT
 
+AC_CHECK_FUNCS([strerror_r])
+
 AC_OUTPUT(Makefile \
           gnulib/lib/Makefile \
           gnulib/tests/Makefile \
diff --git a/src/internal.c b/src/internal.c
index ca1df4e..86e64c2 100644
--- a/src/internal.c
+++ b/src/internal.c
@@ -361,6 +361,22 @@ char *path_of_tree(struct tree *tree) {
     return path;
 }
 
+const char *xstrerror(int errnum, char *buf, size_t len) {
+#ifdef HAVE_STRERROR_R
+# ifdef __USE_GNU
+    /* Annoying linux specific API contract */
+    return strerror_r(errnum, buf, len);
+# else
+    strerror_r(errnum, buf, len);
+    return buf;
+# endif
+#else
+    int n = snprintf(buf, len, "errno=%d", errnum);
+    return (0 < n && n < len
+            ? buf : "internal error: buffer too small in xstrerror");
+#endif
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/src/internal.h b/src/internal.h
index 1b020c5..7844935 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -254,6 +254,11 @@ char *format_pos(const char *text, int pos);
  */
 char* read_file(const char *path);
 
+/* Get the error message for ERRNUM in a threadsafe way. Based on libvirt's
+ * virStrError
+ */
+const char *xstrerror(int errnum, char *buf, size_t len);
+
 /* Define: AUG_NO_DEFAULT_LOAD
  * A hidden flag used by augparse to suppress loading of all the modules
  * on the path */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]