diff mbox series

[06/11] stdio: Rename __printf_buffer to __vfprintf_buffer

Message ID c23bed2f8fed8be96f0b56f3b81430515e6ccf24.1707491940.git.fweimer@redhat.com
State New
Headers show
Series Build getdomainname, gethostname, syslog with fortification | expand

Commit Message

Florian Weimer Feb. 9, 2024, 3:25 p.m. UTC
And __wprintf_buffer to __vwprintf_buffer.  These functions take
a va_list argument, so they are closer to the v-variant functions
in <stdio.h>.

Also move the declaration to <printf_buffer.h>, which is arguably
a better fit than <printf.h> (which contains lots of printf
internals).
---
 include/printf.h                 |  9 +--------
 include/printf_buffer.h          |  9 +++++++++
 libio/iovdprintf.c               |  2 +-
 libio/iovsprintf.c               |  2 +-
 libio/obprintf.c                 |  2 +-
 libio/vasprintf.c                |  2 +-
 libio/vsnprintf.c                |  2 +-
 libio/vswprintf.c                |  2 +-
 stdio-common/vfprintf-internal.c | 10 ++++++----
 9 files changed, 22 insertions(+), 18 deletions(-)

Comments

Adhemerval Zanella Netto Feb. 16, 2024, 1:40 p.m. UTC | #1
On 09/02/24 12:25, Florian Weimer wrote:
> And __wprintf_buffer to __vwprintf_buffer.  These functions take
> a va_list argument, so they are closer to the v-variant functions
> in <stdio.h>.
> 
> Also move the declaration to <printf_buffer.h>, which is arguably
> a better fit than <printf.h> (which contains lots of printf
> internals).

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  include/printf.h                 |  9 +--------
>  include/printf_buffer.h          |  9 +++++++++
>  libio/iovdprintf.c               |  2 +-
>  libio/iovsprintf.c               |  2 +-
>  libio/obprintf.c                 |  2 +-
>  libio/vasprintf.c                |  2 +-
>  libio/vsnprintf.c                |  2 +-
>  libio/vswprintf.c                |  2 +-
>  stdio-common/vfprintf-internal.c | 10 ++++++----
>  9 files changed, 22 insertions(+), 18 deletions(-)
> 
> diff --git a/include/printf.h b/include/printf.h
> index 2c998059d4..78aac4dcad 100644
> --- a/include/printf.h
> +++ b/include/printf.h
> @@ -65,18 +65,11 @@ int __translated_number_width (locale_t loc,
>  			       const char *first, const char *last)
>    attribute_hidden;
>  
> -
> -struct __printf_buffer;
> -void __printf_buffer (struct __printf_buffer *buf, const char *format,
> -		      va_list ap, unsigned int mode_flags);
> -struct __wprintf_buffer;
> -void __wprintf_buffer (struct __wprintf_buffer *buf, const wchar_t *format,
> -		       va_list ap, unsigned int mode_flags);
> -
>  extern int __printf_fp (FILE *, const struct printf_info *,
>  			const void *const *);
>  libc_hidden_proto (__printf_fp)
>  
> +struct __printf_buffer;
>  void __printf_fphex_l_buffer (struct __printf_buffer *, locale_t,
>  			      const struct printf_info *,
>  			      const void *const *) attribute_hidden;
> diff --git a/include/printf_buffer.h b/include/printf_buffer.h
> index eff8e3413a..fb0b42178e 100644
> --- a/include/printf_buffer.h
> +++ b/include/printf_buffer.h
> @@ -200,6 +200,12 @@ int __printf_buffer_done (struct __printf_buffer *buf) attribute_hidden;
>     known, and the flush implementation can be called directly.  */
>  bool __printf_buffer_flush (struct __printf_buffer *buf) attribute_hidden;
>  
> +/* Building block for printf-style functions.  Write argument list AP
> +   to BUF according to FORMAT.  MODE_FLAGS contains PRINTF_* flags
> +   defined in <libioP.h>.  */
> +void __vprintf_buffer (struct __printf_buffer *buf, const char *format,
> +                       va_list ap, unsigned int mode_flags) attribute_hidden;
> +
>  /* Wide version of struct __printf_buffer follows.  */
>  
>  enum __wprintf_buffer_mode
> @@ -274,6 +280,9 @@ int __wprintf_buffer_done (struct __wprintf_buffer *buf) attribute_hidden;
>  
>  bool __wprintf_buffer_flush (struct __wprintf_buffer *buf) attribute_hidden;
>  
> +void __vwprintf_buffer (struct __wprintf_buffer *buf, const wchar_t *format,
> +                        va_list ap, unsigned int mode_flags) attribute_hidden;
> +
>  /* Type-generic convenience macros.  They are useful if
>     printf_buffer-char.h or printf_buffer-wchar_t.h is included as
>     well.  */
> diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c
> index 6894fa8347..47d9d0ba8f 100644
> --- a/libio/iovdprintf.c
> +++ b/libio/iovdprintf.c
> @@ -66,7 +66,7 @@ __vdprintf_internal (int d, const char *format, va_list arg,
>    __printf_buffer_init (&buf.base, buf.buf, array_length (buf.buf),
>  			__printf_buffer_mode_dprintf);
>    buf.fd = d;
> -  __printf_buffer (&buf.base, format, arg, mode_flags);
> +  __vprintf_buffer (&buf.base, format, arg, mode_flags);
>    if (__printf_buffer_has_failed (&buf.base))
>      return -1;
>    __printf_buffer_flush_dprintf (&buf);
> diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c
> index 2d81ee3507..7fdc06dcd4 100644
> --- a/libio/iovsprintf.c
> +++ b/libio/iovsprintf.c
> @@ -59,7 +59,7 @@ __vsprintf_internal (char *string, size_t maxlen,
>      __printf_buffer_init_end (&buf, string, (char *) ~(uintptr_t) 0,
>  			      __printf_buffer_mode_sprintf);
>  
> -  __printf_buffer (&buf, format, args, mode_flags);
> +  __vprintf_buffer (&buf, format, args, mode_flags);
>  
>    /* Write the NUL terminator if there is room.  Do not use the putc
>       operation to avoid overflowing the character write count.  */
> diff --git a/libio/obprintf.c b/libio/obprintf.c
> index 491d14fbae..24d1edf260 100644
> --- a/libio/obprintf.c
> +++ b/libio/obprintf.c
> @@ -92,7 +92,7 @@ __obstack_vprintf_internal (struct obstack *obstack, const char *format,
>    /* Now allocate the rest of the current chunk.  */
>    obstack_blank_fast (obstack, room);
>  
> -  __printf_buffer (&buf.base, format, args, mode_flags);
> +  __vprintf_buffer (&buf.base, format, args, mode_flags);
>  
>    if (buf.base.write_ptr == &buf.ch + 1)
>      /* buf.ch is in use.  Put it into the obstack.  */
> diff --git a/libio/vasprintf.c b/libio/vasprintf.c
> index 999ae526f4..edcfab2323 100644
> --- a/libio/vasprintf.c
> +++ b/libio/vasprintf.c
> @@ -99,7 +99,7 @@ __vasprintf_internal (char **result_ptr, const char *format, va_list args,
>    __printf_buffer_init (&buf.base, buf.direct, array_length (buf.direct),
>  			__printf_buffer_mode_asprintf);
>  
> -  __printf_buffer (&buf.base, format, args, mode_flags);
> +  __vprintf_buffer (&buf.base, format, args, mode_flags);
>    int done = __printf_buffer_done (&buf.base);
>    if (done < 0)
>      {
> diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c
> index dd7a585cbe..7077fcd9f2 100644
> --- a/libio/vsnprintf.c
> +++ b/libio/vsnprintf.c
> @@ -93,7 +93,7 @@ __vsnprintf_internal (char *string, size_t maxlen, const char *format,
>  {
>    struct __printf_buffer_snprintf buf;
>    __printf_buffer_snprintf_init (&buf, string, maxlen);
> -  __printf_buffer (&buf.base, format, args, mode_flags);
> +  __vprintf_buffer (&buf.base, format, args, mode_flags);
>    return __printf_buffer_snprintf_done (&buf);
>  }
>  
> diff --git a/libio/vswprintf.c b/libio/vswprintf.c
> index 5990bd2eff..d73246ba41 100644
> --- a/libio/vswprintf.c
> +++ b/libio/vswprintf.c
> @@ -41,7 +41,7 @@ __vswprintf_internal (wchar_t *string, size_t maxlen, const wchar_t *format,
>    struct __wprintf_buffer buf;
>    __wprintf_buffer_init (&buf, string, maxlen, __wprintf_buffer_mode_swprintf);
>  
> -  __wprintf_buffer (&buf, format, args, mode_flags);
> +  __vwprintf_buffer (&buf, format, args, mode_flags);
>  
>    if (buf.write_ptr == buf.write_end)
>      {
> diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
> index 771beca9bf..23754232f2 100644
> --- a/stdio-common/vfprintf-internal.c
> +++ b/stdio-common/vfprintf-internal.c
> @@ -122,6 +122,7 @@
>  
>  #ifndef COMPILE_WPRINTF
>  # include "printf_buffer-char.h"
> +# define VFPRINTF_BUFFER __vprintf_buffer
>  # define vfprintf	__vfprintf_internal
>  # define OTHER_CHAR_T   wchar_t
>  # define UCHAR_T	unsigned char
> @@ -136,6 +137,7 @@ typedef const char *THOUSANDS_SEP_T;
>  # define CONVERT_FROM_OTHER_STRING __wcsrtombs
>  #else
>  # include "printf_buffer-wchar_t.h"
> +# define VFPRINTF_BUFFER __vwprintf_buffer
>  # define vfprintf	__vfwprintf_internal
>  # define OTHER_CHAR_T   char
>  /* This is a hack!!!  There should be a type uwchar_t.  */
> @@ -595,8 +597,8 @@ static void group_number (struct Xprintf_buffer *buf,
>  
>  /* The buffer-based function itself.  */
>  void
> -Xprintf_buffer (struct Xprintf_buffer *buf, const CHAR_T *format,
> -		  va_list ap, unsigned int mode_flags)
> +VFPRINTF_BUFFER (struct Xprintf_buffer *buf, const CHAR_T *format,
> +		 va_list ap, unsigned int mode_flags)
>  {
>    /* The character used as thousands separator.  */
>    THOUSANDS_SEP_T thousands_sep = 0;
> @@ -1541,7 +1543,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap, unsigned int mode_flags)
>      {
>        struct Xprintf (buffer_to_file) wrap;
>        Xprintf (buffer_to_file_init) (&wrap, s);
> -      Xprintf_buffer (&wrap.base, format, ap, mode_flags);
> +      VFPRINTF_BUFFER (&wrap.base, format, ap, mode_flags);
>        return Xprintf (buffer_to_file_done) (&wrap);
>      }
>  
> @@ -1556,7 +1558,7 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap, unsigned int mode_flags)
>    Xprintf (buffer_to_file_init) (&wrap, s);
>  
>    /* Perform the printing operation on the buffer.  */
> -  Xprintf_buffer (&wrap.base, format, ap, mode_flags);
> +  VFPRINTF_BUFFER (&wrap.base, format, ap, mode_flags);
>    done = Xprintf (buffer_to_file_done) (&wrap);
>  
>    /* Unlock the stream.  */
diff mbox series

Patch

diff --git a/include/printf.h b/include/printf.h
index 2c998059d4..78aac4dcad 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -65,18 +65,11 @@  int __translated_number_width (locale_t loc,
 			       const char *first, const char *last)
   attribute_hidden;
 
-
-struct __printf_buffer;
-void __printf_buffer (struct __printf_buffer *buf, const char *format,
-		      va_list ap, unsigned int mode_flags);
-struct __wprintf_buffer;
-void __wprintf_buffer (struct __wprintf_buffer *buf, const wchar_t *format,
-		       va_list ap, unsigned int mode_flags);
-
 extern int __printf_fp (FILE *, const struct printf_info *,
 			const void *const *);
 libc_hidden_proto (__printf_fp)
 
+struct __printf_buffer;
 void __printf_fphex_l_buffer (struct __printf_buffer *, locale_t,
 			      const struct printf_info *,
 			      const void *const *) attribute_hidden;
diff --git a/include/printf_buffer.h b/include/printf_buffer.h
index eff8e3413a..fb0b42178e 100644
--- a/include/printf_buffer.h
+++ b/include/printf_buffer.h
@@ -200,6 +200,12 @@  int __printf_buffer_done (struct __printf_buffer *buf) attribute_hidden;
    known, and the flush implementation can be called directly.  */
 bool __printf_buffer_flush (struct __printf_buffer *buf) attribute_hidden;
 
+/* Building block for printf-style functions.  Write argument list AP
+   to BUF according to FORMAT.  MODE_FLAGS contains PRINTF_* flags
+   defined in <libioP.h>.  */
+void __vprintf_buffer (struct __printf_buffer *buf, const char *format,
+                       va_list ap, unsigned int mode_flags) attribute_hidden;
+
 /* Wide version of struct __printf_buffer follows.  */
 
 enum __wprintf_buffer_mode
@@ -274,6 +280,9 @@  int __wprintf_buffer_done (struct __wprintf_buffer *buf) attribute_hidden;
 
 bool __wprintf_buffer_flush (struct __wprintf_buffer *buf) attribute_hidden;
 
+void __vwprintf_buffer (struct __wprintf_buffer *buf, const wchar_t *format,
+                        va_list ap, unsigned int mode_flags) attribute_hidden;
+
 /* Type-generic convenience macros.  They are useful if
    printf_buffer-char.h or printf_buffer-wchar_t.h is included as
    well.  */
diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c
index 6894fa8347..47d9d0ba8f 100644
--- a/libio/iovdprintf.c
+++ b/libio/iovdprintf.c
@@ -66,7 +66,7 @@  __vdprintf_internal (int d, const char *format, va_list arg,
   __printf_buffer_init (&buf.base, buf.buf, array_length (buf.buf),
 			__printf_buffer_mode_dprintf);
   buf.fd = d;
-  __printf_buffer (&buf.base, format, arg, mode_flags);
+  __vprintf_buffer (&buf.base, format, arg, mode_flags);
   if (__printf_buffer_has_failed (&buf.base))
     return -1;
   __printf_buffer_flush_dprintf (&buf);
diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c
index 2d81ee3507..7fdc06dcd4 100644
--- a/libio/iovsprintf.c
+++ b/libio/iovsprintf.c
@@ -59,7 +59,7 @@  __vsprintf_internal (char *string, size_t maxlen,
     __printf_buffer_init_end (&buf, string, (char *) ~(uintptr_t) 0,
 			      __printf_buffer_mode_sprintf);
 
-  __printf_buffer (&buf, format, args, mode_flags);
+  __vprintf_buffer (&buf, format, args, mode_flags);
 
   /* Write the NUL terminator if there is room.  Do not use the putc
      operation to avoid overflowing the character write count.  */
diff --git a/libio/obprintf.c b/libio/obprintf.c
index 491d14fbae..24d1edf260 100644
--- a/libio/obprintf.c
+++ b/libio/obprintf.c
@@ -92,7 +92,7 @@  __obstack_vprintf_internal (struct obstack *obstack, const char *format,
   /* Now allocate the rest of the current chunk.  */
   obstack_blank_fast (obstack, room);
 
-  __printf_buffer (&buf.base, format, args, mode_flags);
+  __vprintf_buffer (&buf.base, format, args, mode_flags);
 
   if (buf.base.write_ptr == &buf.ch + 1)
     /* buf.ch is in use.  Put it into the obstack.  */
diff --git a/libio/vasprintf.c b/libio/vasprintf.c
index 999ae526f4..edcfab2323 100644
--- a/libio/vasprintf.c
+++ b/libio/vasprintf.c
@@ -99,7 +99,7 @@  __vasprintf_internal (char **result_ptr, const char *format, va_list args,
   __printf_buffer_init (&buf.base, buf.direct, array_length (buf.direct),
 			__printf_buffer_mode_asprintf);
 
-  __printf_buffer (&buf.base, format, args, mode_flags);
+  __vprintf_buffer (&buf.base, format, args, mode_flags);
   int done = __printf_buffer_done (&buf.base);
   if (done < 0)
     {
diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c
index dd7a585cbe..7077fcd9f2 100644
--- a/libio/vsnprintf.c
+++ b/libio/vsnprintf.c
@@ -93,7 +93,7 @@  __vsnprintf_internal (char *string, size_t maxlen, const char *format,
 {
   struct __printf_buffer_snprintf buf;
   __printf_buffer_snprintf_init (&buf, string, maxlen);
-  __printf_buffer (&buf.base, format, args, mode_flags);
+  __vprintf_buffer (&buf.base, format, args, mode_flags);
   return __printf_buffer_snprintf_done (&buf);
 }
 
diff --git a/libio/vswprintf.c b/libio/vswprintf.c
index 5990bd2eff..d73246ba41 100644
--- a/libio/vswprintf.c
+++ b/libio/vswprintf.c
@@ -41,7 +41,7 @@  __vswprintf_internal (wchar_t *string, size_t maxlen, const wchar_t *format,
   struct __wprintf_buffer buf;
   __wprintf_buffer_init (&buf, string, maxlen, __wprintf_buffer_mode_swprintf);
 
-  __wprintf_buffer (&buf, format, args, mode_flags);
+  __vwprintf_buffer (&buf, format, args, mode_flags);
 
   if (buf.write_ptr == buf.write_end)
     {
diff --git a/stdio-common/vfprintf-internal.c b/stdio-common/vfprintf-internal.c
index 771beca9bf..23754232f2 100644
--- a/stdio-common/vfprintf-internal.c
+++ b/stdio-common/vfprintf-internal.c
@@ -122,6 +122,7 @@ 
 
 #ifndef COMPILE_WPRINTF
 # include "printf_buffer-char.h"
+# define VFPRINTF_BUFFER __vprintf_buffer
 # define vfprintf	__vfprintf_internal
 # define OTHER_CHAR_T   wchar_t
 # define UCHAR_T	unsigned char
@@ -136,6 +137,7 @@  typedef const char *THOUSANDS_SEP_T;
 # define CONVERT_FROM_OTHER_STRING __wcsrtombs
 #else
 # include "printf_buffer-wchar_t.h"
+# define VFPRINTF_BUFFER __vwprintf_buffer
 # define vfprintf	__vfwprintf_internal
 # define OTHER_CHAR_T   char
 /* This is a hack!!!  There should be a type uwchar_t.  */
@@ -595,8 +597,8 @@  static void group_number (struct Xprintf_buffer *buf,
 
 /* The buffer-based function itself.  */
 void
-Xprintf_buffer (struct Xprintf_buffer *buf, const CHAR_T *format,
-		  va_list ap, unsigned int mode_flags)
+VFPRINTF_BUFFER (struct Xprintf_buffer *buf, const CHAR_T *format,
+		 va_list ap, unsigned int mode_flags)
 {
   /* The character used as thousands separator.  */
   THOUSANDS_SEP_T thousands_sep = 0;
@@ -1541,7 +1543,7 @@  vfprintf (FILE *s, const CHAR_T *format, va_list ap, unsigned int mode_flags)
     {
       struct Xprintf (buffer_to_file) wrap;
       Xprintf (buffer_to_file_init) (&wrap, s);
-      Xprintf_buffer (&wrap.base, format, ap, mode_flags);
+      VFPRINTF_BUFFER (&wrap.base, format, ap, mode_flags);
       return Xprintf (buffer_to_file_done) (&wrap);
     }
 
@@ -1556,7 +1558,7 @@  vfprintf (FILE *s, const CHAR_T *format, va_list ap, unsigned int mode_flags)
   Xprintf (buffer_to_file_init) (&wrap, s);
 
   /* Perform the printing operation on the buffer.  */
-  Xprintf_buffer (&wrap.base, format, ap, mode_flags);
+  VFPRINTF_BUFFER (&wrap.base, format, ap, mode_flags);
   done = Xprintf (buffer_to_file_done) (&wrap);
 
   /* Unlock the stream.  */