From: Bruno Haible <bruno@clisp.org> Date: Sat, 29 Jun 2024 23:32:24 +0000 (+0200) Subject: Global rename *zs[n]printf -> *s[n]zprintf. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=9118630ed3c8cdb3e623b289237f72a4ea0b0ab5;p=gnulib.git Global rename *zs[n]printf -> *s[n]zprintf. * lib/aszprintf.c: Renamed from lib/azsprintf.c. * lib/c-aszprintf.c: Renamed from lib/c-azsprintf.c. * lib/c-vaszprintf.c: Renamed from lib/c-vazsprintf.c. * lib/c-vsnzprintf.c: Renamed from lib/c-vzsnprintf.c. * lib/c-snzprintf.c: Renamed from lib/c-zsnprintf.c. * lib/vaszprintf.c: Renamed from lib/vazsprintf.c. * lib/vsnzprintf.c: Renamed from lib/vzsnprintf.c. * lib/vszprintf.c: Renamed from lib/vzsprintf.c. * lib/snzprintf.c: Renamed from lib/zsnprintf.c. * lib/szprintf.c: Renamed from lib/zsprintf.c. * tests/test-c-vaszprintf-gnu.c: Renamed from tests/test-c-vazsprintf-gnu.c. * tests/test-c-vaszprintf-gnu.sh: Renamed from tests/test-c-vazsprintf-gnu.sh. * tests/test-c-vsnzprintf-gnu.c: Renamed from tests/test-c-vzsnprintf-gnu.c. * tests/test-c-vsnzprintf-gnu.sh: Renamed from tests/test-c-vzsnprintf-gnu.sh. * tests/test-c-snzprintf-gnu.c: Renamed from tests/test-c-zsnprintf-gnu.c. * tests/test-c-snzprintf-gnu.sh: Renamed from tests/test-c-zsnprintf-gnu.sh. * tests/test-vaszprintf-gnu.c: Renamed from tests/test-vazsprintf-gnu.c. * tests/test-vaszprintf-gnu.h: Renamed from tests/test-vazsprintf-gnu.h. * tests/test-vaszprintf-posix.c: Renamed from tests/test-vazsprintf-posix.c. * tests/test-vsnzprintf-gnu.c: Renamed from tests/test-vzsnprintf-gnu.c. * tests/test-vsnzprintf-posix.c: Renamed from tests/test-vzsnprintf-posix.c. * tests/test-vszprintf-gnu.c: Renamed from tests/test-vzsprintf-gnu.c. * tests/test-vszprintf-posix.c: Renamed from tests/test-vzsprintf-posix.c. * tests/test-snzprintf-gnu.c: Renamed from tests/test-zsnprintf-gnu.c. * tests/test-snzprintf-gnu.h: Renamed from tests/test-zsnprintf-gnu.h. * tests/test-snzprintf-posix.c: Renamed from tests/test-zsnprintf-posix.c. * tests/test-snzprintf-posix.h: Renamed from tests/test-zsnprintf-posix.h. * tests/test-szprintf-gnu.c: Renamed from tests/test-zsprintf-gnu.c. * tests/test-szprintf-gnu.h: Renamed from tests/test-zsprintf-gnu.h. * tests/test-szprintf-posix.c: Renamed from tests/test-zsprintf-posix.c. * tests/test-szprintf-posix.h: Renamed from tests/test-zsprintf-posix.h. * modules/c-vaszprintf: Renamed from modules/c-vazsprintf. * modules/c-vaszprintf-gnu: Renamed from modules/c-vazsprintf-gnu. * modules/c-vaszprintf-gnu-tests: Renamed from modules/c-vazsprintf-gnu-tests. * modules/c-vsnzprintf: Renamed from modules/c-vzsnprintf. * modules/c-vsnzprintf-gnu: Renamed from modules/c-vzsnprintf-gnu. * modules/c-vsnzprintf-gnu-tests: Renamed from modules/c-vzsnprintf-gnu-tests. * modules/c-snzprintf: Renamed from modules/c-zsnprintf. * modules/c-snzprintf-gnu: Renamed from modules/c-zsnprintf-gnu. * modules/c-snzprintf-gnu-tests: Renamed from modules/c-zsnprintf-gnu-tests. * modules/vaszprintf: Renamed from modules/vazsprintf. * modules/vaszprintf-gnu: Renamed from modules/vazsprintf-gnu. * modules/vaszprintf-gnu-tests: Renamed from modules/vazsprintf-gnu-tests. * modules/vaszprintf-posix: Renamed from modules/vazsprintf-posix. * modules/vaszprintf-posix-tests: Renamed from modules/vazsprintf-posix-tests. * modules/vsnzprintf: Renamed from modules/vzsnprintf. * modules/vsnzprintf-gnu: Renamed from modules/vzsnprintf-gnu. * modules/vsnzprintf-gnu-tests: Renamed from modules/vzsnprintf-gnu-tests. * modules/vsnzprintf-posix: Renamed from modules/vzsnprintf-posix. * modules/vsnzprintf-posix-tests: Renamed from modules/vzsnprintf-posix-tests. * modules/vszprintf: Renamed from modules/vzsprintf. * modules/vszprintf-gnu: Renamed from modules/vzsprintf-gnu. * modules/vszprintf-gnu-tests: Renamed from modules/vzsprintf-gnu-tests. * modules/vszprintf-posix: Renamed from modules/vzsprintf-posix. * modules/vszprintf-posix-tests: Renamed from modules/vzsprintf-posix-tests. * modules/snzprintf: Renamed from modules/zsnprintf. * modules/snzprintf-gnu: Renamed from modules/zsnprintf-gnu. * modules/snzprintf-gnu-tests: Renamed from modules/zsnprintf-gnu-tests. * modules/snzprintf-posix: Renamed from modules/zsnprintf-posix. * modules/snzprintf-posix-tests: Renamed from modules/zsnprintf-posix-tests. * modules/szprintf: Renamed from modules/zsprintf. * modules/szprintf-gnu: Renamed from modules/zsprintf-gnu. * modules/szprintf-gnu-tests: Renamed from modules/zsprintf-gnu-tests. * modules/szprintf-posix: Renamed from modules/zsprintf-posix. * modules/szprintf-posix-tests: Renamed from modules/zsprintf-posix-tests. All function names updated. * lib/stdio.in.h, m4/stdio_h.m4, modules/stdio: Update module indicator names. --- diff --git a/ChangeLog b/ChangeLog index e55831aaef..86fae3c408 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,96 @@ +2024-06-29 Bruno Haible <bruno@clisp.org> + + Global rename *zs[n]printf -> *s[n]zprintf. + * lib/aszprintf.c: Renamed from lib/azsprintf.c. + * lib/c-aszprintf.c: Renamed from lib/c-azsprintf.c. + * lib/c-vaszprintf.c: Renamed from lib/c-vazsprintf.c. + * lib/c-vsnzprintf.c: Renamed from lib/c-vzsnprintf.c. + * lib/c-snzprintf.c: Renamed from lib/c-zsnprintf.c. + * lib/vaszprintf.c: Renamed from lib/vazsprintf.c. + * lib/vsnzprintf.c: Renamed from lib/vzsnprintf.c. + * lib/vszprintf.c: Renamed from lib/vzsprintf.c. + * lib/snzprintf.c: Renamed from lib/zsnprintf.c. + * lib/szprintf.c: Renamed from lib/zsprintf.c. + * tests/test-c-vaszprintf-gnu.c: Renamed from + tests/test-c-vazsprintf-gnu.c. + * tests/test-c-vaszprintf-gnu.sh: Renamed from + tests/test-c-vazsprintf-gnu.sh. + * tests/test-c-vsnzprintf-gnu.c: Renamed from + tests/test-c-vzsnprintf-gnu.c. + * tests/test-c-vsnzprintf-gnu.sh: Renamed from + tests/test-c-vzsnprintf-gnu.sh. + * tests/test-c-snzprintf-gnu.c: Renamed from + tests/test-c-zsnprintf-gnu.c. + * tests/test-c-snzprintf-gnu.sh: Renamed from + tests/test-c-zsnprintf-gnu.sh. + * tests/test-vaszprintf-gnu.c: Renamed from tests/test-vazsprintf-gnu.c. + * tests/test-vaszprintf-gnu.h: Renamed from tests/test-vazsprintf-gnu.h. + * tests/test-vaszprintf-posix.c: Renamed from + tests/test-vazsprintf-posix.c. + * tests/test-vsnzprintf-gnu.c: Renamed from tests/test-vzsnprintf-gnu.c. + * tests/test-vsnzprintf-posix.c: Renamed from + tests/test-vzsnprintf-posix.c. + * tests/test-vszprintf-gnu.c: Renamed from tests/test-vzsprintf-gnu.c. + * tests/test-vszprintf-posix.c: Renamed from + tests/test-vzsprintf-posix.c. + * tests/test-snzprintf-gnu.c: Renamed from tests/test-zsnprintf-gnu.c. + * tests/test-snzprintf-gnu.h: Renamed from tests/test-zsnprintf-gnu.h. + * tests/test-snzprintf-posix.c: Renamed from + tests/test-zsnprintf-posix.c. + * tests/test-snzprintf-posix.h: Renamed from + tests/test-zsnprintf-posix.h. + * tests/test-szprintf-gnu.c: Renamed from tests/test-zsprintf-gnu.c. + * tests/test-szprintf-gnu.h: Renamed from tests/test-zsprintf-gnu.h. + * tests/test-szprintf-posix.c: Renamed from tests/test-zsprintf-posix.c. + * tests/test-szprintf-posix.h: Renamed from tests/test-zsprintf-posix.h. + * modules/c-vaszprintf: Renamed from modules/c-vazsprintf. + * modules/c-vaszprintf-gnu: Renamed from modules/c-vazsprintf-gnu. + * modules/c-vaszprintf-gnu-tests: Renamed from + modules/c-vazsprintf-gnu-tests. + * modules/c-vsnzprintf: Renamed from modules/c-vzsnprintf. + * modules/c-vsnzprintf-gnu: Renamed from modules/c-vzsnprintf-gnu. + * modules/c-vsnzprintf-gnu-tests: Renamed from + modules/c-vzsnprintf-gnu-tests. + * modules/c-snzprintf: Renamed from modules/c-zsnprintf. + * modules/c-snzprintf-gnu: Renamed from modules/c-zsnprintf-gnu. + * modules/c-snzprintf-gnu-tests: Renamed from + modules/c-zsnprintf-gnu-tests. + * modules/vaszprintf: Renamed from modules/vazsprintf. + * modules/vaszprintf-gnu: Renamed from modules/vazsprintf-gnu. + * modules/vaszprintf-gnu-tests: Renamed from + modules/vazsprintf-gnu-tests. + * modules/vaszprintf-posix: Renamed from modules/vazsprintf-posix. + * modules/vaszprintf-posix-tests: Renamed from + modules/vazsprintf-posix-tests. + * modules/vsnzprintf: Renamed from modules/vzsnprintf. + * modules/vsnzprintf-gnu: Renamed from modules/vzsnprintf-gnu. + * modules/vsnzprintf-gnu-tests: Renamed from + modules/vzsnprintf-gnu-tests. + * modules/vsnzprintf-posix: Renamed from modules/vzsnprintf-posix. + * modules/vsnzprintf-posix-tests: Renamed from + modules/vzsnprintf-posix-tests. + * modules/vszprintf: Renamed from modules/vzsprintf. + * modules/vszprintf-gnu: Renamed from modules/vzsprintf-gnu. + * modules/vszprintf-gnu-tests: Renamed from modules/vzsprintf-gnu-tests. + * modules/vszprintf-posix: Renamed from modules/vzsprintf-posix. + * modules/vszprintf-posix-tests: Renamed from + modules/vzsprintf-posix-tests. + * modules/snzprintf: Renamed from modules/zsnprintf. + * modules/snzprintf-gnu: Renamed from modules/zsnprintf-gnu. + * modules/snzprintf-gnu-tests: Renamed from modules/zsnprintf-gnu-tests. + * modules/snzprintf-posix: Renamed from modules/zsnprintf-posix. + * modules/snzprintf-posix-tests: Renamed from + modules/zsnprintf-posix-tests. + * modules/szprintf: Renamed from modules/zsprintf. + * modules/szprintf-gnu: Renamed from modules/zsprintf-gnu. + * modules/szprintf-gnu-tests: Renamed from modules/zsprintf-gnu-tests. + * modules/szprintf-posix: Renamed from modules/zsprintf-posix. + * modules/szprintf-posix-tests: Renamed from + modules/zsprintf-posix-tests. + All function names updated. + * lib/stdio.in.h, m4/stdio_h.m4, modules/stdio: Update module indicator + names. + 2024-06-29 Jim Meyering <meyering@meta.com> bootstrap-funclib.sh: shrink or split too-long lines diff --git a/lib/aszprintf.c b/lib/aszprintf.c new file mode 100644 index 0000000000..206bf743ea --- /dev/null +++ b/lib/aszprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings. + Copyright (C) 1999-2024 Free Software Foundation, Inc. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <stdio.h> + +#include <stdarg.h> + +ptrdiff_t +aszprintf (char **resultp, const char *format, ...) +{ + va_list args; + ptrdiff_t result; + + va_start (args, format); + result = vaszprintf (resultp, format, args); + va_end (args); + return result; +} diff --git a/lib/azsprintf.c b/lib/azsprintf.c deleted file mode 100644 index 9489854cb9..0000000000 --- a/lib/azsprintf.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999-2024 Free Software Foundation, Inc. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#include <stdarg.h> - -ptrdiff_t -azsprintf (char **resultp, const char *format, ...) -{ - va_list args; - ptrdiff_t result; - - va_start (args, format); - result = vazsprintf (resultp, format, args); - va_end (args); - return result; -} diff --git a/lib/c-aszprintf.c b/lib/c-aszprintf.c new file mode 100644 index 0000000000..59d10725ff --- /dev/null +++ b/lib/c-aszprintf.c @@ -0,0 +1,34 @@ +/* Formatted output to strings in C locale. + Copyright (C) 1999-2024 Free Software Foundation, Inc. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "c-vasprintf.h" + +#include <stdarg.h> + +ptrdiff_t +c_aszprintf (char **resultp, const char *format, ...) +{ + va_list args; + ptrdiff_t result; + + va_start (args, format); + result = c_vaszprintf (resultp, format, args); + va_end (args); + return result; +} diff --git a/lib/c-azsprintf.c b/lib/c-azsprintf.c deleted file mode 100644 index 78bc973ef5..0000000000 --- a/lib/c-azsprintf.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Formatted output to strings in C locale. - Copyright (C) 1999-2024 Free Software Foundation, Inc. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#include <config.h> - -/* Specification. */ -#include "c-vasprintf.h" - -#include <stdarg.h> - -ptrdiff_t -c_azsprintf (char **resultp, const char *format, ...) -{ - va_list args; - ptrdiff_t result; - - va_start (args, format); - result = c_vazsprintf (resultp, format, args); - va_end (args); - return result; -} diff --git a/lib/c-snprintf.c b/lib/c-snprintf.c index 658f3faed4..f768213ba2 100644 --- a/lib/c-snprintf.c +++ b/lib/c-snprintf.c @@ -33,7 +33,7 @@ c_snprintf (char *str, size_t size, const char *format, ...) ptrdiff_t ret; va_start (args, format); - ret = c_vzsnprintf (str, size, format, args); + ret = c_vsnzprintf (str, size, format, args); va_end (args); #if PTRDIFF_MAX > INT_MAX diff --git a/lib/c-snprintf.h b/lib/c-snprintf.h index f52e058e9e..8cd637d4dd 100644 --- a/lib/c-snprintf.h +++ b/lib/c-snprintf.h @@ -44,7 +44,7 @@ extern "C" { Formatting takes place in the C locale, that is, the decimal point used in floating-point formatting directives is always '.'. */ -extern ptrdiff_t c_zsnprintf (char *restrict str, size_t size, +extern ptrdiff_t c_snzprintf (char *restrict str, size_t size, const char *format, ...) _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4)); diff --git a/lib/c-snzprintf.c b/lib/c-snzprintf.c new file mode 100644 index 0000000000..c674af9814 --- /dev/null +++ b/lib/c-snzprintf.c @@ -0,0 +1,66 @@ +/* Formatted output to strings in C locale. + Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. + Written by Simon Josefsson and Paul Eggert. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "c-snprintf.h" + +#include <errno.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "c-vasnprintf.h" + +ptrdiff_t +c_snzprintf (char *str, size_t size, const char *format, ...) +{ + char *output; + size_t len; + size_t lenbuf = size; + va_list args; + + va_start (args, format); + output = c_vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + va_end (args); + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (len > PTRDIFF_MAX) + { + errno = ENOMEM; + return -1; + } + + return len; +} diff --git a/lib/c-vasprintf.h b/lib/c-vasprintf.h index bcd40bd5e0..048ecf0f62 100644 --- a/lib/c-vasprintf.h +++ b/lib/c-vasprintf.h @@ -47,9 +47,9 @@ extern "C" { Formatting takes place in the C locale, that is, the decimal point used in floating-point formatting directives is always '.'. */ -ptrdiff_t c_azsprintf (char **resultp, const char *format, ...) +ptrdiff_t c_aszprintf (char **resultp, const char *format, ...) _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3)); -ptrdiff_t c_vazsprintf (char **resultp, const char *format, va_list args) +ptrdiff_t c_vaszprintf (char **resultp, const char *format, va_list args) _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0)); /* Prints formatted output to a string dynamically allocated with malloc(). diff --git a/lib/c-vaszprintf.c b/lib/c-vaszprintf.c new file mode 100644 index 0000000000..a5ef6864ab --- /dev/null +++ b/lib/c-vaszprintf.c @@ -0,0 +1,46 @@ +/* Formatted output to strings in C locale. + Copyright (C) 1999-2024 Free Software Foundation, Inc. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include "c-vasprintf.h" + +#include <errno.h> +#include <stdint.h> +#include <stdlib.h> + +#include "c-vasnprintf.h" + +ptrdiff_t +c_vaszprintf (char **resultp, const char *format, va_list args) +{ + size_t length; + char *result = c_vasnprintf (NULL, &length, format, args); + if (result == NULL) + return -1; + + if (length > PTRDIFF_MAX) + { + free (result); + errno = ENOMEM; + return -1; + } + + *resultp = result; + /* Return the number of resulting bytes, excluding the trailing NUL. */ + return length; +} diff --git a/lib/c-vazsprintf.c b/lib/c-vazsprintf.c deleted file mode 100644 index 88ab938489..0000000000 --- a/lib/c-vazsprintf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Formatted output to strings in C locale. - Copyright (C) 1999-2024 Free Software Foundation, Inc. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#include <config.h> - -/* Specification. */ -#include "c-vasprintf.h" - -#include <errno.h> -#include <stdint.h> -#include <stdlib.h> - -#include "c-vasnprintf.h" - -ptrdiff_t -c_vazsprintf (char **resultp, const char *format, va_list args) -{ - size_t length; - char *result = c_vasnprintf (NULL, &length, format, args); - if (result == NULL) - return -1; - - if (length > PTRDIFF_MAX) - { - free (result); - errno = ENOMEM; - return -1; - } - - *resultp = result; - /* Return the number of resulting bytes, excluding the trailing NUL. */ - return length; -} diff --git a/lib/c-vsnprintf.c b/lib/c-vsnprintf.c index 941c2d4609..aee05c2be2 100644 --- a/lib/c-vsnprintf.c +++ b/lib/c-vsnprintf.c @@ -29,7 +29,7 @@ int c_vsnprintf (char *str, size_t size, const char *format, va_list args) { - ptrdiff_t ret = c_vzsnprintf (str, size, format, args); + ptrdiff_t ret = c_vsnzprintf (str, size, format, args); #if PTRDIFF_MAX > INT_MAX if (ret > INT_MAX) diff --git a/lib/c-vsnprintf.h b/lib/c-vsnprintf.h index ff9cc2250c..2615118335 100644 --- a/lib/c-vsnprintf.h +++ b/lib/c-vsnprintf.h @@ -47,7 +47,7 @@ extern "C" { Formatting takes place in the C locale, that is, the decimal point used in floating-point formatting directives is always '.'. */ -extern ptrdiff_t c_vzsnprintf (char *restrict str, size_t size, +extern ptrdiff_t c_vsnzprintf (char *restrict str, size_t size, const char *format, va_list args) _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0)); diff --git a/lib/c-vsnzprintf.c b/lib/c-vsnzprintf.c new file mode 100644 index 0000000000..28f7e4fa85 --- /dev/null +++ b/lib/c-vsnzprintf.c @@ -0,0 +1,66 @@ +/* Formatted output to strings in C locale. + Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. + Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. + Modified for C locale by Ben Pfaff. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/* Specification. */ +#include "c-vsnprintf.h" + +#include <errno.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "c-vasnprintf.h" + +ptrdiff_t +c_vsnzprintf (char *str, size_t size, const char *format, va_list args) +{ + char *output; + size_t len; + size_t lenbuf = size; + + output = c_vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (len > PTRDIFF_MAX) + { + errno = ENOMEM; + return -1; + } + + return len; +} diff --git a/lib/c-vzsnprintf.c b/lib/c-vzsnprintf.c deleted file mode 100644 index 948266dd99..0000000000 --- a/lib/c-vzsnprintf.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Formatted output to strings in C locale. - Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. - Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. - Modified for C locale by Ben Pfaff. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#include "c-vsnprintf.h" - -#include <errno.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "c-vasnprintf.h" - -ptrdiff_t -c_vzsnprintf (char *str, size_t size, const char *format, va_list args) -{ - char *output; - size_t len; - size_t lenbuf = size; - - output = c_vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - - if (!output) - return -1; - - if (output != str) - { - if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } - - free (output); - } - - if (len > PTRDIFF_MAX) - { - errno = ENOMEM; - return -1; - } - - return len; -} diff --git a/lib/c-xvasprintf.c b/lib/c-xvasprintf.c index b058bde4c5..f4c77d4a00 100644 --- a/lib/c-xvasprintf.c +++ b/lib/c-xvasprintf.c @@ -32,7 +32,7 @@ c_xvasprintf (const char *format, va_list args) { char *result; - if (c_vazsprintf (&result, format, args) < 0) + if (c_vaszprintf (&result, format, args) < 0) { if (errno == ENOMEM) xalloc_die (); diff --git a/lib/c-zsnprintf.c b/lib/c-zsnprintf.c deleted file mode 100644 index 85ed3f9191..0000000000 --- a/lib/c-zsnprintf.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Formatted output to strings in C locale. - Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. - Written by Simon Josefsson and Paul Eggert. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#include <config.h> - -/* Specification. */ -#include "c-snprintf.h" - -#include <errno.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "c-vasnprintf.h" - -ptrdiff_t -c_zsnprintf (char *str, size_t size, const char *format, ...) -{ - char *output; - size_t len; - size_t lenbuf = size; - va_list args; - - va_start (args, format); - output = c_vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - va_end (args); - - if (!output) - return -1; - - if (output != str) - { - if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } - - free (output); - } - - if (len > PTRDIFF_MAX) - { - errno = ENOMEM; - return -1; - } - - return len; -} diff --git a/lib/snprintf.c b/lib/snprintf.c index 80f69225ac..b82f782a9d 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c @@ -31,7 +31,7 @@ snprintf (char *str, size_t size, const char *format, ...) ptrdiff_t ret; va_start (args, format); - ret = vzsnprintf (str, size, format, args); + ret = vsnzprintf (str, size, format, args); va_end (args); #if PTRDIFF_MAX > INT_MAX diff --git a/lib/snzprintf.c b/lib/snzprintf.c new file mode 100644 index 0000000000..b786914a1c --- /dev/null +++ b/lib/snzprintf.c @@ -0,0 +1,66 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. + Written by Simon Josefsson and Paul Eggert. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <stdio.h> + +#include <errno.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "vasnprintf.h" + +ptrdiff_t +snzprintf (char *str, size_t size, const char *format, ...) +{ + char *output; + size_t len; + size_t lenbuf = size; + va_list args; + + va_start (args, format); + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + va_end (args); + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (len > PTRDIFF_MAX) + { + errno = ENOMEM; + return -1; + } + + return len; +} diff --git a/lib/sprintf.c b/lib/sprintf.c index d781b8c7b5..fb861b87e6 100644 --- a/lib/sprintf.c +++ b/lib/sprintf.c @@ -33,7 +33,7 @@ sprintf (char *str, const char *format, ...) ptrdiff_t ret; va_start (args, format); - ret = vzsprintf (str, format, args); + ret = vszprintf (str, format, args); va_end (args); #if PTRDIFF_MAX > INT_MAX diff --git a/lib/stdio.in.h b/lib/stdio.in.h index cf2d8c999b..bcae688b78 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -1459,7 +1459,7 @@ _GL_CXXALIASWARN (scanf); # endif #endif -#if @GNULIB_ZSNPRINTF@ +#if @GNULIB_SNZPRINTF@ /* Prints formatted output to string STR. Similar to sprintf, but the additional parameter SIZE limits how much is written into STR. STR may be NULL, in which case nothing will be written. @@ -1468,12 +1468,12 @@ _GL_CXXALIASWARN (scanf); Failure code EOVERFLOW can only occur when a width > INT_MAX is used. Therefore, if the format string is valid and does not use %ls/%lc directives nor widths, the only possible failure code is ENOMEM. */ -_GL_FUNCDECL_SYS (zsnprintf, ptrdiff_t, +_GL_FUNCDECL_SYS (snzprintf, ptrdiff_t, (char *restrict str, size_t size, const char *restrict format, ...) _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4) _GL_ARG_NONNULL ((3))); -_GL_CXXALIAS_SYS (zsnprintf, ptrdiff_t, +_GL_CXXALIAS_SYS (snzprintf, ptrdiff_t, (char *restrict str, size_t size, const char *restrict format, ...)); #endif @@ -1520,19 +1520,19 @@ _GL_WARN_ON_USE (snprintf, "snprintf is unportable - " # endif #endif -#if @GNULIB_ZSPRINTF@ +#if @GNULIB_SZPRINTF@ /* Prints formatted output to string STR. Returns the string length of the formatted string. Upon failure, returns -1 with errno set. Failure code EOVERFLOW can only occur when a width > INT_MAX is used. Therefore, if the format string is valid and does not use %ls/%lc directives nor widths, the only possible failure code is ENOMEM. */ -_GL_FUNCDECL_SYS (zsprintf, ptrdiff_t, +_GL_FUNCDECL_SYS (szprintf, ptrdiff_t, (char *restrict str, const char *restrict format, ...) _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_SYS (zsprintf, ptrdiff_t, +_GL_CXXALIAS_SYS (szprintf, ptrdiff_t, (char *restrict str, const char *restrict format, ...)); #endif @@ -1629,7 +1629,7 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " # endif #endif -#if @GNULIB_VAZSPRINTF@ +#if @GNULIB_VASZPRINTF@ /* Prints formatted output to a string dynamically allocated with malloc(). If the memory allocation succeeds, it stores the address of the string in *RESULT and returns the number of resulting bytes, excluding the trailing @@ -1638,17 +1638,17 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " Failure code EOVERFLOW can only occur when a width > INT_MAX is used. Therefore, if the format string is valid and does not use %ls/%lc directives nor widths, the only possible failure code is ENOMEM. */ -_GL_FUNCDECL_SYS (azsprintf, ptrdiff_t, +_GL_FUNCDECL_SYS (aszprintf, ptrdiff_t, (char **result, const char *format, ...) _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_SYS (azsprintf, ptrdiff_t, +_GL_CXXALIAS_SYS (aszprintf, ptrdiff_t, (char **result, const char *format, ...)); -_GL_FUNCDECL_SYS (vazsprintf, ptrdiff_t, +_GL_FUNCDECL_SYS (vaszprintf, ptrdiff_t, (char **result, const char *format, va_list args) _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_SYS (vazsprintf, ptrdiff_t, +_GL_CXXALIAS_SYS (vaszprintf, ptrdiff_t, (char **result, const char *format, va_list args)); #endif @@ -1862,7 +1862,7 @@ _GL_CXXALIASWARN (vscanf); # endif #endif -#if @GNULIB_VZSNPRINTF@ +#if @GNULIB_VSNZPRINTF@ /* Prints formatted output to string STR. Similar to sprintf, but the additional parameter SIZE limits how much is written into STR. STR may be NULL, in which case nothing will be written. @@ -1871,12 +1871,12 @@ _GL_CXXALIASWARN (vscanf); Failure code EOVERFLOW can only occur when a width > INT_MAX is used. Therefore, if the format string is valid and does not use %ls/%lc directives nor widths, the only possible failure code is ENOMEM. */ -_GL_FUNCDECL_SYS (vzsnprintf, ptrdiff_t, +_GL_FUNCDECL_SYS (vsnzprintf, ptrdiff_t, (char *restrict str, size_t size, const char *restrict format, va_list args) _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))); -_GL_CXXALIAS_SYS (vzsnprintf, ptrdiff_t, +_GL_CXXALIAS_SYS (vsnzprintf, ptrdiff_t, (char *restrict str, size_t size, const char *restrict format, va_list args)); #endif @@ -1923,19 +1923,19 @@ _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - " # endif #endif -#if @GNULIB_VZSPRINTF@ +#if @GNULIB_VSZPRINTF@ /* Prints formatted output to string STR. Returns the string length of the formatted string. Upon failure, returns -1 with errno set. Failure code EOVERFLOW can only occur when a width > INT_MAX is used. Therefore, if the format string is valid and does not use %ls/%lc directives nor widths, the only possible failure code is ENOMEM. */ -_GL_FUNCDECL_SYS (vzsprintf, ptrdiff_t, +_GL_FUNCDECL_SYS (vszprintf, ptrdiff_t, (char *restrict str, const char *restrict format, va_list args) _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); -_GL_CXXALIAS_SYS (vzsprintf, ptrdiff_t, +_GL_CXXALIAS_SYS (vszprintf, ptrdiff_t, (char *restrict str, const char *restrict format, va_list args)); #endif diff --git a/lib/szprintf.c b/lib/szprintf.c new file mode 100644 index 0000000000..c5f07dec25 --- /dev/null +++ b/lib/szprintf.c @@ -0,0 +1,67 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. + + This file 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 3 of the + License, or (at your option) any later version. + + This file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/* Specification. */ +#include <stdio.h> + +#include <errno.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> + +#include "vasnprintf.h" + +ptrdiff_t +szprintf (char *str, const char *format, ...) +{ + char *output; + size_t len; + size_t lenbuf; + va_list args; + + /* Set lenbuf = min (SIZE_MAX, - (uintptr_t) str - 1). */ + lenbuf = SIZE_MAX; + if (lenbuf >= ~ (uintptr_t) str) + lenbuf = ~ (uintptr_t) str; + + va_start (args, format); + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + va_end (args); + + if (!output) + return -1; + + if (output != str) + { + /* len is near SIZE_MAX. */ + free (output); + errno = ENOMEM; + return -1; + } + + if (len > PTRDIFF_MAX) + { + errno = ENOMEM; + return -1; + } + + return len; +} diff --git a/lib/vaszprintf.c b/lib/vaszprintf.c new file mode 100644 index 0000000000..7589fbe607 --- /dev/null +++ b/lib/vaszprintf.c @@ -0,0 +1,46 @@ +/* Formatted output to strings. + Copyright (C) 1999-2024 Free Software Foundation, Inc. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <stdio.h> + +#include <errno.h> +#include <stdint.h> +#include <stdlib.h> + +#include "vasnprintf.h" + +ptrdiff_t +vaszprintf (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 > PTRDIFF_MAX) + { + free (result); + errno = ENOMEM; + return -1; + } + + *resultp = result; + /* Return the number of resulting bytes, excluding the trailing NUL. */ + return length; +} diff --git a/lib/vazsprintf.c b/lib/vazsprintf.c deleted file mode 100644 index 73002a17d5..0000000000 --- a/lib/vazsprintf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 1999-2024 Free Software Foundation, Inc. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <stdint.h> -#include <stdlib.h> - -#include "vasnprintf.h" - -ptrdiff_t -vazsprintf (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 > PTRDIFF_MAX) - { - free (result); - errno = ENOMEM; - return -1; - } - - *resultp = result; - /* Return the number of resulting bytes, excluding the trailing NUL. */ - return length; -} diff --git a/lib/vsnprintf.c b/lib/vsnprintf.c index 1954dcea26..cfcee78b86 100644 --- a/lib/vsnprintf.c +++ b/lib/vsnprintf.c @@ -29,7 +29,7 @@ int vsnprintf (char *str, size_t size, const char *format, va_list args) { - ptrdiff_t ret = vzsnprintf (str, size, format, args); + ptrdiff_t ret = vsnzprintf (str, size, format, args); #if PTRDIFF_MAX > INT_MAX if (ret > INT_MAX) diff --git a/lib/vsnzprintf.c b/lib/vsnzprintf.c new file mode 100644 index 0000000000..f598526c80 --- /dev/null +++ b/lib/vsnzprintf.c @@ -0,0 +1,65 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. + Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. + + This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/* Specification. */ +#include <stdio.h> + +#include <errno.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#include "vasnprintf.h" + +ptrdiff_t +vsnzprintf (char *str, size_t size, const char *format, va_list args) +{ + char *output; + size_t len; + size_t lenbuf = size; + + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + + if (!output) + return -1; + + if (output != str) + { + if (size) + { + size_t pruned_len = (len < size ? len : size - 1); + memcpy (str, output, pruned_len); + str[pruned_len] = '\0'; + } + + free (output); + } + + if (len > PTRDIFF_MAX) + { + errno = ENOMEM; + return -1; + } + + return len; +} diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 065ed74222..ec7c8da4f8 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -29,7 +29,7 @@ int vsprintf (char *str, const char *format, va_list args) { - ptrdiff_t ret = vzsprintf (str, format, args); + ptrdiff_t ret = vszprintf (str, format, args); #if PTRDIFF_MAX > INT_MAX if (ret > INT_MAX) diff --git a/lib/vszprintf.c b/lib/vszprintf.c new file mode 100644 index 0000000000..f980d1ec3e --- /dev/null +++ b/lib/vszprintf.c @@ -0,0 +1,64 @@ +/* Formatted output to strings. + Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. + + This file 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 3 of the + License, or (at your option) any later version. + + This file 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 program. If not, see <https://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/* Specification. */ +#include <stdio.h> + +#include <errno.h> +#include <stdarg.h> +#include <stdint.h> +#include <stdlib.h> + +#include "vasnprintf.h" + +ptrdiff_t +vszprintf (char *str, const char *format, va_list args) +{ + char *output; + size_t len; + size_t lenbuf; + + /* Set lenbuf = min (SIZE_MAX, - (uintptr_t) str - 1). */ + lenbuf = SIZE_MAX; + if (lenbuf >= ~ (uintptr_t) str) + lenbuf = ~ (uintptr_t) str; + + output = vasnprintf (str, &lenbuf, format, args); + len = lenbuf; + + if (!output) + return -1; + + if (output != str) + { + /* len is near SIZE_MAX. */ + free (output); + errno = ENOMEM; + return -1; + } + + if (len > PTRDIFF_MAX) + { + errno = ENOMEM; + return -1; + } + + return len; +} diff --git a/lib/vzsnprintf.c b/lib/vzsnprintf.c deleted file mode 100644 index 96e240bdb7..0000000000 --- a/lib/vzsnprintf.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. - Written by Simon Josefsson and Yoann Vandoorselaere <yoann@prelude-ids.org>. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "vasnprintf.h" - -ptrdiff_t -vzsnprintf (char *str, size_t size, const char *format, va_list args) -{ - char *output; - size_t len; - size_t lenbuf = size; - - output = vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - - if (!output) - return -1; - - if (output != str) - { - if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } - - free (output); - } - - if (len > PTRDIFF_MAX) - { - errno = ENOMEM; - return -1; - } - - return len; -} diff --git a/lib/vzsprintf.c b/lib/vzsprintf.c deleted file mode 100644 index 549543070c..0000000000 --- a/lib/vzsprintf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. - - This file 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 3 of the - License, or (at your option) any later version. - - This file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdlib.h> - -#include "vasnprintf.h" - -ptrdiff_t -vzsprintf (char *str, const char *format, va_list args) -{ - char *output; - size_t len; - size_t lenbuf; - - /* Set lenbuf = min (SIZE_MAX, - (uintptr_t) str - 1). */ - lenbuf = SIZE_MAX; - if (lenbuf >= ~ (uintptr_t) str) - lenbuf = ~ (uintptr_t) str; - - output = vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - - if (!output) - return -1; - - if (output != str) - { - /* len is near SIZE_MAX. */ - free (output); - errno = ENOMEM; - return -1; - } - - if (len > PTRDIFF_MAX) - { - errno = ENOMEM; - return -1; - } - - return len; -} diff --git a/lib/xvasprintf.c b/lib/xvasprintf.c index 97f24eb297..6aba32c09a 100644 --- a/lib/xvasprintf.c +++ b/lib/xvasprintf.c @@ -96,7 +96,7 @@ xvasprintf (const char *format, va_list args) } } - if (vazsprintf (&result, format, args) < 0) + if (vaszprintf (&result, format, args) < 0) { if (errno == ENOMEM) xalloc_die (); diff --git a/lib/zsnprintf.c b/lib/zsnprintf.c deleted file mode 100644 index 894631d16a..0000000000 --- a/lib/zsnprintf.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. - Written by Simon Josefsson and Paul Eggert. - - This file 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 file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#include <config.h> - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -#include "vasnprintf.h" - -ptrdiff_t -zsnprintf (char *str, size_t size, const char *format, ...) -{ - char *output; - size_t len; - size_t lenbuf = size; - va_list args; - - va_start (args, format); - output = vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - va_end (args); - - if (!output) - return -1; - - if (output != str) - { - if (size) - { - size_t pruned_len = (len < size ? len : size - 1); - memcpy (str, output, pruned_len); - str[pruned_len] = '\0'; - } - - free (output); - } - - if (len > PTRDIFF_MAX) - { - errno = ENOMEM; - return -1; - } - - return len; -} diff --git a/lib/zsprintf.c b/lib/zsprintf.c deleted file mode 100644 index f004ed7238..0000000000 --- a/lib/zsprintf.c +++ /dev/null @@ -1,67 +0,0 @@ -/* Formatted output to strings. - Copyright (C) 2004, 2006-2024 Free Software Foundation, Inc. - - This file 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 3 of the - License, or (at your option) any later version. - - This file 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 program. If not, see <https://www.gnu.org/licenses/>. */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -/* Specification. */ -#include <stdio.h> - -#include <errno.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdlib.h> - -#include "vasnprintf.h" - -ptrdiff_t -zsprintf (char *str, const char *format, ...) -{ - char *output; - size_t len; - size_t lenbuf; - va_list args; - - /* Set lenbuf = min (SIZE_MAX, - (uintptr_t) str - 1). */ - lenbuf = SIZE_MAX; - if (lenbuf >= ~ (uintptr_t) str) - lenbuf = ~ (uintptr_t) str; - - va_start (args, format); - output = vasnprintf (str, &lenbuf, format, args); - len = lenbuf; - va_end (args); - - if (!output) - return -1; - - if (output != str) - { - /* len is near SIZE_MAX. */ - free (output); - errno = ENOMEM; - return -1; - } - - if (len > PTRDIFF_MAX) - { - errno = ENOMEM; - return -1; - } - - return len; -} diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index 10e1fbb8aa..f3edc43ccd 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -178,7 +178,7 @@ AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF]) - gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VAZSPRINTF]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASZPRINTF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF]) @@ -188,10 +188,10 @@ AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS], gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX]) - gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VZSNPRINTF]) - gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VZSPRINTF]) - gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ZSNPRINTF]) - gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ZSPRINTF]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNZPRINTF]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSZPRINTF]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNZPRINTF]) + gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SZPRINTF]) dnl Support Microsoft deprecated alias function names by default. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1]) gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1]) diff --git a/modules/c-snprintf b/modules/c-snprintf index 49857beca7..19a054dcbe 100644 --- a/modules/c-snprintf +++ b/modules/c-snprintf @@ -8,7 +8,7 @@ lib/c-snprintf.c Depends-on: stdint stdio -c-vzsnprintf +c-vsnzprintf configure.ac: AC_REQUIRE([AC_C_RESTRICT]) diff --git a/modules/c-snzprintf b/modules/c-snzprintf new file mode 100644 index 0000000000..83c2cd83a7 --- /dev/null +++ b/modules/c-snzprintf @@ -0,0 +1,27 @@ +Description: +c_snzprintf(): print formatted output to a fixed length string (without +INT_MAX limitation) in C locale + +Files: +lib/c-snprintf.h +lib/c-snzprintf.c + +Depends-on: +stdint +stdio +c-vasnprintf + +configure.ac: +AC_REQUIRE([AC_C_RESTRICT]) + +Makefile.am: +lib_SOURCES += c-snzprintf.c + +Include: +"c-snprintf.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-snzprintf-gnu b/modules/c-snzprintf-gnu new file mode 100644 index 0000000000..ff4d2c599d --- /dev/null +++ b/modules/c-snzprintf-gnu @@ -0,0 +1,23 @@ +Description: +c_snzprintf() function +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +c-snzprintf +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +"c-snprintf.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-snzprintf-gnu-tests b/modules/c-snzprintf-gnu-tests new file mode 100644 index 0000000000..ce574fc3a2 --- /dev/null +++ b/modules/c-snzprintf-gnu-tests @@ -0,0 +1,19 @@ +Files: +tests/test-c-snzprintf-gnu.c +tests/test-snzprintf-gnu.h +tests/test-c-snzprintf-gnu.sh +tests/macros.h +m4/locale-fr.m4 +m4/codeset.m4 + +Depends-on: +setlocale + +configure.ac: +gt_LOCALE_FR + +Makefile.am: +TESTS += test-c-snzprintf-gnu.sh +TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' +check_PROGRAMS += test-c-snzprintf-gnu +test_c_snzprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/c-vaszprintf b/modules/c-vaszprintf new file mode 100644 index 0000000000..da7df0d7be --- /dev/null +++ b/modules/c-vaszprintf @@ -0,0 +1,26 @@ +Description: +aszprintf() and vaszprintf() in C locale + +Files: +lib/c-vasprintf.h +lib/c-aszprintf.c +lib/c-vaszprintf.c + +Depends-on: +stdint +stdio +c-vasnprintf + +configure.ac: + +Makefile.am: +lib_SOURCES += c-aszprintf.c c-vaszprintf.c + +Include: +"c-vasprintf.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-vaszprintf-gnu b/modules/c-vaszprintf-gnu new file mode 100644 index 0000000000..acee07d3b8 --- /dev/null +++ b/modules/c-vaszprintf-gnu @@ -0,0 +1,23 @@ +Description: +c_aszprintf() and c_vaszprintf() functions +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +c-vaszprintf +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +"c-vasprintf.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-vaszprintf-gnu-tests b/modules/c-vaszprintf-gnu-tests new file mode 100644 index 0000000000..56565cda42 --- /dev/null +++ b/modules/c-vaszprintf-gnu-tests @@ -0,0 +1,19 @@ +Files: +tests/test-c-vaszprintf-gnu.c +tests/test-vaszprintf-gnu.h +tests/test-c-vaszprintf-gnu.sh +tests/macros.h +m4/locale-fr.m4 +m4/codeset.m4 + +Depends-on: +setlocale + +configure.ac: +gt_LOCALE_FR + +Makefile.am: +TESTS += test-c-vaszprintf-gnu.sh +TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' +check_PROGRAMS += test-c-vaszprintf-gnu +test_c_vaszprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/c-vazsprintf b/modules/c-vazsprintf deleted file mode 100644 index 5cea385926..0000000000 --- a/modules/c-vazsprintf +++ /dev/null @@ -1,26 +0,0 @@ -Description: -azsprintf() and vazsprintf() in C locale - -Files: -lib/c-vasprintf.h -lib/c-azsprintf.c -lib/c-vazsprintf.c - -Depends-on: -stdint -stdio -c-vasnprintf - -configure.ac: - -Makefile.am: -lib_SOURCES += c-azsprintf.c c-vazsprintf.c - -Include: -"c-vasprintf.h" - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/c-vazsprintf-gnu b/modules/c-vazsprintf-gnu deleted file mode 100644 index 46690f4ddb..0000000000 --- a/modules/c-vazsprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -c_azsprintf() and c_vazsprintf() functions -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -c-vazsprintf -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -"c-vasprintf.h" - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/c-vazsprintf-gnu-tests b/modules/c-vazsprintf-gnu-tests deleted file mode 100644 index a7c5762b9c..0000000000 --- a/modules/c-vazsprintf-gnu-tests +++ /dev/null @@ -1,19 +0,0 @@ -Files: -tests/test-c-vazsprintf-gnu.c -tests/test-vazsprintf-gnu.h -tests/test-c-vazsprintf-gnu.sh -tests/macros.h -m4/locale-fr.m4 -m4/codeset.m4 - -Depends-on: -setlocale - -configure.ac: -gt_LOCALE_FR - -Makefile.am: -TESTS += test-c-vazsprintf-gnu.sh -TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' -check_PROGRAMS += test-c-vazsprintf-gnu -test_c_vazsprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/c-vsnprintf b/modules/c-vsnprintf index 835968f96a..9ba2b3657a 100644 --- a/modules/c-vsnprintf +++ b/modules/c-vsnprintf @@ -9,7 +9,7 @@ lib/c-vsnprintf.c Depends-on: stdint stdio -c-vzsnprintf +c-vsnzprintf configure.ac: AC_REQUIRE([AC_C_RESTRICT]) diff --git a/modules/c-vsnzprintf b/modules/c-vsnzprintf new file mode 100644 index 0000000000..9d56f9cdbe --- /dev/null +++ b/modules/c-vsnzprintf @@ -0,0 +1,27 @@ +Description: +c_vsnzprintf(): print formatted output from an stdarg argument list to a +fixed length string (without INT_MAX limitation) in C locale + +Files: +lib/c-vsnprintf.h +lib/c-vsnzprintf.c + +Depends-on: +stdint +stdio +c-vasnprintf + +configure.ac: +AC_REQUIRE([AC_C_RESTRICT]) + +Makefile.am: +lib_SOURCES += c-vsnzprintf.c + +Include: +"c-vsnprintf.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-vsnzprintf-gnu b/modules/c-vsnzprintf-gnu new file mode 100644 index 0000000000..0bebe833ca --- /dev/null +++ b/modules/c-vsnzprintf-gnu @@ -0,0 +1,23 @@ +Description: +c_vsnzprintf() function +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +c-vsnzprintf +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +"c-vsnprintf.h" + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/c-vsnzprintf-gnu-tests b/modules/c-vsnzprintf-gnu-tests new file mode 100644 index 0000000000..c731225056 --- /dev/null +++ b/modules/c-vsnzprintf-gnu-tests @@ -0,0 +1,19 @@ +Files: +tests/test-c-vsnzprintf-gnu.c +tests/test-snzprintf-gnu.h +tests/test-c-vsnzprintf-gnu.sh +tests/macros.h +m4/locale-fr.m4 +m4/codeset.m4 + +Depends-on: +setlocale + +configure.ac: +gt_LOCALE_FR + +Makefile.am: +TESTS += test-c-vsnzprintf-gnu.sh +TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' +check_PROGRAMS += test-c-vsnzprintf-gnu +test_c_vsnzprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/c-vzsnprintf b/modules/c-vzsnprintf deleted file mode 100644 index 4049974f4a..0000000000 --- a/modules/c-vzsnprintf +++ /dev/null @@ -1,27 +0,0 @@ -Description: -c_vzsnprintf(): print formatted output from an stdarg argument list to a -fixed length string (without INT_MAX limitation) in C locale - -Files: -lib/c-vsnprintf.h -lib/c-vzsnprintf.c - -Depends-on: -stdint -stdio -c-vasnprintf - -configure.ac: -AC_REQUIRE([AC_C_RESTRICT]) - -Makefile.am: -lib_SOURCES += c-vzsnprintf.c - -Include: -"c-vsnprintf.h" - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/c-vzsnprintf-gnu b/modules/c-vzsnprintf-gnu deleted file mode 100644 index 9a02c1d847..0000000000 --- a/modules/c-vzsnprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -c_vzsnprintf() function -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -c-vzsnprintf -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -"c-vsnprintf.h" - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/c-vzsnprintf-gnu-tests b/modules/c-vzsnprintf-gnu-tests deleted file mode 100644 index 044c5f25ec..0000000000 --- a/modules/c-vzsnprintf-gnu-tests +++ /dev/null @@ -1,19 +0,0 @@ -Files: -tests/test-c-vzsnprintf-gnu.c -tests/test-zsnprintf-gnu.h -tests/test-c-vzsnprintf-gnu.sh -tests/macros.h -m4/locale-fr.m4 -m4/codeset.m4 - -Depends-on: -setlocale - -configure.ac: -gt_LOCALE_FR - -Makefile.am: -TESTS += test-c-vzsnprintf-gnu.sh -TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' -check_PROGRAMS += test-c-vzsnprintf-gnu -test_c_vzsnprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/c-xvasprintf b/modules/c-xvasprintf index ccbc93d794..a46e418544 100644 --- a/modules/c-xvasprintf +++ b/modules/c-xvasprintf @@ -10,7 +10,7 @@ m4/strerrorname_np.m4 Depends-on: extensions stdio -c-vazsprintf +c-vaszprintf xalloc-die configure.ac: diff --git a/modules/c-zsnprintf b/modules/c-zsnprintf deleted file mode 100644 index 5410db03cd..0000000000 --- a/modules/c-zsnprintf +++ /dev/null @@ -1,27 +0,0 @@ -Description: -c_zsnprintf(): print formatted output to a fixed length string (without -INT_MAX limitation) in C locale - -Files: -lib/c-snprintf.h -lib/c-zsnprintf.c - -Depends-on: -stdint -stdio -c-vasnprintf - -configure.ac: -AC_REQUIRE([AC_C_RESTRICT]) - -Makefile.am: -lib_SOURCES += c-zsnprintf.c - -Include: -"c-snprintf.h" - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/c-zsnprintf-gnu b/modules/c-zsnprintf-gnu deleted file mode 100644 index 1955098d4a..0000000000 --- a/modules/c-zsnprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -c_zsnprintf() function -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -c-zsnprintf -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -"c-snprintf.h" - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/c-zsnprintf-gnu-tests b/modules/c-zsnprintf-gnu-tests deleted file mode 100644 index 6ae7df356d..0000000000 --- a/modules/c-zsnprintf-gnu-tests +++ /dev/null @@ -1,19 +0,0 @@ -Files: -tests/test-c-zsnprintf-gnu.c -tests/test-zsnprintf-gnu.h -tests/test-c-zsnprintf-gnu.sh -tests/macros.h -m4/locale-fr.m4 -m4/codeset.m4 - -Depends-on: -setlocale - -configure.ac: -gt_LOCALE_FR - -Makefile.am: -TESTS += test-c-zsnprintf-gnu.sh -TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@' -check_PROGRAMS += test-c-zsnprintf-gnu -test_c_zsnprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB) diff --git a/modules/snprintf b/modules/snprintf index cd4eb6b2c4..b44fc9a6ea 100644 --- a/modules/snprintf +++ b/modules/snprintf @@ -10,7 +10,7 @@ Depends-on: stdio errno [test $ac_cv_func_snprintf = no || test $REPLACE_SNPRINTF = 1] stdint [test $ac_cv_func_snprintf = no || test $REPLACE_SNPRINTF = 1] -vzsnprintf [test $ac_cv_func_snprintf = no || test $REPLACE_SNPRINTF = 1] +vsnzprintf [test $ac_cv_func_snprintf = no || test $REPLACE_SNPRINTF = 1] configure.ac: gl_FUNC_SNPRINTF diff --git a/modules/snzprintf b/modules/snzprintf new file mode 100644 index 0000000000..9d81fc4ca1 --- /dev/null +++ b/modules/snzprintf @@ -0,0 +1,27 @@ +Description: +snzprintf() function: print formatted output to a fixed length string +(without INT_MAX limitation) + +Files: +lib/snzprintf.c + +Depends-on: +stdio +vasnprintf +errno +stdint + +configure.ac: +gl_STDIO_MODULE_INDICATOR([snzprintf]) + +Makefile.am: +lib_SOURCES += snzprintf.c + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/snzprintf-gnu b/modules/snzprintf-gnu new file mode 100644 index 0000000000..d2aa9e5359 --- /dev/null +++ b/modules/snzprintf-gnu @@ -0,0 +1,23 @@ +Description: +snzprintf() function +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +snzprintf-posix +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/snzprintf-gnu-tests b/modules/snzprintf-gnu-tests new file mode 100644 index 0000000000..662795cdff --- /dev/null +++ b/modules/snzprintf-gnu-tests @@ -0,0 +1,12 @@ +Files: +tests/test-snzprintf-gnu.c +tests/test-snzprintf-gnu.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-snzprintf-gnu +check_PROGRAMS += test-snzprintf-gnu diff --git a/modules/snzprintf-posix b/modules/snzprintf-posix new file mode 100644 index 0000000000..c181159ce9 --- /dev/null +++ b/modules/snzprintf-posix @@ -0,0 +1,22 @@ +Description: +snzprintf() function with POSIX compliant format string interpretation + +Files: + +Depends-on: +snzprintf +mixin/printf-posix + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/snzprintf-posix-tests b/modules/snzprintf-posix-tests new file mode 100644 index 0000000000..bafb886c07 --- /dev/null +++ b/modules/snzprintf-posix-tests @@ -0,0 +1,14 @@ +Files: +tests/test-snzprintf-posix.c +tests/test-snzprintf-posix.h +tests/infinity.h +tests/macros.h + +Depends-on: +nan + +configure.ac: + +Makefile.am: +TESTS += test-snzprintf-posix +check_PROGRAMS += test-snzprintf-posix diff --git a/modules/sprintf-posix b/modules/sprintf-posix index 2c47424bec..682043847f 100644 --- a/modules/sprintf-posix +++ b/modules/sprintf-posix @@ -18,7 +18,7 @@ stdio nocrash printf-safe multiarch -vzsprintf [test $REPLACE_SPRINTF = 1] +vszprintf [test $REPLACE_SPRINTF = 1] mixin/printf-posix [test $REPLACE_SPRINTF = 1] stdint [test $REPLACE_SPRINTF = 1] errno [test $REPLACE_SPRINTF = 1] diff --git a/modules/stdio b/modules/stdio index 64fdc5fb60..319309828f 100644 --- a/modules/stdio +++ b/modules/stdio @@ -113,7 +113,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GNULIB_STDIO_H_SIGPIPE)/g' \ -e 's/@''GNULIB_TMPFILE''@/$(GNULIB_TMPFILE)/g' \ -e 's/@''GNULIB_VASPRINTF''@/$(GNULIB_VASPRINTF)/g' \ - -e 's/@''GNULIB_VAZSPRINTF''@/$(GNULIB_VAZSPRINTF)/g' \ + -e 's/@''GNULIB_VASZPRINTF''@/$(GNULIB_VASZPRINTF)/g' \ -e 's/@''GNULIB_VDPRINTF''@/$(GNULIB_VDPRINTF)/g' \ -e 's/@''GNULIB_VFPRINTF''@/$(GNULIB_VFPRINTF)/g' \ -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GNULIB_VFPRINTF_POSIX)/g' \ @@ -123,10 +123,10 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GNULIB_VPRINTF_POSIX)/g' \ -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \ -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \ - -e 's/@''GNULIB_VZSNPRINTF''@/$(GNULIB_VZSNPRINTF)/g' \ - -e 's/@''GNULIB_VZSPRINTF''@/$(GNULIB_VZSPRINTF)/g' \ - -e 's/@''GNULIB_ZSNPRINTF''@/$(GNULIB_ZSNPRINTF)/g' \ - -e 's/@''GNULIB_ZSPRINTF''@/$(GNULIB_ZSPRINTF)/g' \ + -e 's/@''GNULIB_VSNZPRINTF''@/$(GNULIB_VSNZPRINTF)/g' \ + -e 's/@''GNULIB_VSZPRINTF''@/$(GNULIB_VSZPRINTF)/g' \ + -e 's/@''GNULIB_SNZPRINTF''@/$(GNULIB_SNZPRINTF)/g' \ + -e 's/@''GNULIB_SZPRINTF''@/$(GNULIB_SZPRINTF)/g' \ -e 's/@''GNULIB_MDA_FCLOSEALL''@/$(GNULIB_MDA_FCLOSEALL)/g' \ -e 's/@''GNULIB_MDA_FDOPEN''@/$(GNULIB_MDA_FDOPEN)/g' \ -e 's/@''GNULIB_MDA_FILENO''@/$(GNULIB_MDA_FILENO)/g' \ diff --git a/modules/szprintf b/modules/szprintf new file mode 100644 index 0000000000..1e647c20b7 --- /dev/null +++ b/modules/szprintf @@ -0,0 +1,27 @@ +Description: +szprintf() function: print formatted output to a string (without INT_MAX +limitation) + +Files: +lib/szprintf.c + +Depends-on: +stdio +vasnprintf +errno +stdint + +configure.ac: +gl_STDIO_MODULE_INDICATOR([szprintf]) + +Makefile.am: +lib_SOURCES += szprintf.c + +Include: +<stdio.h> + +License: +LGPL + +Maintainer: +all diff --git a/modules/szprintf-gnu b/modules/szprintf-gnu new file mode 100644 index 0000000000..4fcb993ec5 --- /dev/null +++ b/modules/szprintf-gnu @@ -0,0 +1,23 @@ +Description: +szprintf() function +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +szprintf-posix +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPL + +Maintainer: +all diff --git a/modules/szprintf-gnu-tests b/modules/szprintf-gnu-tests new file mode 100644 index 0000000000..3910afb03c --- /dev/null +++ b/modules/szprintf-gnu-tests @@ -0,0 +1,12 @@ +Files: +tests/test-szprintf-gnu.c +tests/test-szprintf-gnu.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-szprintf-gnu +check_PROGRAMS += test-szprintf-gnu diff --git a/modules/szprintf-posix b/modules/szprintf-posix new file mode 100644 index 0000000000..67757628aa --- /dev/null +++ b/modules/szprintf-posix @@ -0,0 +1,22 @@ +Description: +szprintf() function with POSIX compliant format string interpretation + +Files: + +Depends-on: +szprintf +mixin/printf-posix + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPL + +Maintainer: +all diff --git a/modules/szprintf-posix-tests b/modules/szprintf-posix-tests new file mode 100644 index 0000000000..39a93998fe --- /dev/null +++ b/modules/szprintf-posix-tests @@ -0,0 +1,14 @@ +Files: +tests/test-szprintf-posix.c +tests/test-szprintf-posix.h +tests/infinity.h +tests/macros.h + +Depends-on: +nan + +configure.ac: + +Makefile.am: +TESTS += test-szprintf-posix +check_PROGRAMS += test-szprintf-posix diff --git a/modules/vaszprintf b/modules/vaszprintf new file mode 100644 index 0000000000..a732581d93 --- /dev/null +++ b/modules/vaszprintf @@ -0,0 +1,30 @@ +Description: +vsprintf (without INT_MAX limitation) with automatic memory allocation + +Files: +lib/vaszprintf.c +lib/aszprintf.c + +Depends-on: +stdio +vasnprintf +errno +stdint + +configure.ac: +gl_STDIO_MODULE_INDICATOR([vaszprintf]) +m4_ifdef([AM_XGETTEXT_OPTION], + [AM_][XGETTEXT_OPTION([--flag=aszprintf:2:c-format]) + AM_][XGETTEXT_OPTION([--flag=vaszprintf:2:c-format])]) + +Makefile.am: +lib_SOURCES += vaszprintf.c aszprintf.c + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/vaszprintf-gnu b/modules/vaszprintf-gnu new file mode 100644 index 0000000000..c4cbf7caa7 --- /dev/null +++ b/modules/vaszprintf-gnu @@ -0,0 +1,23 @@ +Description: +aszprintf() and vaszprintf() functions +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +vaszprintf-posix +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/vaszprintf-gnu-tests b/modules/vaszprintf-gnu-tests new file mode 100644 index 0000000000..3076d19105 --- /dev/null +++ b/modules/vaszprintf-gnu-tests @@ -0,0 +1,12 @@ +Files: +tests/test-vaszprintf-gnu.c +tests/test-vaszprintf-gnu.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-vaszprintf-gnu +check_PROGRAMS += test-vaszprintf-gnu diff --git a/modules/vaszprintf-posix b/modules/vaszprintf-posix new file mode 100644 index 0000000000..add22fceac --- /dev/null +++ b/modules/vaszprintf-posix @@ -0,0 +1,23 @@ +Description: +aszprintf() and vaszprintf() functions +with POSIX compliant format string interpretation + +Files: + +Depends-on: +vaszprintf +mixin/printf-posix + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/vaszprintf-posix-tests b/modules/vaszprintf-posix-tests new file mode 100644 index 0000000000..da83ebc5c3 --- /dev/null +++ b/modules/vaszprintf-posix-tests @@ -0,0 +1,13 @@ +Files: +tests/test-vaszprintf-posix.c +tests/infinity.h +tests/macros.h + +Depends-on: +nan + +configure.ac: + +Makefile.am: +TESTS += test-vaszprintf-posix +check_PROGRAMS += test-vaszprintf-posix diff --git a/modules/vazsprintf b/modules/vazsprintf deleted file mode 100644 index 787825aa71..0000000000 --- a/modules/vazsprintf +++ /dev/null @@ -1,30 +0,0 @@ -Description: -vsprintf (without INT_MAX limitation) with automatic memory allocation - -Files: -lib/vazsprintf.c -lib/azsprintf.c - -Depends-on: -stdio -vasnprintf -errno -stdint - -configure.ac: -gl_STDIO_MODULE_INDICATOR([vazsprintf]) -m4_ifdef([AM_XGETTEXT_OPTION], - [AM_][XGETTEXT_OPTION([--flag=azsprintf:2:c-format]) - AM_][XGETTEXT_OPTION([--flag=vazsprintf:2:c-format])]) - -Makefile.am: -lib_SOURCES += vazsprintf.c azsprintf.c - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/vazsprintf-gnu b/modules/vazsprintf-gnu deleted file mode 100644 index ce3c0e1788..0000000000 --- a/modules/vazsprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -azsprintf() and vazsprintf() functions -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -vazsprintf-posix -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/vazsprintf-gnu-tests b/modules/vazsprintf-gnu-tests deleted file mode 100644 index 80de638ce8..0000000000 --- a/modules/vazsprintf-gnu-tests +++ /dev/null @@ -1,12 +0,0 @@ -Files: -tests/test-vazsprintf-gnu.c -tests/test-vazsprintf-gnu.h -tests/macros.h - -Depends-on: - -configure.ac: - -Makefile.am: -TESTS += test-vazsprintf-gnu -check_PROGRAMS += test-vazsprintf-gnu diff --git a/modules/vazsprintf-posix b/modules/vazsprintf-posix deleted file mode 100644 index 39a1da3800..0000000000 --- a/modules/vazsprintf-posix +++ /dev/null @@ -1,23 +0,0 @@ -Description: -azsprintf() and vazsprintf() functions -with POSIX compliant format string interpretation - -Files: - -Depends-on: -vazsprintf -mixin/printf-posix - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/vazsprintf-posix-tests b/modules/vazsprintf-posix-tests deleted file mode 100644 index 04c84e7861..0000000000 --- a/modules/vazsprintf-posix-tests +++ /dev/null @@ -1,13 +0,0 @@ -Files: -tests/test-vazsprintf-posix.c -tests/infinity.h -tests/macros.h - -Depends-on: -nan - -configure.ac: - -Makefile.am: -TESTS += test-vazsprintf-posix -check_PROGRAMS += test-vazsprintf-posix diff --git a/modules/vsnprintf b/modules/vsnprintf index de2a86e285..2c77dd4d61 100644 --- a/modules/vsnprintf +++ b/modules/vsnprintf @@ -11,7 +11,7 @@ Depends-on: stdio errno [test $ac_cv_func_vsnprintf = no || test $REPLACE_VSNPRINTF = 1] stdint [test $ac_cv_func_vsnprintf = no || test $REPLACE_VSNPRINTF = 1] -vzsnprintf [test $ac_cv_func_vsnprintf = no || test $REPLACE_VSNPRINTF = 1] +vsnzprintf [test $ac_cv_func_vsnprintf = no || test $REPLACE_VSNPRINTF = 1] configure.ac: gl_FUNC_VSNPRINTF diff --git a/modules/vsnzprintf b/modules/vsnzprintf new file mode 100644 index 0000000000..e6b060d41d --- /dev/null +++ b/modules/vsnzprintf @@ -0,0 +1,27 @@ +Description: +vsnzprintf() function: print formatted output from an stdarg argument list +to a fixed length string (without INT_MAX limitation) + +Files: +lib/vsnzprintf.c + +Depends-on: +stdio +vasnprintf +errno +stdint + +configure.ac: +gl_STDIO_MODULE_INDICATOR([vsnzprintf]) + +Makefile.am: +lib_SOURCES += vsnzprintf.c + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/vsnzprintf-gnu b/modules/vsnzprintf-gnu new file mode 100644 index 0000000000..54c8b7f244 --- /dev/null +++ b/modules/vsnzprintf-gnu @@ -0,0 +1,23 @@ +Description: +vsnzprintf() function +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +vsnzprintf-posix +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/vsnzprintf-gnu-tests b/modules/vsnzprintf-gnu-tests new file mode 100644 index 0000000000..299ce4f1b0 --- /dev/null +++ b/modules/vsnzprintf-gnu-tests @@ -0,0 +1,12 @@ +Files: +tests/test-vsnzprintf-gnu.c +tests/test-snzprintf-gnu.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-vsnzprintf-gnu +check_PROGRAMS += test-vsnzprintf-gnu diff --git a/modules/vsnzprintf-posix b/modules/vsnzprintf-posix new file mode 100644 index 0000000000..dac079c20f --- /dev/null +++ b/modules/vsnzprintf-posix @@ -0,0 +1,22 @@ +Description: +vsnzprintf() function with POSIX compliant format string interpretation + +Files: + +Depends-on: +vsnzprintf +mixin/printf-posix + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/vsnzprintf-posix-tests b/modules/vsnzprintf-posix-tests new file mode 100644 index 0000000000..3d4e214456 --- /dev/null +++ b/modules/vsnzprintf-posix-tests @@ -0,0 +1,14 @@ +Files: +tests/test-vsnzprintf-posix.c +tests/test-snzprintf-posix.h +tests/infinity.h +tests/macros.h + +Depends-on: +nan + +configure.ac: + +Makefile.am: +TESTS += test-vsnzprintf-posix +check_PROGRAMS += test-vsnzprintf-posix diff --git a/modules/vsprintf-posix b/modules/vsprintf-posix index 91b634921a..d1df5a39b9 100644 --- a/modules/vsprintf-posix +++ b/modules/vsprintf-posix @@ -18,7 +18,7 @@ stdio nocrash printf-safe multiarch -vzsprintf [test $REPLACE_VSPRINTF = 1] +vszprintf [test $REPLACE_VSPRINTF = 1] mixin/printf-posix [test $REPLACE_VSPRINTF = 1] stdint [test $REPLACE_VSPRINTF = 1] errno [test $REPLACE_VSPRINTF = 1] diff --git a/modules/vszprintf b/modules/vszprintf new file mode 100644 index 0000000000..1e74637574 --- /dev/null +++ b/modules/vszprintf @@ -0,0 +1,27 @@ +Description: +vszprintf() function: print formatted output from an stdarg argument list +to a string (without INT_MAX limitation) + +Files: +lib/vszprintf.c + +Depends-on: +stdio +vasnprintf +errno +stdint + +configure.ac: +gl_STDIO_MODULE_INDICATOR([vszprintf]) + +Makefile.am: +lib_SOURCES += vszprintf.c + +Include: +<stdio.h> + +License: +LGPL + +Maintainer: +all diff --git a/modules/vszprintf-gnu b/modules/vszprintf-gnu new file mode 100644 index 0000000000..a93d90ca16 --- /dev/null +++ b/modules/vszprintf-gnu @@ -0,0 +1,23 @@ +Description: +vszprintf() function +with POSIX compliant and GNU compatible format string interpretation + +Files: + +Depends-on: +vszprintf-posix +mixin/printf-gnu + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPL + +Maintainer: +all diff --git a/modules/vszprintf-gnu-tests b/modules/vszprintf-gnu-tests new file mode 100644 index 0000000000..5a843aafb5 --- /dev/null +++ b/modules/vszprintf-gnu-tests @@ -0,0 +1,12 @@ +Files: +tests/test-vszprintf-gnu.c +tests/test-szprintf-gnu.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-vszprintf-gnu +check_PROGRAMS += test-vszprintf-gnu diff --git a/modules/vszprintf-posix b/modules/vszprintf-posix new file mode 100644 index 0000000000..573356060d --- /dev/null +++ b/modules/vszprintf-posix @@ -0,0 +1,22 @@ +Description: +vszprintf() function with POSIX compliant format string interpretation + +Files: + +Depends-on: +vszprintf +mixin/printf-posix + +configure.ac: +gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS + +Makefile.am: + +Include: +<stdio.h> + +License: +LGPL + +Maintainer: +all diff --git a/modules/vszprintf-posix-tests b/modules/vszprintf-posix-tests new file mode 100644 index 0000000000..9f430dc703 --- /dev/null +++ b/modules/vszprintf-posix-tests @@ -0,0 +1,14 @@ +Files: +tests/test-vszprintf-posix.c +tests/test-szprintf-posix.h +tests/infinity.h +tests/macros.h + +Depends-on: +nan + +configure.ac: + +Makefile.am: +TESTS += test-vszprintf-posix +check_PROGRAMS += test-vszprintf-posix diff --git a/modules/vzsnprintf b/modules/vzsnprintf deleted file mode 100644 index 853d88210d..0000000000 --- a/modules/vzsnprintf +++ /dev/null @@ -1,27 +0,0 @@ -Description: -vzsnprintf() function: print formatted output from an stdarg argument list -to a fixed length string (without INT_MAX limitation) - -Files: -lib/vzsnprintf.c - -Depends-on: -stdio -vasnprintf -errno -stdint - -configure.ac: -gl_STDIO_MODULE_INDICATOR([vzsnprintf]) - -Makefile.am: -lib_SOURCES += vzsnprintf.c - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/vzsnprintf-gnu b/modules/vzsnprintf-gnu deleted file mode 100644 index 04c46a3cc3..0000000000 --- a/modules/vzsnprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -vzsnprintf() function -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -vzsnprintf-posix -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/vzsnprintf-gnu-tests b/modules/vzsnprintf-gnu-tests deleted file mode 100644 index caf3f4ee8d..0000000000 --- a/modules/vzsnprintf-gnu-tests +++ /dev/null @@ -1,12 +0,0 @@ -Files: -tests/test-vzsnprintf-gnu.c -tests/test-zsnprintf-gnu.h -tests/macros.h - -Depends-on: - -configure.ac: - -Makefile.am: -TESTS += test-vzsnprintf-gnu -check_PROGRAMS += test-vzsnprintf-gnu diff --git a/modules/vzsnprintf-posix b/modules/vzsnprintf-posix deleted file mode 100644 index e1d30cf54f..0000000000 --- a/modules/vzsnprintf-posix +++ /dev/null @@ -1,22 +0,0 @@ -Description: -vzsnprintf() function with POSIX compliant format string interpretation - -Files: - -Depends-on: -vzsnprintf -mixin/printf-posix - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/vzsnprintf-posix-tests b/modules/vzsnprintf-posix-tests deleted file mode 100644 index 58df0a2436..0000000000 --- a/modules/vzsnprintf-posix-tests +++ /dev/null @@ -1,14 +0,0 @@ -Files: -tests/test-vzsnprintf-posix.c -tests/test-zsnprintf-posix.h -tests/infinity.h -tests/macros.h - -Depends-on: -nan - -configure.ac: - -Makefile.am: -TESTS += test-vzsnprintf-posix -check_PROGRAMS += test-vzsnprintf-posix diff --git a/modules/vzsprintf b/modules/vzsprintf deleted file mode 100644 index 6564c020f1..0000000000 --- a/modules/vzsprintf +++ /dev/null @@ -1,27 +0,0 @@ -Description: -vzsprintf() function: print formatted output from an stdarg argument list -to a string (without INT_MAX limitation) - -Files: -lib/vzsprintf.c - -Depends-on: -stdio -vasnprintf -errno -stdint - -configure.ac: -gl_STDIO_MODULE_INDICATOR([vzsprintf]) - -Makefile.am: -lib_SOURCES += vzsprintf.c - -Include: -<stdio.h> - -License: -LGPL - -Maintainer: -all diff --git a/modules/vzsprintf-gnu b/modules/vzsprintf-gnu deleted file mode 100644 index 3241ea5235..0000000000 --- a/modules/vzsprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -vzsprintf() function -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -vzsprintf-posix -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPL - -Maintainer: -all diff --git a/modules/vzsprintf-gnu-tests b/modules/vzsprintf-gnu-tests deleted file mode 100644 index 38bf0381ad..0000000000 --- a/modules/vzsprintf-gnu-tests +++ /dev/null @@ -1,12 +0,0 @@ -Files: -tests/test-vzsprintf-gnu.c -tests/test-zsprintf-gnu.h -tests/macros.h - -Depends-on: - -configure.ac: - -Makefile.am: -TESTS += test-vzsprintf-gnu -check_PROGRAMS += test-vzsprintf-gnu diff --git a/modules/vzsprintf-posix b/modules/vzsprintf-posix deleted file mode 100644 index fb3428a8e1..0000000000 --- a/modules/vzsprintf-posix +++ /dev/null @@ -1,22 +0,0 @@ -Description: -vzsprintf() function with POSIX compliant format string interpretation - -Files: - -Depends-on: -vzsprintf -mixin/printf-posix - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPL - -Maintainer: -all diff --git a/modules/vzsprintf-posix-tests b/modules/vzsprintf-posix-tests deleted file mode 100644 index ea4682d504..0000000000 --- a/modules/vzsprintf-posix-tests +++ /dev/null @@ -1,14 +0,0 @@ -Files: -tests/test-vzsprintf-posix.c -tests/test-zsprintf-posix.h -tests/infinity.h -tests/macros.h - -Depends-on: -nan - -configure.ac: - -Makefile.am: -TESTS += test-vzsprintf-posix -check_PROGRAMS += test-vzsprintf-posix diff --git a/modules/xvasprintf b/modules/xvasprintf index bb537ce3ee..b94bd66940 100644 --- a/modules/xvasprintf +++ b/modules/xvasprintf @@ -12,7 +12,7 @@ m4/strerrorname_np.m4 Depends-on: extensions stdio -vazsprintf +vaszprintf xalloc xalloc-die extern-inline diff --git a/modules/zsnprintf b/modules/zsnprintf deleted file mode 100644 index 40fd329e0e..0000000000 --- a/modules/zsnprintf +++ /dev/null @@ -1,27 +0,0 @@ -Description: -zsnprintf() function: print formatted output to a fixed length string -(without INT_MAX limitation) - -Files: -lib/zsnprintf.c - -Depends-on: -stdio -vasnprintf -errno -stdint - -configure.ac: -gl_STDIO_MODULE_INDICATOR([zsnprintf]) - -Makefile.am: -lib_SOURCES += zsnprintf.c - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/zsnprintf-gnu b/modules/zsnprintf-gnu deleted file mode 100644 index d0bd55792d..0000000000 --- a/modules/zsnprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -zsnprintf() function -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -zsnprintf-posix -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/zsnprintf-gnu-tests b/modules/zsnprintf-gnu-tests deleted file mode 100644 index 6fd7c1c83f..0000000000 --- a/modules/zsnprintf-gnu-tests +++ /dev/null @@ -1,12 +0,0 @@ -Files: -tests/test-zsnprintf-gnu.c -tests/test-zsnprintf-gnu.h -tests/macros.h - -Depends-on: - -configure.ac: - -Makefile.am: -TESTS += test-zsnprintf-gnu -check_PROGRAMS += test-zsnprintf-gnu diff --git a/modules/zsnprintf-posix b/modules/zsnprintf-posix deleted file mode 100644 index 6e2f2c6589..0000000000 --- a/modules/zsnprintf-posix +++ /dev/null @@ -1,22 +0,0 @@ -Description: -zsnprintf() function with POSIX compliant format string interpretation - -Files: - -Depends-on: -zsnprintf -mixin/printf-posix - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPLv2+ - -Maintainer: -all diff --git a/modules/zsnprintf-posix-tests b/modules/zsnprintf-posix-tests deleted file mode 100644 index 75f7594293..0000000000 --- a/modules/zsnprintf-posix-tests +++ /dev/null @@ -1,14 +0,0 @@ -Files: -tests/test-zsnprintf-posix.c -tests/test-zsnprintf-posix.h -tests/infinity.h -tests/macros.h - -Depends-on: -nan - -configure.ac: - -Makefile.am: -TESTS += test-zsnprintf-posix -check_PROGRAMS += test-zsnprintf-posix diff --git a/modules/zsprintf b/modules/zsprintf deleted file mode 100644 index 7da8687ea4..0000000000 --- a/modules/zsprintf +++ /dev/null @@ -1,27 +0,0 @@ -Description: -zsprintf() function: print formatted output to a string (without INT_MAX -limitation) - -Files: -lib/zsprintf.c - -Depends-on: -stdio -vasnprintf -errno -stdint - -configure.ac: -gl_STDIO_MODULE_INDICATOR([zsprintf]) - -Makefile.am: -lib_SOURCES += zsprintf.c - -Include: -<stdio.h> - -License: -LGPL - -Maintainer: -all diff --git a/modules/zsprintf-gnu b/modules/zsprintf-gnu deleted file mode 100644 index a530b34303..0000000000 --- a/modules/zsprintf-gnu +++ /dev/null @@ -1,23 +0,0 @@ -Description: -zsprintf() function -with POSIX compliant and GNU compatible format string interpretation - -Files: - -Depends-on: -zsprintf-posix -mixin/printf-gnu - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPL - -Maintainer: -all diff --git a/modules/zsprintf-gnu-tests b/modules/zsprintf-gnu-tests deleted file mode 100644 index 7db1e58043..0000000000 --- a/modules/zsprintf-gnu-tests +++ /dev/null @@ -1,12 +0,0 @@ -Files: -tests/test-zsprintf-gnu.c -tests/test-zsprintf-gnu.h -tests/macros.h - -Depends-on: - -configure.ac: - -Makefile.am: -TESTS += test-zsprintf-gnu -check_PROGRAMS += test-zsprintf-gnu diff --git a/modules/zsprintf-posix b/modules/zsprintf-posix deleted file mode 100644 index c3ab891f88..0000000000 --- a/modules/zsprintf-posix +++ /dev/null @@ -1,22 +0,0 @@ -Description: -zsprintf() function with POSIX compliant format string interpretation - -Files: - -Depends-on: -zsprintf -mixin/printf-posix - -configure.ac: -gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS - -Makefile.am: - -Include: -<stdio.h> - -License: -LGPL - -Maintainer: -all diff --git a/modules/zsprintf-posix-tests b/modules/zsprintf-posix-tests deleted file mode 100644 index 8ea6819c06..0000000000 --- a/modules/zsprintf-posix-tests +++ /dev/null @@ -1,14 +0,0 @@ -Files: -tests/test-zsprintf-posix.c -tests/test-zsprintf-posix.h -tests/infinity.h -tests/macros.h - -Depends-on: -nan - -configure.ac: - -Makefile.am: -TESTS += test-zsprintf-posix -check_PROGRAMS += test-zsprintf-posix diff --git a/tests/test-c-snzprintf-gnu.c b/tests/test-c-snzprintf-gnu.c new file mode 100644 index 0000000000..0609a6fd09 --- /dev/null +++ b/tests/test-c-snzprintf-gnu.c @@ -0,0 +1,41 @@ +/* Test of POSIX and GNU compatible c_snzprintf() function. + Copyright (C) 2011-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +#include <config.h> + +#include "c-snprintf.h" + +#include <locale.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +#include "test-snzprintf-gnu.h" + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_function (c_snzprintf); + + return test_exit_status; +} diff --git a/tests/test-c-snzprintf-gnu.sh b/tests/test-c-snzprintf-gnu.sh new file mode 100755 index 0000000000..66d967a9ec --- /dev/null +++ b/tests/test-c-snzprintf-gnu.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: "${LOCALE_FR=fr_FR}" +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +${CHECKER} ./test-c-snzprintf-gnu${EXEEXT} 1 diff --git a/tests/test-c-vaszprintf-gnu.c b/tests/test-c-vaszprintf-gnu.c new file mode 100644 index 0000000000..aa8140dae5 --- /dev/null +++ b/tests/test-c-vaszprintf-gnu.c @@ -0,0 +1,66 @@ +/* Test of POSIX and GNU compatible c_vaszprintf() and c_aszprintf() functions. + Copyright (C) 2011-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +#include <config.h> + +#include "c-vasprintf.h" + +#include <locale.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +#include "test-vaszprintf-gnu.h" + +static ptrdiff_t +my_c_aszprintf (char **result, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = c_vaszprintf (result, format, args); + va_end (args); + return ret; +} + +static void +test_c_vaszprintf () +{ + test_function (my_c_aszprintf); +} + +static void +test_c_aszprintf () +{ + test_function (c_aszprintf); +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_c_vaszprintf (); + test_c_aszprintf (); + + return test_exit_status; +} diff --git a/tests/test-c-vaszprintf-gnu.sh b/tests/test-c-vaszprintf-gnu.sh new file mode 100755 index 0000000000..79b2560c0c --- /dev/null +++ b/tests/test-c-vaszprintf-gnu.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: "${LOCALE_FR=fr_FR}" +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +${CHECKER} ./test-c-vaszprintf-gnu${EXEEXT} 1 diff --git a/tests/test-c-vazsprintf-gnu.c b/tests/test-c-vazsprintf-gnu.c deleted file mode 100644 index 0db9948d06..0000000000 --- a/tests/test-c-vazsprintf-gnu.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Test of POSIX and GNU compatible c_vazsprintf() and c_azsprintf() functions. - Copyright (C) 2011-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -#include <config.h> - -#include "c-vasprintf.h" - -#include <locale.h> -#include <stdio.h> -#include <string.h> - -#include "macros.h" - -#include "test-vazsprintf-gnu.h" - -static ptrdiff_t -my_c_azsprintf (char **result, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = c_vazsprintf (result, format, args); - va_end (args); - return ret; -} - -static void -test_c_vazsprintf () -{ - test_function (my_c_azsprintf); -} - -static void -test_c_azsprintf () -{ - test_function (c_azsprintf); -} - -int -main (int argc, char *argv[]) -{ - /* configure should already have checked that the locale is supported. */ - if (setlocale (LC_ALL, "") == NULL) - return 1; - - test_c_vazsprintf (); - test_c_azsprintf (); - - return test_exit_status; -} diff --git a/tests/test-c-vazsprintf-gnu.sh b/tests/test-c-vazsprintf-gnu.sh deleted file mode 100755 index 1410b4e51e..0000000000 --- a/tests/test-c-vazsprintf-gnu.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Test in an ISO-8859-1 or ISO-8859-15 locale. -: "${LOCALE_FR=fr_FR}" -if test $LOCALE_FR = none; then - if test -f /usr/bin/localedef; then - echo "Skipping test: no traditional french locale is installed" - else - echo "Skipping test: no traditional french locale is supported" - fi - exit 77 -fi - -LC_ALL=$LOCALE_FR \ -${CHECKER} ./test-c-vazsprintf-gnu${EXEEXT} 1 diff --git a/tests/test-c-vsnzprintf-gnu.c b/tests/test-c-vsnzprintf-gnu.c new file mode 100644 index 0000000000..85272e3e26 --- /dev/null +++ b/tests/test-c-vsnzprintf-gnu.c @@ -0,0 +1,53 @@ +/* Test of POSIX and GNU compatible c_vsnzprintf() function. + Copyright (C) 2011-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +#include <config.h> + +#include "c-vsnprintf.h" + +#include <locale.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +#include "test-snzprintf-gnu.h" + +static ptrdiff_t +my_c_snzprintf (char *str, size_t size, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = c_vsnzprintf (str, size, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + test_function (my_c_snzprintf); + + return test_exit_status; +} diff --git a/tests/test-c-vsnzprintf-gnu.sh b/tests/test-c-vsnzprintf-gnu.sh new file mode 100755 index 0000000000..a49ea672e6 --- /dev/null +++ b/tests/test-c-vsnzprintf-gnu.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: "${LOCALE_FR=fr_FR}" +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +${CHECKER} ./test-c-vsnzprintf-gnu${EXEEXT} 1 diff --git a/tests/test-c-vzsnprintf-gnu.c b/tests/test-c-vzsnprintf-gnu.c deleted file mode 100644 index 4facc1f9c3..0000000000 --- a/tests/test-c-vzsnprintf-gnu.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Test of POSIX and GNU compatible c_vzsnprintf() function. - Copyright (C) 2011-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -#include <config.h> - -#include "c-vsnprintf.h" - -#include <locale.h> -#include <stdio.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsnprintf-gnu.h" - -static ptrdiff_t -my_c_zsnprintf (char *str, size_t size, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = c_vzsnprintf (str, size, format, args); - va_end (args); - return ret; -} - -int -main (int argc, char *argv[]) -{ - /* configure should already have checked that the locale is supported. */ - if (setlocale (LC_ALL, "") == NULL) - return 1; - - test_function (my_c_zsnprintf); - - return test_exit_status; -} diff --git a/tests/test-c-vzsnprintf-gnu.sh b/tests/test-c-vzsnprintf-gnu.sh deleted file mode 100755 index 9d416a13ef..0000000000 --- a/tests/test-c-vzsnprintf-gnu.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Test in an ISO-8859-1 or ISO-8859-15 locale. -: "${LOCALE_FR=fr_FR}" -if test $LOCALE_FR = none; then - if test -f /usr/bin/localedef; then - echo "Skipping test: no traditional french locale is installed" - else - echo "Skipping test: no traditional french locale is supported" - fi - exit 77 -fi - -LC_ALL=$LOCALE_FR \ -${CHECKER} ./test-c-vzsnprintf-gnu${EXEEXT} 1 diff --git a/tests/test-c-zsnprintf-gnu.c b/tests/test-c-zsnprintf-gnu.c deleted file mode 100644 index 016c78247a..0000000000 --- a/tests/test-c-zsnprintf-gnu.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Test of POSIX and GNU compatible c_zsnprintf() function. - Copyright (C) 2011-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -#include <config.h> - -#include "c-snprintf.h" - -#include <locale.h> -#include <stdio.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsnprintf-gnu.h" - -int -main (int argc, char *argv[]) -{ - /* configure should already have checked that the locale is supported. */ - if (setlocale (LC_ALL, "") == NULL) - return 1; - - test_function (c_zsnprintf); - - return test_exit_status; -} diff --git a/tests/test-c-zsnprintf-gnu.sh b/tests/test-c-zsnprintf-gnu.sh deleted file mode 100755 index 3edb34ebee..0000000000 --- a/tests/test-c-zsnprintf-gnu.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Test in an ISO-8859-1 or ISO-8859-15 locale. -: "${LOCALE_FR=fr_FR}" -if test $LOCALE_FR = none; then - if test -f /usr/bin/localedef; then - echo "Skipping test: no traditional french locale is installed" - else - echo "Skipping test: no traditional french locale is supported" - fi - exit 77 -fi - -LC_ALL=$LOCALE_FR \ -${CHECKER} ./test-c-zsnprintf-gnu${EXEEXT} 1 diff --git a/tests/test-snzprintf-gnu.c b/tests/test-snzprintf-gnu.c new file mode 100644 index 0000000000..f502eebf84 --- /dev/null +++ b/tests/test-snzprintf-gnu.c @@ -0,0 +1,35 @@ +/* Test of POSIX and GNU compatible snzprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-snzprintf-gnu.h" + +int +main (int argc, char *argv[]) +{ + test_function (snzprintf); + return test_exit_status; +} diff --git a/tests/test-snzprintf-gnu.h b/tests/test-snzprintf-gnu.h new file mode 100644 index 0000000000..eb8e503079 --- /dev/null +++ b/tests/test-snzprintf-gnu.h @@ -0,0 +1,37 @@ +/* Test of POSIX and GNU compatible vsnzprintf() and snzprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +/* This test exercises only a few POSIX compliance problems that are still + visible on platforms relevant in 2024. For a much more complete test suite, + see test-snprintf-posix.h. */ + +static void +test_function (ptrdiff_t (*my_snzprintf) (char *, size_t, const char *, ...)) +{ + char result[5000]; + + /* Test the support of the 'B' conversion specifier for binary output of + integers. */ + + { /* This test would fail on all platforms other than glibc ⥠2.35. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%#B %d", 12345, 33, 44, 55); + ASSERT (strcmp (result, "0B11000000111001 33") == 0); + ASSERT (retval == strlen (result)); + } +} diff --git a/tests/test-snzprintf-posix.c b/tests/test-snzprintf-posix.c new file mode 100644 index 0000000000..673f880553 --- /dev/null +++ b/tests/test-snzprintf-posix.c @@ -0,0 +1,35 @@ +/* Test of POSIX compatible snzprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-snzprintf-posix.h" + +int +main (int argc, char *argv[]) +{ + test_function (snzprintf); + return test_exit_status; +} diff --git a/tests/test-snzprintf-posix.h b/tests/test-snzprintf-posix.h new file mode 100644 index 0000000000..46cef4f27e --- /dev/null +++ b/tests/test-snzprintf-posix.h @@ -0,0 +1,183 @@ +/* Test of POSIX compatible vsnzprintf() and snzprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +/* This test exercises only a few POSIX compliance problems that are still + visible on platforms relevant in 2024. For a much more complete test suite, + see test-snprintf-posix.h. */ + +#include "infinity.h" +#include "nan.h" + +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + +static void +test_function (ptrdiff_t (*my_snzprintf) (char *, size_t, const char *, ...)) +{ + char result[5000]; + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* This test would fail on Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%a %d", 3.1416015625, 33, 44, 55); + ASSERT (strcmp (result, "0x1.922p+1 33") == 0 + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%A %d", -3.1416015625, 33, 44, 55); + ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on FreeBSD 6.1, NetBSD 10.0. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%.2a %d", 1.51, 33, 44, 55); + ASSERT (strcmp (result, "0x1.83p+0 33") == 0 + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on macOS 14, FreeBSD 14.0, OpenBSD 7.5, AIX 7.3, + Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%.0a %d", 1.51, 33, 44, 55); + ASSERT (strcmp (result, "0x2p+0 33") == 0 + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %f format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%f %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%010f %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, " inf 33") == 0 + || strcmp (result, " infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %e format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%e %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %g format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%g %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of large precision. */ + + { /* This test would fail on AIX 7.1. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%.4000d %d", 1234567, 99); + size_t i; + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the 'b' conversion specifier for binary output of + integers. */ + + { /* This test would fail on glibc 2.34, musl libc, macOS 14, + FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_snzprintf (result, sizeof (result), "%b %d", 12345, 33, 44, 55); + ASSERT (strcmp (result, "11000000111001 33") == 0); + ASSERT (retval == strlen (result)); + } +} diff --git a/tests/test-szprintf-gnu.c b/tests/test-szprintf-gnu.c new file mode 100644 index 0000000000..bdc6d1a2c0 --- /dev/null +++ b/tests/test-szprintf-gnu.c @@ -0,0 +1,36 @@ +/* Test of POSIX and GNU compatible szprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-szprintf-gnu.h" + +int +main (int argc, char *argv[]) +{ + test_function (szprintf); + return test_exit_status; +} diff --git a/tests/test-szprintf-gnu.h b/tests/test-szprintf-gnu.h new file mode 100644 index 0000000000..8f059e2e44 --- /dev/null +++ b/tests/test-szprintf-gnu.h @@ -0,0 +1,37 @@ +/* Test of POSIX and GNU compatible vszprintf() and szprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +/* This test exercises only a few POSIX compliance problems that are still + visible on platforms relevant in 2024. For a much more complete test suite, + see test-sprintf-posix.h. */ + +static void +test_function (ptrdiff_t (*my_szprintf) (char *, const char *, ...)) +{ + char result[5000]; + + /* Test the support of the 'B' conversion specifier for binary output of + integers. */ + + { /* This test would fail on all platforms other than glibc ⥠2.35. */ + ptrdiff_t retval = + my_szprintf (result, "%#B %d", 12345, 33, 44, 55); + ASSERT (strcmp (result, "0B11000000111001 33") == 0); + ASSERT (retval == strlen (result)); + } +} diff --git a/tests/test-szprintf-posix.c b/tests/test-szprintf-posix.c new file mode 100644 index 0000000000..fef51c7775 --- /dev/null +++ b/tests/test-szprintf-posix.c @@ -0,0 +1,36 @@ +/* Test of POSIX compatible szprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-szprintf-posix.h" + +int +main (int argc, char *argv[]) +{ + test_function (szprintf); + return test_exit_status; +} diff --git a/tests/test-szprintf-posix.h b/tests/test-szprintf-posix.h new file mode 100644 index 0000000000..6ab9cfc3e3 --- /dev/null +++ b/tests/test-szprintf-posix.h @@ -0,0 +1,183 @@ +/* Test of POSIX compatible vszprintf() and szprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +/* This test exercises only a few POSIX compliance problems that are still + visible on platforms relevant in 2024. For a much more complete test suite, + see test-sprintf-posix.h. */ + +#include "infinity.h" +#include "nan.h" + +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + +static void +test_function (ptrdiff_t (*my_szprintf) (char *, const char *, ...)) +{ + char result[5000]; + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* This test would fail on Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%a %d", 3.1416015625, 33, 44, 55); + ASSERT (strcmp (result, "0x1.922p+1 33") == 0 + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%A %d", -3.1416015625, 33, 44, 55); + ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on FreeBSD 6.1, NetBSD 10.0. */ + ptrdiff_t retval = + my_szprintf (result, "%.2a %d", 1.51, 33, 44, 55); + ASSERT (strcmp (result, "0x1.83p+0 33") == 0 + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on macOS 14, FreeBSD 14.0, OpenBSD 7.5, AIX 7.3, + Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%.0a %d", 1.51, 33, 44, 55); + ASSERT (strcmp (result, "0x2p+0 33") == 0 + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %f format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%f %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%f %d", NaNd (), 33, 44, 55); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%010f %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, " inf 33") == 0 + || strcmp (result, " infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %e format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%e %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%e %d", NaNd (), 33, 44, 55); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the %g format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%g %d", Infinityd (), 33, 44, 55); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%g %d", NaNd (), 33, 44, 55); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of large precision. */ + + { /* This test would fail on AIX 7.1. */ + ptrdiff_t retval = + my_szprintf (result, "%.4000d %d", 1234567, 99); + size_t i; + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (retval == strlen (result)); + } + + /* Test the support of the 'b' conversion specifier for binary output of + integers. */ + + { /* This test would fail on glibc 2.34, musl libc, macOS 14, + FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */ + ptrdiff_t retval = + my_szprintf (result, "%b %d", 12345, 33, 44, 55); + ASSERT (strcmp (result, "11000000111001 33") == 0); + ASSERT (retval == strlen (result)); + } +} diff --git a/tests/test-vaszprintf-gnu.c b/tests/test-vaszprintf-gnu.c new file mode 100644 index 0000000000..357554e833 --- /dev/null +++ b/tests/test-vaszprintf-gnu.c @@ -0,0 +1,66 @@ +/* Test of POSIX and GNU compatible vaszprintf() and aszprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +/* This test exercises only a few POSIX compliance problems that are still + visible on platforms relevant in 2024. For a much more complete test suite, + see test-vasprintf-posix.c. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> + +#include "macros.h" + +#include "test-vaszprintf-gnu.h" + +static ptrdiff_t +my_aszprintf (char **result, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = vaszprintf (result, format, args); + va_end (args); + return ret; +} + +static void +test_vaszprintf () +{ + test_function (my_aszprintf); +} + +static void +test_aszprintf () +{ + test_function (aszprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vaszprintf (); + test_aszprintf (); + return test_exit_status; +} diff --git a/tests/test-vaszprintf-gnu.h b/tests/test-vaszprintf-gnu.h new file mode 100644 index 0000000000..498c8ef730 --- /dev/null +++ b/tests/test-vaszprintf-gnu.h @@ -0,0 +1,34 @@ +/* Test of POSIX and GNU compatible vaszprintf() and aszprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +static void +test_function (ptrdiff_t (*my_aszprintf) (char **, const char *, ...)) +{ + /* Test the support of the 'B' conversion specifier for binary output of + integers. */ + + { /* This test would fail on all platforms other than glibc ⥠2.35. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%#B %d", 12345, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0B11000000111001 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } +} diff --git a/tests/test-vaszprintf-posix.c b/tests/test-vaszprintf-posix.c new file mode 100644 index 0000000000..0e6af1c371 --- /dev/null +++ b/tests/test-vaszprintf-posix.c @@ -0,0 +1,264 @@ +/* Test of POSIX compatible vaszprintf() and aszprintf() functions. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ + +/* This test exercises only a few POSIX compliance problems that are still + visible on platforms relevant in 2024. For a much more complete test suite, + see test-vasprintf-posix.c. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> + +#include "macros.h" +#include "infinity.h" +#include "nan.h" + +/* Test whether string[start_index..end_index-1] is a valid textual + representation of NaN. */ +static int +strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) +{ + if (start_index < end_index) + { + if (string[start_index] == '-') + start_index++; + if (start_index + 3 <= end_index + && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) + { + start_index += 3; + if (start_index == end_index + || (string[start_index] == '(' && string[end_index - 1] == ')')) + return 1; + } + } + return 0; +} + +static void +test_function (ptrdiff_t (*my_aszprintf) (char **, const char *, ...)) +{ + char result[5000]; + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + { /* This test would fail on Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%a %d", 3.1416015625, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.922p+1 33") == 0 + || strcmp (result, "0x3.244p+0 33") == 0 + || strcmp (result, "0x6.488p-1 33") == 0 + || strcmp (result, "0xc.91p-2 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%A %d", -3.1416015625, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 + || strcmp (result, "-0X3.244P+0 33") == 0 + || strcmp (result, "-0X6.488P-1 33") == 0 + || strcmp (result, "-0XC.91P-2 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on FreeBSD 6.1, NetBSD 10.0. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%.2a %d", 1.51, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x1.83p+0 33") == 0 + || strcmp (result, "0x3.05p-1 33") == 0 + || strcmp (result, "0x6.0ap-2 33") == 0 + || strcmp (result, "0xc.14p-3 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on macOS 14, FreeBSD 14.0, OpenBSD 7.5, AIX 7.3, + Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%.0a %d", 1.51, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "0x2p+0 33") == 0 + || strcmp (result, "0x3p-1 33") == 0 + || strcmp (result, "0x6p-2 33") == 0 + || strcmp (result, "0xcp-3 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + /* Test the support of the %f format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%f %d", Infinityd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%f %d", NaNd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%010f %d", Infinityd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, " inf 33") == 0 + || strcmp (result, " infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + /* Test the support of the %e format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%e %d", Infinityd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%e %d", NaNd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + /* Test the support of the %g format directive. */ + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%g %d", Infinityd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "inf 33") == 0 + || strcmp (result, "infinity 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* This test would fail on AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%g %d", NaNd (), 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strlen (result) >= 3 + 3 + && strisnan (result, 0, strlen (result) - 3, 0) + && strcmp (result + strlen (result) - 3, " 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + /* Test the support of large precision. */ + + { /* This test would fail on AIX 7.1. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%.4000d %d", 1234567, 99); + ASSERT (result != NULL); + size_t i; + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + /* Test the support of the 'b' conversion specifier for binary output of + integers. */ + + { /* This test would fail on glibc 2.34, musl libc, macOS 14, + FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */ + char *result; + ptrdiff_t retval = + my_aszprintf (&result, "%b %d", 12345, 33, 44, 55); + ASSERT (result != NULL); + ASSERT (strcmp (result, "11000000111001 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } +} + +static ptrdiff_t +my_aszprintf (char **result, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = vaszprintf (result, format, args); + va_end (args); + return ret; +} + +static void +test_vaszprintf () +{ + test_function (my_aszprintf); +} + +static void +test_aszprintf () +{ + test_function (aszprintf); +} + +int +main (int argc, char *argv[]) +{ + test_vaszprintf (); + test_aszprintf (); + return test_exit_status; +} diff --git a/tests/test-vazsprintf-gnu.c b/tests/test-vazsprintf-gnu.c deleted file mode 100644 index f0c015d1fb..0000000000 --- a/tests/test-vazsprintf-gnu.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Test of POSIX and GNU compatible vazsprintf() and azsprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -/* This test exercises only a few POSIX compliance problems that are still - visible on platforms relevant in 2024. For a much more complete test suite, - see test-vasprintf-posix.c. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> - -#include "macros.h" - -#include "test-vazsprintf-gnu.h" - -static ptrdiff_t -my_azsprintf (char **result, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = vazsprintf (result, format, args); - va_end (args); - return ret; -} - -static void -test_vazsprintf () -{ - test_function (my_azsprintf); -} - -static void -test_azsprintf () -{ - test_function (azsprintf); -} - -int -main (int argc, char *argv[]) -{ - test_vazsprintf (); - test_azsprintf (); - return test_exit_status; -} diff --git a/tests/test-vazsprintf-gnu.h b/tests/test-vazsprintf-gnu.h deleted file mode 100644 index 0aba9faa6a..0000000000 --- a/tests/test-vazsprintf-gnu.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Test of POSIX and GNU compatible vazsprintf() and azsprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -static void -test_function (ptrdiff_t (*my_azsprintf) (char **, const char *, ...)) -{ - /* Test the support of the 'B' conversion specifier for binary output of - integers. */ - - { /* This test would fail on all platforms other than glibc ⥠2.35. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%#B %d", 12345, 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "0B11000000111001 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } -} diff --git a/tests/test-vazsprintf-posix.c b/tests/test-vazsprintf-posix.c deleted file mode 100644 index 550596652c..0000000000 --- a/tests/test-vazsprintf-posix.c +++ /dev/null @@ -1,264 +0,0 @@ -/* Test of POSIX compatible vazsprintf() and azsprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -/* This test exercises only a few POSIX compliance problems that are still - visible on platforms relevant in 2024. For a much more complete test suite, - see test-vasprintf-posix.c. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> - -#include "macros.h" -#include "infinity.h" -#include "nan.h" - -/* Test whether string[start_index..end_index-1] is a valid textual - representation of NaN. */ -static int -strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) -{ - if (start_index < end_index) - { - if (string[start_index] == '-') - start_index++; - if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } - } - return 0; -} - -static void -test_function (ptrdiff_t (*my_azsprintf) (char **, const char *, ...)) -{ - char result[5000]; - - /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal - output of floating-point numbers. */ - - { /* This test would fail on Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%a %d", 3.1416015625, 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%A %d", -3.1416015625, 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on FreeBSD 6.1, NetBSD 10.0. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%.2a %d", 1.51, 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on macOS 14, FreeBSD 14.0, OpenBSD 7.5, AIX 7.3, - Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%.0a %d", 1.51, 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - /* Test the support of the %f format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%f %d", Infinityd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%f %d", NaNd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%010f %d", Infinityd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, " inf 33") == 0 - || strcmp (result, " infinity 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - /* Test the support of the %e format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%e %d", Infinityd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%e %d", NaNd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - /* Test the support of the %g format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%g %d", Infinityd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%g %d", NaNd (), 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - /* Test the support of large precision. */ - - { /* This test would fail on AIX 7.1. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%.4000d %d", 1234567, 99); - ASSERT (result != NULL); - size_t i; - for (i = 0; i < 4000 - 7; i++) - ASSERT (result[i] == '0'); - ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); - ASSERT (retval == strlen (result)); - free (result); - } - - /* Test the support of the 'b' conversion specifier for binary output of - integers. */ - - { /* This test would fail on glibc 2.34, musl libc, macOS 14, - FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */ - char *result; - ptrdiff_t retval = - my_azsprintf (&result, "%b %d", 12345, 33, 44, 55); - ASSERT (result != NULL); - ASSERT (strcmp (result, "11000000111001 33") == 0); - ASSERT (retval == strlen (result)); - free (result); - } -} - -static ptrdiff_t -my_azsprintf (char **result, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = vazsprintf (result, format, args); - va_end (args); - return ret; -} - -static void -test_vazsprintf () -{ - test_function (my_azsprintf); -} - -static void -test_azsprintf () -{ - test_function (azsprintf); -} - -int -main (int argc, char *argv[]) -{ - test_vazsprintf (); - test_azsprintf (); - return test_exit_status; -} diff --git a/tests/test-vsnzprintf-gnu.c b/tests/test-vsnzprintf-gnu.c new file mode 100644 index 0000000000..d47ff964b0 --- /dev/null +++ b/tests/test-vsnzprintf-gnu.c @@ -0,0 +1,48 @@ +/* Test of POSIX and GNU compatible vsnzprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-snzprintf-gnu.h" + +static ptrdiff_t +my_snzprintf (char *str, size_t size, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = vsnzprintf (str, size, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_snzprintf); + return test_exit_status; +} diff --git a/tests/test-vsnzprintf-posix.c b/tests/test-vsnzprintf-posix.c new file mode 100644 index 0000000000..f245796eb1 --- /dev/null +++ b/tests/test-vsnzprintf-posix.c @@ -0,0 +1,48 @@ +/* Test of POSIX compatible vsnzprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-snzprintf-posix.h" + +static ptrdiff_t +my_snzprintf (char *str, size_t size, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = vsnzprintf (str, size, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_snzprintf); + return test_exit_status; +} diff --git a/tests/test-vszprintf-gnu.c b/tests/test-vszprintf-gnu.c new file mode 100644 index 0000000000..e77855b985 --- /dev/null +++ b/tests/test-vszprintf-gnu.c @@ -0,0 +1,48 @@ +/* Test of POSIX and GNU compatible vszprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-szprintf-gnu.h" + +static ptrdiff_t +my_szprintf (char *str, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = vszprintf (str, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_szprintf); + return test_exit_status; +} diff --git a/tests/test-vszprintf-posix.c b/tests/test-vszprintf-posix.c new file mode 100644 index 0000000000..10f021311d --- /dev/null +++ b/tests/test-vszprintf-posix.c @@ -0,0 +1,48 @@ +/* Test of POSIX compatible vszprintf() function. + Copyright (C) 2007-2024 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 of the License, 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ + +#include <config.h> + +#include <stdio.h> + +#include <stdarg.h> +#include <stddef.h> +#include <string.h> + +#include "macros.h" + +#include "test-szprintf-posix.h" + +static ptrdiff_t +my_szprintf (char *str, const char *format, ...) +{ + va_list args; + ptrdiff_t ret; + + va_start (args, format); + ret = vszprintf (str, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_szprintf); + return test_exit_status; +} diff --git a/tests/test-vzsnprintf-gnu.c b/tests/test-vzsnprintf-gnu.c deleted file mode 100644 index 65e893c050..0000000000 --- a/tests/test-vzsnprintf-gnu.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Test of POSIX and GNU compatible vzsnprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsnprintf-gnu.h" - -static ptrdiff_t -my_zsnprintf (char *str, size_t size, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = vzsnprintf (str, size, format, args); - va_end (args); - return ret; -} - -int -main (int argc, char *argv[]) -{ - test_function (my_zsnprintf); - return test_exit_status; -} diff --git a/tests/test-vzsnprintf-posix.c b/tests/test-vzsnprintf-posix.c deleted file mode 100644 index e44b94cafc..0000000000 --- a/tests/test-vzsnprintf-posix.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Test of POSIX compatible vzsnprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsnprintf-posix.h" - -static ptrdiff_t -my_zsnprintf (char *str, size_t size, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = vzsnprintf (str, size, format, args); - va_end (args); - return ret; -} - -int -main (int argc, char *argv[]) -{ - test_function (my_zsnprintf); - return test_exit_status; -} diff --git a/tests/test-vzsprintf-gnu.c b/tests/test-vzsprintf-gnu.c deleted file mode 100644 index 8920fa1ca5..0000000000 --- a/tests/test-vzsprintf-gnu.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Test of POSIX and GNU compatible vzsprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsprintf-gnu.h" - -static ptrdiff_t -my_zsprintf (char *str, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = vzsprintf (str, format, args); - va_end (args); - return ret; -} - -int -main (int argc, char *argv[]) -{ - test_function (my_zsprintf); - return test_exit_status; -} diff --git a/tests/test-vzsprintf-posix.c b/tests/test-vzsprintf-posix.c deleted file mode 100644 index a3dd260731..0000000000 --- a/tests/test-vzsprintf-posix.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Test of POSIX compatible vzsprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsprintf-posix.h" - -static ptrdiff_t -my_zsprintf (char *str, const char *format, ...) -{ - va_list args; - ptrdiff_t ret; - - va_start (args, format); - ret = vzsprintf (str, format, args); - va_end (args); - return ret; -} - -int -main (int argc, char *argv[]) -{ - test_function (my_zsprintf); - return test_exit_status; -} diff --git a/tests/test-zsnprintf-gnu.c b/tests/test-zsnprintf-gnu.c deleted file mode 100644 index efd4f5b53f..0000000000 --- a/tests/test-zsnprintf-gnu.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Test of POSIX and GNU compatible zsnprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsnprintf-gnu.h" - -int -main (int argc, char *argv[]) -{ - test_function (zsnprintf); - return test_exit_status; -} diff --git a/tests/test-zsnprintf-gnu.h b/tests/test-zsnprintf-gnu.h deleted file mode 100644 index 0e28c588ab..0000000000 --- a/tests/test-zsnprintf-gnu.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Test of POSIX and GNU compatible vzsnprintf() and zsnprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -/* This test exercises only a few POSIX compliance problems that are still - visible on platforms relevant in 2024. For a much more complete test suite, - see test-snprintf-posix.h. */ - -static void -test_function (ptrdiff_t (*my_zsnprintf) (char *, size_t, const char *, ...)) -{ - char result[5000]; - - /* Test the support of the 'B' conversion specifier for binary output of - integers. */ - - { /* This test would fail on all platforms other than glibc ⥠2.35. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%#B %d", 12345, 33, 44, 55); - ASSERT (strcmp (result, "0B11000000111001 33") == 0); - ASSERT (retval == strlen (result)); - } -} diff --git a/tests/test-zsnprintf-posix.c b/tests/test-zsnprintf-posix.c deleted file mode 100644 index 0acefb59dc..0000000000 --- a/tests/test-zsnprintf-posix.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Test of POSIX compatible zsnprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsnprintf-posix.h" - -int -main (int argc, char *argv[]) -{ - test_function (zsnprintf); - return test_exit_status; -} diff --git a/tests/test-zsnprintf-posix.h b/tests/test-zsnprintf-posix.h deleted file mode 100644 index 64639d4f17..0000000000 --- a/tests/test-zsnprintf-posix.h +++ /dev/null @@ -1,183 +0,0 @@ -/* Test of POSIX compatible vzsnprintf() and zsnprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -/* This test exercises only a few POSIX compliance problems that are still - visible on platforms relevant in 2024. For a much more complete test suite, - see test-snprintf-posix.h. */ - -#include "infinity.h" -#include "nan.h" - -/* Test whether string[start_index..end_index-1] is a valid textual - representation of NaN. */ -static int -strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) -{ - if (start_index < end_index) - { - if (string[start_index] == '-') - start_index++; - if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } - } - return 0; -} - -static void -test_function (ptrdiff_t (*my_zsnprintf) (char *, size_t, const char *, ...)) -{ - char result[5000]; - - /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal - output of floating-point numbers. */ - - { /* This test would fail on Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%a %d", 3.1416015625, 33, 44, 55); - ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%A %d", -3.1416015625, 33, 44, 55); - ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on FreeBSD 6.1, NetBSD 10.0. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%.2a %d", 1.51, 33, 44, 55); - ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on macOS 14, FreeBSD 14.0, OpenBSD 7.5, AIX 7.3, - Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%.0a %d", 1.51, 33, 44, 55); - ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the %f format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%f %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%f %d", NaNd (), 33, 44, 55); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%010f %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, " inf 33") == 0 - || strcmp (result, " infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the %e format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%e %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%e %d", NaNd (), 33, 44, 55); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the %g format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%g %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%g %d", NaNd (), 33, 44, 55); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of large precision. */ - - { /* This test would fail on AIX 7.1. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%.4000d %d", 1234567, 99); - size_t i; - for (i = 0; i < 4000 - 7; i++) - ASSERT (result[i] == '0'); - ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the 'b' conversion specifier for binary output of - integers. */ - - { /* This test would fail on glibc 2.34, musl libc, macOS 14, - FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsnprintf (result, sizeof (result), "%b %d", 12345, 33, 44, 55); - ASSERT (strcmp (result, "11000000111001 33") == 0); - ASSERT (retval == strlen (result)); - } -} diff --git a/tests/test-zsprintf-gnu.c b/tests/test-zsprintf-gnu.c deleted file mode 100644 index 8f95471d13..0000000000 --- a/tests/test-zsprintf-gnu.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Test of POSIX and GNU compatible zsprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsprintf-gnu.h" - -int -main (int argc, char *argv[]) -{ - test_function (zsprintf); - return test_exit_status; -} diff --git a/tests/test-zsprintf-gnu.h b/tests/test-zsprintf-gnu.h deleted file mode 100644 index d33a18f6f4..0000000000 --- a/tests/test-zsprintf-gnu.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Test of POSIX and GNU compatible vzsprintf() and zsprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -/* This test exercises only a few POSIX compliance problems that are still - visible on platforms relevant in 2024. For a much more complete test suite, - see test-sprintf-posix.h. */ - -static void -test_function (ptrdiff_t (*my_zsprintf) (char *, const char *, ...)) -{ - char result[5000]; - - /* Test the support of the 'B' conversion specifier for binary output of - integers. */ - - { /* This test would fail on all platforms other than glibc ⥠2.35. */ - ptrdiff_t retval = - my_zsprintf (result, "%#B %d", 12345, 33, 44, 55); - ASSERT (strcmp (result, "0B11000000111001 33") == 0); - ASSERT (retval == strlen (result)); - } -} diff --git a/tests/test-zsprintf-posix.c b/tests/test-zsprintf-posix.c deleted file mode 100644 index b5af845b15..0000000000 --- a/tests/test-zsprintf-posix.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Test of POSIX compatible zsprintf() function. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2007. */ - -#include <config.h> - -#include <stdio.h> - -#include <stdarg.h> -#include <stddef.h> -#include <string.h> - -#include "macros.h" - -#include "test-zsprintf-posix.h" - -int -main (int argc, char *argv[]) -{ - test_function (zsprintf); - return test_exit_status; -} diff --git a/tests/test-zsprintf-posix.h b/tests/test-zsprintf-posix.h deleted file mode 100644 index c12754970d..0000000000 --- a/tests/test-zsprintf-posix.h +++ /dev/null @@ -1,183 +0,0 @@ -/* Test of POSIX compatible vzsprintf() and zsprintf() functions. - Copyright (C) 2007-2024 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 of the License, 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/>. */ - -/* Written by Bruno Haible <bruno@clisp.org>, 2024. */ - -/* This test exercises only a few POSIX compliance problems that are still - visible on platforms relevant in 2024. For a much more complete test suite, - see test-sprintf-posix.h. */ - -#include "infinity.h" -#include "nan.h" - -/* Test whether string[start_index..end_index-1] is a valid textual - representation of NaN. */ -static int -strisnan (const char *string, size_t start_index, size_t end_index, int uppercase) -{ - if (start_index < end_index) - { - if (string[start_index] == '-') - start_index++; - if (start_index + 3 <= end_index - && memcmp (string + start_index, uppercase ? "NAN" : "nan", 3) == 0) - { - start_index += 3; - if (start_index == end_index - || (string[start_index] == '(' && string[end_index - 1] == ')')) - return 1; - } - } - return 0; -} - -static void -test_function (ptrdiff_t (*my_zsprintf) (char *, const char *, ...)) -{ - char result[5000]; - - /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal - output of floating-point numbers. */ - - { /* This test would fail on Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%a %d", 3.1416015625, 33, 44, 55); - ASSERT (strcmp (result, "0x1.922p+1 33") == 0 - || strcmp (result, "0x3.244p+0 33") == 0 - || strcmp (result, "0x6.488p-1 33") == 0 - || strcmp (result, "0xc.91p-2 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%A %d", -3.1416015625, 33, 44, 55); - ASSERT (strcmp (result, "-0X1.922P+1 33") == 0 - || strcmp (result, "-0X3.244P+0 33") == 0 - || strcmp (result, "-0X6.488P-1 33") == 0 - || strcmp (result, "-0XC.91P-2 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on FreeBSD 6.1, NetBSD 10.0. */ - ptrdiff_t retval = - my_zsprintf (result, "%.2a %d", 1.51, 33, 44, 55); - ASSERT (strcmp (result, "0x1.83p+0 33") == 0 - || strcmp (result, "0x3.05p-1 33") == 0 - || strcmp (result, "0x6.0ap-2 33") == 0 - || strcmp (result, "0xc.14p-3 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on macOS 14, FreeBSD 14.0, OpenBSD 7.5, AIX 7.3, - Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%.0a %d", 1.51, 33, 44, 55); - ASSERT (strcmp (result, "0x2p+0 33") == 0 - || strcmp (result, "0x3p-1 33") == 0 - || strcmp (result, "0x6p-2 33") == 0 - || strcmp (result, "0xcp-3 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the %f format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%f %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%f %d", NaNd (), 33, 44, 55); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%010f %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, " inf 33") == 0 - || strcmp (result, " infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the %e format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%e %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%e %d", NaNd (), 33, 44, 55); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the %g format directive. */ - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%g %d", Infinityd (), 33, 44, 55); - ASSERT (strcmp (result, "inf 33") == 0 - || strcmp (result, "infinity 33") == 0); - ASSERT (retval == strlen (result)); - } - - { /* This test would fail on AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%g %d", NaNd (), 33, 44, 55); - ASSERT (strlen (result) >= 3 + 3 - && strisnan (result, 0, strlen (result) - 3, 0) - && strcmp (result + strlen (result) - 3, " 33") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of large precision. */ - - { /* This test would fail on AIX 7.1. */ - ptrdiff_t retval = - my_zsprintf (result, "%.4000d %d", 1234567, 99); - size_t i; - for (i = 0; i < 4000 - 7; i++) - ASSERT (result[i] == '0'); - ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); - ASSERT (retval == strlen (result)); - } - - /* Test the support of the 'b' conversion specifier for binary output of - integers. */ - - { /* This test would fail on glibc 2.34, musl libc, macOS 14, - FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */ - ptrdiff_t retval = - my_zsprintf (result, "%b %d", 12345, 33, 44, 55); - ASSERT (strcmp (result, "11000000111001 33") == 0); - ASSERT (retval == strlen (result)); - } -}