* lib/c-vasprintf.h (c_asprintf, c_vasprintf): Add specification.
* lib/c-asprintf.c: Replaced with code based on lib/asprintf.c.
* lib/c-vasprintf.c: Replaced with code based on lib/vasprintf.c.
* modules/c-vasprintf (Depends-on): Add stdint.
(License): Change to LGPLv2+.
2024-06-22 Bruno Haible <bruno@clisp.org>
+ c-vasprintf: Make return convention consistent with other modules.
+ * lib/c-vasprintf.h (c_asprintf, c_vasprintf): Add specification.
+ * lib/c-asprintf.c: Replaced with code based on lib/asprintf.c.
+ * lib/c-vasprintf.c: Replaced with code based on lib/vasprintf.c.
+ * modules/c-vasprintf (Depends-on): Add stdint.
+ (License): Change to LGPLv2+.
+
c-vazsprintf: New module.
* lib/c-vasprintf.h: Change license to LGPLv2+.
Include <stddef.h>.
Inc.
This file 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.
+ 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 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/>. */
#include <config.h>
Copyright (C) 1999, 2002, 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 General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+ 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 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/>. */
#include <config.h>
#include <errno.h>
#include <limits.h>
+#include <stdint.h>
#include <stdlib.h>
#include "c-vasnprintf.h"
if (result == NULL)
return -1;
+#if PTRDIFF_MAX > INT_MAX
if (length > INT_MAX)
{
free (result);
- errno = EOVERFLOW;
+ errno = (length > PTRDIFF_MAX ? ENOMEM : EOVERFLOW);
return -1;
}
+#else
+ if (length > PTRDIFF_MAX)
+ {
+ free (result);
+ errno = ENOMEM;
+ return -1;
+ }
+#endif
*resultp = result;
/* Return the number of resulting bytes, excluding the trailing NUL. */
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
- '.'. */
+/* 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.
+
+ Formatting takes place in the C locale, that is, the decimal point
+ used in floating-point formatting directives is always '.'. */
int c_asprintf (char **resultp, const char *format, ...)
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3));
int c_vasprintf (char **resultp, const char *format, va_list args)
lib/c-vasprintf.c
Depends-on:
+stdint
stdio
c-vasnprintf
"c-vasprintf.h"
License:
-GPL
+LGPLv2+
Maintainer:
Ben Pfaff