]> Savannah Git Hosting - gnulib.git/commitdiff
c-vasprintf: Make return convention consistent with other modules.
authorBruno Haible <bruno@clisp.org>
Sat, 22 Jun 2024 10:21:51 +0000 (12:21 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 22 Jun 2024 10:22:05 +0000 (12:22 +0200)
* 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+.

ChangeLog
lib/c-asprintf.c
lib/c-vasprintf.c
lib/c-vasprintf.h
modules/c-vasprintf

index 7a2dd7375cd7b68045989506359447d7620937db..f3aec5b9280dce26e6711db1bbd4fb626de01e97 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 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>.
index c6f771953162eb0d6639df329f5da0d00beeebe0..f626c5207b368ea98073b5fb29f3843e43e5622c 100644 (file)
@@ -3,16 +3,16 @@
    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>
index 5adaec93f2d427b99e09a6563883ac0a214b31ca..81d45ce0ace2b12b0aba0794281e41b84cbfc32d 100644 (file)
@@ -2,16 +2,16 @@
    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>
@@ -21,6 +21,7 @@
 
 #include <errno.h>
 #include <limits.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "c-vasnprintf.h"
@@ -33,12 +34,21 @@ c_vasprintf (char **resultp, const char *format, va_list args)
   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.  */
index 7eae757e3a643edef445784488c4c4322cb0665c..bcd40bd5e012a7ae6bb4e49dcac80a7cbb3c6640 100644 (file)
@@ -52,9 +52,13 @@ ptrdiff_t c_azsprintf (char **resultp, const char *format, ...)
 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)
index 868dc16d10853c68a9e1c8257d4688d676bf893a..8b012daabe8d863ecd93eac0c79842e371c080f8 100644 (file)
@@ -7,6 +7,7 @@ lib/c-asprintf.c
 lib/c-vasprintf.c
 
 Depends-on:
+stdint
 stdio
 c-vasnprintf
 
@@ -19,7 +20,7 @@ Include:
 "c-vasprintf.h"
 
 License:
-GPL
+LGPLv2+
 
 Maintainer:
 Ben Pfaff