* lib/c-vasprintf.h: Change license to LGPLv2+.
Include <stddef.h>.
(c_azsprintf, c_vazsprintf): New declarations.
* lib/c-azsprintf.c: New file, based on lib/azsprintf.c.
* lib/c-vazsprintf.c: New file, based on lib/vazsprintf.c.
* modules/c-vazsprintf: New file.
+2024-06-22 Bruno Haible <bruno@clisp.org>
+
+ c-vazsprintf: New module.
+ * lib/c-vasprintf.h: Change license to LGPLv2+.
+ Include <stddef.h>.
+ (c_azsprintf, c_vazsprintf): New declarations.
+ * lib/c-azsprintf.c: New file, based on lib/azsprintf.c.
+ * lib/c-vazsprintf.c: New file, based on lib/vazsprintf.c.
+ * modules/c-vazsprintf: New file.
+
2024-06-22 Bruno Haible <bruno@clisp.org>
c-snprintf: Use c-vzsnprintf.
--- /dev/null
+/* 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;
+}
/* vasprintf and asprintf, in C locale.
Copyright (C) 2002-2004, 2006-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 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 program is distributed in the hope that it will be useful,
+ 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 General Public License for more details.
+ GNU Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
+ 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/>. */
#ifndef _C_VASPRINTF_H
/* Get va_list. */
#include <stdarg.h>
+/* Get ptrdiff_t. */
+#include <stddef.h>
+
/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */
#include <stdio.h>
extern "C" {
#endif
+/* 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
+ NUL. Upon memory allocation error, or some other error, it 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.
+
+ 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, ...)
+ _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3));
+ptrdiff_t c_vazsprintf (char **resultp, const char *format, va_list args)
+ _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0));
+
/* asprintf() and vasprintf(), but formatting takes place in the C locale, that
is, the decimal point used in floating-point formatting directives is always
'.'. */
--- /dev/null
+/* 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;
+}
--- /dev/null
+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