[Open-scap] [PATCH] Added implementation of vasprintf

Marshall Miller mmiller at tresys.com
Wed May 11 19:03:02 UTC 2011


vasprintf is not implemented on Solaris, so added it.
---
 configure.ac                      |    4 +++
 src/OVAL/probes/SEAP/Makefile.am  |    2 +
 src/OVAL/probes/SEAP/sexp-manip.c |    1 +
 src/OVAL/probes/SEAP/vasprintf.c  |   53 +++++++++++++++++++++++++++++++++++++
 src/OVAL/probes/SEAP/vasprintf.h  |   36 +++++++++++++++++++++++++
 5 files changed, 96 insertions(+), 0 deletions(-)
 create mode 100644 src/OVAL/probes/SEAP/vasprintf.c
 create mode 100644 src/OVAL/probes/SEAP/vasprintf.h

diff --git a/configure.ac b/configure.ac
index 03c77d8..72ae9da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,10 @@ CFLAGS_NODEBUG="-DNDEBUG -Wno-unused-function -Wno-unused-but-set-variable"
 #
 AC_CHECK_FUNC(sigwaitinfo, [sigwaitinfo_libs=""], [sigwaitinfo_libs="-lrt"])
 
+# vasprintf
+#
+AC_CHECK_FUNCS([vasprintf])
+
 #
 # posix_memalign
 #
diff --git a/src/OVAL/probes/SEAP/Makefile.am b/src/OVAL/probes/SEAP/Makefile.am
index 74decd9..28ca81d 100644
--- a/src/OVAL/probes/SEAP/Makefile.am
+++ b/src/OVAL/probes/SEAP/Makefile.am
@@ -76,6 +76,8 @@ libseap_la_SOURCES= generic/bfind.c		\
 		    public/seap-error.h		\
 		    public/sexp-datatype.h 	\
 		    public/strbuf.h		\
+		    vasprintf.h		\
+		    vasprintf.c		\
 		    _sexp-rawptr.h
 
 libseap_la_CFLAGS= @pthread_cflags@ -DUSE_XMALLOC -DXMALLOC_EXIT -DWANT_BASE64 -I$(top_srcdir) -I$(top_srcdir)/src -I. -I$(top_srcdir)/src/OVAL/probes/SEAP/public -DSEAP_THREAD_SAFE -DSEAP_MSGID_BITS=32
diff --git a/src/OVAL/probes/SEAP/sexp-manip.c b/src/OVAL/probes/SEAP/sexp-manip.c
index 1a3e603..2afc02d 100644
--- a/src/OVAL/probes/SEAP/sexp-manip.c
+++ b/src/OVAL/probes/SEAP/sexp-manip.c
@@ -45,6 +45,7 @@
 #include "_sexp-rawptr.h"
 #include "public/sexp-manip.h"
 #include "public/sexp-manip_r.h"
+#include "vasprintf.h"
 
 static void SEXP_free_lmemb (SEXP_t *s_exp);
 
diff --git a/src/OVAL/probes/SEAP/vasprintf.c b/src/OVAL/probes/SEAP/vasprintf.c
new file mode 100644
index 0000000..976fbeb
--- /dev/null
+++ b/src/OVAL/probes/SEAP/vasprintf.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2011 Tresys Technology Inc., Columbia, Maryland.
+ * All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *      "Marshall Miller" <mmiller at tresys.com>
+ */
+
+#include "config.h"
+#if !defined(HAVE_VASPRINTF)
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include "vasprintf.h"
+
+int vasprintf(char **strp, const char *fmt, va_list ap) {
+    va_list ap2;
+    char tmpchar[1];
+    char *newstr;
+    int s;
+
+    va_copy(ap2, ap);
+    s = vsnprintf(tmpchar, 1, fmt, ap);
+
+    newstr = malloc(s+1);
+    if (newstr == NULL) {
+        va_end(ap2);
+        return (-1);
+    }
+    s = vsnprintf(newstr, s+1, fmt, ap2);
+    va_end(ap2);
+
+    *strp = newstr;
+    return (s);
+}
+
+#endif
+
diff --git a/src/OVAL/probes/SEAP/vasprintf.h b/src/OVAL/probes/SEAP/vasprintf.h
new file mode 100644
index 0000000..2027383
--- /dev/null
+++ b/src/OVAL/probes/SEAP/vasprintf.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 Tresys Technology Inc., Columbia, Maryland.
+ * All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *      "Marshall Miller" <mmiller at tresys.com>
+ */
+
+#ifndef _VASPRINTF_H
+#define _VASPRINTF_H
+
+#include "config.h"
+#if !defined(HAVE_VASPRINTF)
+
+#include <stdarg.h>
+
+int vasprintf(char **strp, const char *fmt, va_list ap);
+
+#endif
+
+#endif
+
-- 
1.6.2.5




More information about the Open-scap-list mailing list