confd: Allow usage of asprintf

This commit is contained in:
Tobias Waldekranz
2023-04-17 14:09:24 +02:00
committed by Joachim Wiberg
parent 95a4b43091
commit db804eb9d0
5 changed files with 54 additions and 1 deletions
+4
View File
@@ -15,6 +15,10 @@ AC_CONFIG_FILES([
AC_PROG_CC
AC_PROG_INSTALL
AC_CONFIG_LIBOBJ_DIR(lib)
AC_REPLACE_FUNCS(vasprintf)
AC_REPLACE_FUNCS(asprintf)
# Check for pkg-config first, warn if it's not installed
PKG_PROG_PKG_CONFIG
+18
View File
@@ -0,0 +1,18 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef HAVE_VASPRINTF
int vasprintf(char **strp, const char *fmt, va_list ap);
#endif
int asprintf(char **strp, const char *fmt, ...)
{
va_list ap;
int len;
va_start(ap, fmt);
len = vasprintf(strp, fmt, ap);
va_end(ap);
return len;
}
+25
View File
@@ -0,0 +1,25 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
int vasprintf(char **strp, const char *fmt, va_list ap)
{
va_list apdup;
char *str;
int len;
va_copy(apdup, ap);
len = vsnprintf(0, 0, fmt, apdup);
va_end(apdup);
if (len < 0)
return -1;
len++;
str = malloc(len);
if (!str)
return -1;
*strp = str;
return vsnprintf(str, len, fmt, ap);
}
+1 -1
View File
@@ -1,5 +1,5 @@
CFLAGS = -Wall -Wextra -Werror -Wno-unused-parameter
AM_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -DYANG_PATH_=\"$(YANGDIR)/\"
AM_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -D_GNU_SOURCE -DYANG_PATH_=\"$(YANGDIR)/\"
plugindir = $(srpdplugindir)
plugin_LTLIBRARIES = confd-plugin.la
+6
View File
@@ -17,6 +17,12 @@
#include <sysrepo/values.h>
#include <sysrepo/xpath.h>
#ifndef HAVE_VASPRINTF
int vasprintf(char **strp, const char *fmt, va_list ap);
#endif
#ifndef HAVE_ASPRINTF
int asprintf(char **strp, const char *fmt, ...);
#endif
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))