Skip to content

Commit

Permalink
Include vasprintf-posix from gnulib. Not yet in replacement includes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhams committed Oct 20, 2019
1 parent 11f7a6c commit 081399d
Show file tree
Hide file tree
Showing 11 changed files with 3,989 additions and 1 deletion.
10 changes: 10 additions & 0 deletions libdicl/gl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# strtoll \
# strtoull \
# unsetenv \
# vasprintf-posix \
# vfprintf-posix \
# vsprintf-posix \
# wait-process
Expand Down Expand Up @@ -2134,6 +2135,15 @@ EXTRA_libgnu_a_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.c

## end gnulib module vasnprintf

## begin gnulib module vasprintf


EXTRA_DIST += asprintf.c vasprintf.c

EXTRA_libgnu_a_SOURCES += asprintf.c vasprintf.c

## end gnulib module vasprintf

## begin gnulib module verify


Expand Down
39 changes: 39 additions & 0 deletions libdicl/gl/asprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Formatted output to strings.
Copyright (C) 1999, 2002, 2006-2007, 2009-2019 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>. */

#include <config.h>

/* Specification. */
#ifdef IN_LIBASPRINTF
# include "vasprintf.h"
#else
# include <stdio.h>
#endif

#include <stdarg.h>

int
asprintf (char **resultp, const char *format, ...)
{
va_list args;
int result;

va_start (args, format);
result = vasprintf (resultp, format, args);
va_end (args);
return result;
}
2 changes: 2 additions & 0 deletions libdicl/gl/m4/gnulib-cache.m4
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
# strtoll \
# strtoull \
# unsetenv \
# vasprintf-posix \
# vfprintf-posix \
# vsprintf-posix \
# wait-process
Expand All @@ -76,6 +77,7 @@ gl_MODULES([
strtoll
strtoull
unsetenv
vasprintf-posix
vfprintf-posix
vsprintf-posix
wait-process
Expand Down
17 changes: 17 additions & 0 deletions libdicl/gl/m4/gnulib-comp.m4
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ AC_DEFUN([gl_EARLY],
# Code from module usleep-tests:
# Code from module vasnprintf:
# Code from module vasnprintf-tests:
# Code from module vasprintf:
# Code from module vasprintf-posix:
# Code from module vasprintf-posix-tests:
# Code from module vasprintf-tests:
# Code from module verify:
# Code from module verify-tests:
# Code from module vfprintf-posix:
Expand Down Expand Up @@ -617,6 +621,12 @@ AC_DEFUN([gl_INIT],
fi
gl_STDLIB_MODULE_INDICATOR([unsetenv])
gl_FUNC_VASNPRINTF
gl_FUNC_VASPRINTF
gl_STDIO_MODULE_INDICATOR([vasprintf])
m4_ifdef([AM_XGETTEXT_OPTION],
[AM_][XGETTEXT_OPTION([--flag=asprintf:2:c-format])
AM_][XGETTEXT_OPTION([--flag=vasprintf:2:c-format])])
gl_FUNC_VASPRINTF_POSIX
gl_FUNC_VFPRINTF_POSIX
gl_STDIO_MODULE_INDICATOR([vfprintf-posix])
gl_FUNC_VSPRINTF_POSIX
Expand Down Expand Up @@ -879,6 +889,7 @@ changequote([, ])dnl
fi
gl_UNISTD_MODULE_INDICATOR([usleep])
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
AC_REQUIRE([AC_CANONICAL_HOST])
case "$host_os" in
mingw*)
Expand Down Expand Up @@ -1018,6 +1029,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/alloca.in.h
lib/arg-nonnull.h
lib/asnprintf.c
lib/asprintf.c
lib/basename-lgpl.c
lib/c++defs.h
lib/c-ctype.c
Expand Down Expand Up @@ -1156,6 +1168,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/unsetenv.c
lib/vasnprintf.c
lib/vasnprintf.h
lib/vasprintf.c
lib/verify.h
lib/vfprintf.c
lib/vsprintf.c
Expand Down Expand Up @@ -1317,6 +1330,8 @@ AC_DEFUN([gl_FILE_LIST], [
m4/unistd_h.m4
m4/usleep.m4
m4/vasnprintf.m4
m4/vasprintf-posix.m4
m4/vasprintf.m4
m4/vfprintf-posix.m4
m4/vsprintf-posix.m4
m4/wait-process.m4
Expand Down Expand Up @@ -1478,6 +1493,8 @@ AC_DEFUN([gl_FILE_LIST], [
tests/test-unsetenv.c
tests/test-usleep.c
tests/test-vasnprintf.c
tests/test-vasprintf-posix.c
tests/test-vasprintf.c
tests/test-verify-try.c
tests/test-verify.c
tests/test-verify.sh
Expand Down
101 changes: 101 additions & 0 deletions libdicl/gl/m4/vasprintf-posix.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# vasprintf-posix.m4 serial 13
dnl Copyright (C) 2007-2019 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
[
AC_REQUIRE([gl_PRINTF_SIZES_C99])
AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
AC_REQUIRE([gl_PRINTF_INFINITE])
AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
AC_REQUIRE([gl_PRINTF_FLAG_ZERO])
AC_REQUIRE([gl_PRINTF_PRECISION])
AC_REQUIRE([gl_PRINTF_ENOMEM])
gl_cv_func_vasprintf_posix=no
AC_CHECK_FUNCS([vasprintf])
case "$gl_cv_func_printf_sizes_c99" in
*yes)
case "$gl_cv_func_printf_long_double" in
*yes)
case "$gl_cv_func_printf_infinite" in
*yes)
case "$gl_cv_func_printf_infinite_long_double" in
*yes)
case "$gl_cv_func_printf_directive_a" in
*yes)
case "$gl_cv_func_printf_directive_f" in
*yes)
case "$gl_cv_func_printf_directive_n" in
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
case "$gl_cv_func_printf_positions" in
*yes)
case "$gl_cv_func_printf_flag_grouping" in
*yes)
case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
case "$gl_cv_func_printf_flag_zero" in
*yes)
case "$gl_cv_func_printf_precision" in
*yes)
case "$gl_cv_func_printf_enomem" in
*yes)
if test $ac_cv_func_vasprintf = yes; then
# vasprintf exists and is
# already POSIX compliant.
gl_cv_func_vasprintf_posix=yes
fi
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
;;
esac
if test $gl_cv_func_vasprintf_posix = no; then
gl_PREREQ_VASNPRINTF_LONG_DOUBLE
gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
gl_PREREQ_VASNPRINTF_DIRECTIVE_A
gl_PREREQ_VASNPRINTF_DIRECTIVE_F
gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
gl_PREREQ_VASNPRINTF_FLAG_GROUPING
gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
gl_PREREQ_VASNPRINTF_FLAG_ZERO
gl_PREREQ_VASNPRINTF_PRECISION
gl_PREREQ_VASNPRINTF_ENOMEM
gl_REPLACE_VASNPRINTF
gl_REPLACE_VASPRINTF
fi
])
46 changes: 46 additions & 0 deletions libdicl/gl/m4/vasprintf.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# vasprintf.m4 serial 6
dnl Copyright (C) 2002-2003, 2006-2007, 2009-2019 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_VASPRINTF],
[
AC_CHECK_FUNCS([vasprintf])
if test $ac_cv_func_vasprintf = no; then
gl_REPLACE_VASPRINTF
fi
])

AC_DEFUN([gl_REPLACE_VASPRINTF],
[
AC_LIBOBJ([vasprintf])
AC_LIBOBJ([asprintf])
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
if test $ac_cv_func_vasprintf = yes; then
REPLACE_VASPRINTF=1
else
HAVE_VASPRINTF=0
fi
gl_PREREQ_VASPRINTF_H
gl_PREREQ_VASPRINTF
gl_PREREQ_ASPRINTF
])

# Prerequisites of the vasprintf portion of lib/stdio.h.
AC_DEFUN([gl_PREREQ_VASPRINTF_H],
[
dnl Persuade glibc <stdio.h> to declare asprintf() and vasprintf().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
])

# Prerequisites of lib/vasprintf.c.
AC_DEFUN([gl_PREREQ_VASPRINTF],
[
])

# Prerequisites of lib/asprintf.c.
AC_DEFUN([gl_PREREQ_ASPRINTF],
[
])
50 changes: 50 additions & 0 deletions libdicl/gl/vasprintf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Formatted output to strings.
Copyright (C) 1999, 2002, 2006-2019 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>. */

#include <config.h>

/* Specification. */
#ifdef IN_LIBASPRINTF
# include "vasprintf.h"
#else
# include <stdio.h>
#endif

#include <errno.h>
#include <limits.h>
#include <stdlib.h>

#include "vasnprintf.h"

int
vasprintf (char **resultp, const char *format, va_list args)
{
size_t length;
char *result = vasnprintf (NULL, &length, format, args);
if (result == NULL)
return -1;

if (length > INT_MAX)
{
free (result);
errno = EOVERFLOW;
return -1;
}

*resultp = result;
/* Return the number of resulting bytes, excluding the trailing NUL. */
return length;
}
2 changes: 1 addition & 1 deletion libdicl/gnulibimportnotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

#After the import, must set AM_CFLAGS= -fPIC -DPIC to create relocatable code

$GNULIB_HOME/gnulib-tool --import --lib=libgnu --source-base=gl --m4-base=/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=. --with-tests --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files getline getopt-posix getprogname mkdtemp mktime nanosleep printf-posix select setenv sprintf-posix strtod strtold strtoll strtoull unsetenv vfprintf-posix vsprintf-posix wait-process
$GNULIB_HOME/gnulib-tool --import --lib=libgnu --source-base=gl --m4-base=/gl/m4 --doc-base=doc --tests-base=tests --aux-dir=. --with-tests --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files getline getopt-posix getprogname mkdtemp mktime nanosleep printf-posix select setenv sprintf-posix strtod strtold strtoll strtoull unsetenv vfprintf-posix vsprintf-posix vasprintf-posix wait-process
18 changes: 18 additions & 0 deletions libdicl/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,24 @@ EXTRA_DIST += test-vasnprintf.c macros.h

## end gnulib module vasnprintf-tests

## begin gnulib module vasprintf-posix-tests

TESTS += test-vasprintf-posix
check_PROGRAMS += test-vasprintf-posix

EXTRA_DIST += test-vasprintf-posix.c minus-zero.h infinity.h nan.h macros.h

## end gnulib module vasprintf-posix-tests

## begin gnulib module vasprintf-tests

TESTS += test-vasprintf
check_PROGRAMS += test-vasprintf

EXTRA_DIST += test-vasprintf.c signature.h macros.h

## end gnulib module vasprintf-tests

## begin gnulib module verify-tests

TESTS_ENVIRONMENT += MAKE='$(MAKE)'
Expand Down
Loading

0 comments on commit 081399d

Please sign in to comment.