* lib/vasprintf.c: Include <stdint.h>.
(vasprintf): If the length is > PTRDIFF_MAX, fail with ENOMEM, not
EOVERFLOW.
* modules/vasprintf (Depends-on): Add stdint.
2024-06-22 Bruno Haible <bruno@clisp.org>
+ vasprintf: Make return convention consistent with other modules.
+ * lib/vasprintf.c: Include <stdint.h>.
+ (vasprintf): If the length is > PTRDIFF_MAX, fail with ENOMEM, not
+ EOVERFLOW.
+ * modules/vasprintf (Depends-on): Add stdint.
+
vazsprintf: New module.
* lib/stdio.in.h (azsprintf, vazsprintf): New declarations.
* lib/vazsprintf.c: New file, based on lib/vasprintf.c.
#include <errno.h>
#include <limits.h>
+#include <stdint.h>
#include <stdlib.h>
#include "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. */
extensions
vasnprintf [test $HAVE_VASPRINTF = 0 || test $REPLACE_VASPRINTF = 1]
errno [test $HAVE_VASPRINTF = 0 || test $REPLACE_VASPRINTF = 1]
+stdint [test $HAVE_VASPRINTF = 0 || test $REPLACE_VASPRINTF = 1]
configure.ac:
gl_FUNC_VASPRINTF