mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 04:33:00 +02:00
confd: Allow usage of asprintf
This commit is contained in:
committed by
Joachim Wiberg
parent
95a4b43091
commit
db804eb9d0
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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,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
|
||||
|
||||
@@ -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]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user