[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xprintf, xprintf-posix, xprintf-gnu: Use *zprintf
From: |
Bruno Haible |
Subject: |
xprintf, xprintf-posix, xprintf-gnu: Use *zprintf |
Date: |
Wed, 25 Dec 2024 19:30:17 +0100 |
The *zprintf patches from end of June 2024 are not yet complete. The
only remaining modules with *printf functions which have an 'int' return
type are
xprintf, xprintf-posix, xprintf-gnu.
It appears from looking at the code that invokes the functions x[v][f]printf
(cf. maint-tools/code-search.txt) that all users ignore the return value.
Therefore we don't need new modules
xzprintf, xzprintf-posix, xzprintf-gnu
but can instead just reuse these modules and merely change the return type.
Done through this patch:
2024-12-25 Bruno Haible <bruno@clisp.org>
xprintf, xprintf-posix, xprintf-gnu: Use *zprintf.
* lib/xprintf.h (xprintf, xvprintf, xfprintf, xvfprintf): Change return
type to off64_t. Move documentation from xprintf.c to here. Mention
EOVERFLOW as another possible error unrelated to file I/O.
* lib/xprintf.c (xprintf): Change return type to off64_t.
(xvprintf): Likewise. Use vzprintf.
(xfprintf): Change return type to off64_t.
(xvfprintf): Likewise. Use vfzprintf.
* modules/xprintf (Description): Mention also fprintf. Mention EOVERFLOW
as another possible error unrelated to file I/O.
(Depends-on): Add vzprintf, vfzprintf.
* modules/xprintf-posix (Description): Mention also fprintf. Mention
EOVERFLOW as another possible error unrelated to file I/O.
(Depends-on): Add vzprintf-posix, vfzprintf-posix. Remove vprintf-posix,
vfprintf-posix.
* modules/xprintf-gnu (Description): Mention also fprintf. Mention
EOVERFLOW as another possible error unrelated to file I/O.
(Depends-on): Add vzprintf-gnu, vfzprintf-gnu. Remove vprintf-gnu,
vfprintf-gnu.
* tests/test-xprintf-posix.c (RETTYPE): Change to off64_t.
* tests/test-xfprintf-posix.c (RETTYPE): Likewise.
* NEWS: Document the change.
diff --git a/NEWS b/NEWS
index 9e08bd1048..e64d1583f8 100644
--- a/NEWS
+++ b/NEWS
@@ -74,6 +74,9 @@ User visible incompatible changes
Date Modules Changes
+2024-12-25 xprintf The functions x[v][f]printf now return an 'off64_t'
+ instead of an 'int'.
+
2024-11-05 eealloc This module is deprecated. Use malloc-gnu or
realloc-posix instead.
diff --git a/lib/xprintf.c b/lib/xprintf.c
index 732bbea407..5d01874b63 100644
--- a/lib/xprintf.c
+++ b/lib/xprintf.c
@@ -14,6 +14,8 @@
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 Jim Meyering */
+
#include <config.h>
#include "xprintf.h"
@@ -26,15 +28,11 @@
#define _(msgid) dgettext ("gnulib", msgid)
-/* written by Jim Meyering */
-
-/* Just like printf, but call error if it fails without setting the
- stream's error indicator. */
-int
+off64_t
xprintf (char const *restrict format, ...)
{
va_list args;
- int retval;
+ off64_t retval;
va_start (args, format);
retval = xvprintf (format, args);
va_end (args);
@@ -42,25 +40,21 @@ xprintf (char const *restrict format, ...)
return retval;
}
-/* Just like vprintf, but call error if it fails without setting the
- stream's error indicator. */
-int
+off64_t
xvprintf (char const *restrict format, va_list args)
{
- int retval = vprintf (format, args);
+ off64_t retval = vzprintf (format, args);
if (retval < 0 && ! ferror (stdout))
error (exit_failure, errno, _("cannot perform formatted output"));
return retval;
}
-/* Just like fprintf, but call error if it fails without setting the
- stream's error indicator. */
-int
+off64_t
xfprintf (FILE *restrict stream, char const *restrict format, ...)
{
va_list args;
- int retval;
+ off64_t retval;
va_start (args, format);
retval = xvfprintf (stream, format, args);
va_end (args);
@@ -68,12 +62,10 @@ xfprintf (FILE *restrict stream, char const *restrict
format, ...)
return retval;
}
-/* Just like vfprintf, but call error if it fails without setting the
- stream's error indicator. */
-int
+off64_t
xvfprintf (FILE *restrict stream, char const *restrict format, va_list args)
{
- int retval = vfprintf (stream, format, args);
+ off64_t retval = vfzprintf (stream, format, args);
if (retval < 0 && ! ferror (stream))
error (exit_failure, errno, _("cannot perform formatted output"));
diff --git a/lib/xprintf.h b/lib/xprintf.h
index 202dbd2022..c30b5080a0 100644
--- a/lib/xprintf.h
+++ b/lib/xprintf.h
@@ -1,4 +1,4 @@
-/* printf wrappers that fail immediately for non-file-related errors
+/* printf and fprintf wrappers that fail immediately for non-file-related
errors
Copyright (C) 2007-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -30,7 +30,9 @@ extern "C" {
#endif
-extern int xprintf (char const *restrict format, ...)
+/* Like zprintf, but call error if it fails without setting stdout's
+ error indicator, i.e. upon ENOMEM, EOVERFLOW, or EILSEQ errors. */
+extern off64_t xprintf (char const *restrict format, ...)
#if GNULIB_VPRINTF_POSIX
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 2))
#else
@@ -38,7 +40,9 @@ extern int xprintf (char const *restrict format, ...)
#endif
;
-extern int xvprintf (char const *restrict format, va_list args)
+/* Like vzprintf, but call error if it fails without setting stdout's
+ error indicator, i.e. upon ENOMEM, EOVERFLOW, or EILSEQ errors. */
+extern off64_t xvprintf (char const *restrict format, va_list args)
#if GNULIB_VPRINTF_POSIX
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 0))
#else
@@ -46,7 +50,10 @@ extern int xvprintf (char const *restrict format, va_list
args)
#endif
;
-extern int xfprintf (FILE *restrict stream, char const *restrict format, ...)
+/* Like fzprintf, but call error if it fails without setting the stream's
+ error indicator, i.e. upon ENOMEM, EOVERFLOW, or EILSEQ errors. */
+extern off64_t xfprintf (FILE *restrict stream, char const *restrict format,
+ ...)
#if GNULIB_VFPRINTF_POSIX
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3))
#else
@@ -54,8 +61,10 @@ extern int xfprintf (FILE *restrict stream, char const
*restrict format, ...)
#endif
;
-extern int xvfprintf (FILE *restrict stream, char const *restrict format,
- va_list args)
+/* Like vfzprintf, but call error if it fails without setting the stream's
+ error indicator, i.e. upon ENOMEM, EOVERFLOW, or EILSEQ errors. */
+extern off64_t xvfprintf (FILE *restrict stream, char const *restrict format,
+ va_list args)
#if GNULIB_VFPRINTF_POSIX
_GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0))
#else
diff --git a/modules/xprintf b/modules/xprintf
index 79c82d9168..dfe8cbe114 100644
--- a/modules/xprintf
+++ b/modules/xprintf
@@ -1,5 +1,6 @@
Description:
-a wrapper around printf that calls error upon ENOMEM or EILSEQ errors
+Wrappers around printf and fprintf that call error
+upon ENOMEM, EOVERFLOW, or EILSEQ errors.
Files:
lib/xprintf.h
@@ -12,6 +13,8 @@ exitfail
gettext-h
gnulib-i18n
stdarg
+vzprintf
+vfzprintf
configure.ac:
m4_ifdef([AM_XGETTEXT_OPTION],
diff --git a/modules/xprintf-gnu b/modules/xprintf-gnu
index c0fd3f062b..704a5fde6d 100644
--- a/modules/xprintf-gnu
+++ b/modules/xprintf-gnu
@@ -1,6 +1,7 @@
Description:
-A wrapper around printf with POSIX and GNU compatible format string
-interpretation, that calls error upon ENOMEM or EILSEQ errors.
+Wrappers around printf and fprintf
+with POSIX and GNU compatible format string interpretation,
+that calls error upon ENOMEM, EOVERFLOW, or EILSEQ errors.
Comment:
This module should not be used as a dependency from a test module,
@@ -12,8 +13,8 @@ Files:
Depends-on:
xprintf
-vprintf-gnu
-vfprintf-gnu
+vzprintf-gnu
+vfzprintf-gnu
configure.ac:
diff --git a/modules/xprintf-posix b/modules/xprintf-posix
index 5335d5c9c0..98e7c6df20 100644
--- a/modules/xprintf-posix
+++ b/modules/xprintf-posix
@@ -1,6 +1,7 @@
Description:
-A wrapper around printf with POSIX compatible format string interpretation,
-that calls error upon ENOMEM or EILSEQ errors.
+Wrappers around printf and fprintf
+with POSIX compatible format string interpretation,
+that calls error upon ENOMEM, EOVERFLOW, or EILSEQ errors.
Comment:
This module should not be used as a dependency from a test module,
@@ -12,8 +13,8 @@ Files:
Depends-on:
xprintf
-vprintf-posix
-vfprintf-posix
+vzprintf-posix
+vfzprintf-posix
configure.ac:
diff --git a/tests/test-xfprintf-posix.c b/tests/test-xfprintf-posix.c
index 18a3a0dfd9..373d95b829 100644
--- a/tests/test-xfprintf-posix.c
+++ b/tests/test-xfprintf-posix.c
@@ -26,7 +26,7 @@
#include "macros.h"
-#define RETTYPE int
+#define RETTYPE off64_t
#include "test-fprintf-posix.h"
int
diff --git a/tests/test-xprintf-posix.c b/tests/test-xprintf-posix.c
index c9e79c0e26..38e5c2c9d6 100644
--- a/tests/test-xprintf-posix.c
+++ b/tests/test-xprintf-posix.c
@@ -26,7 +26,7 @@
#include "macros.h"
-#define RETTYPE int
+#define RETTYPE off64_t
#include "test-printf-posix.h"
int
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- xprintf, xprintf-posix, xprintf-gnu: Use *zprintf,
Bruno Haible <=