From 91df00a92543a45a4916cbaeecbbf70bfa946b78 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 20 Feb 2023 13:46:12 +0100 Subject: Remove ostream_printf By cobbling together the xattr lines manually in libtar, the need (and thus the function itself) are removed. Signed-off-by: David Oberhollenzer --- include/compat.h | 8 +++++++- include/io/ostream.h | 20 -------------------- lib/io/Makemodule.am | 2 +- lib/io/src/printf.c | 30 ------------------------------ lib/tar/src/write_header.c | 14 +++++++++++--- 5 files changed, 19 insertions(+), 55 deletions(-) delete mode 100644 lib/io/src/printf.c diff --git a/include/compat.h b/include/compat.h index 8969d6c..7d0a646 100644 --- a/include/compat.h +++ b/include/compat.h @@ -8,12 +8,18 @@ #define COMPAT_H #include "sqfs/predef.h" -#include "io/ostream.h" #include "config.h" #include #include +#if defined(__GNUC__) || defined(__clang__) +# define PRINTF_ATTRIB(fmt, elipsis) \ + __attribute__ ((format (printf, fmt, elipsis))) +#else +# define PRINTF_ATTRIB(fmt, elipsis) +#endif + #if defined(__GNUC__) && __GNUC__ >= 5 # define SZ_ADD_OV __builtin_add_overflow # define SZ_MUL_OV __builtin_mul_overflow diff --git a/include/io/ostream.h b/include/io/ostream.h index 21850d4..c1602ab 100644 --- a/include/io/ostream.h +++ b/include/io/ostream.h @@ -10,13 +10,6 @@ #include "sqfs/predef.h" #include "io/istream.h" -#if defined(__GNUC__) || defined(__clang__) -# define PRINTF_ATTRIB(fmt, elipsis) \ - __attribute__ ((format (printf, fmt, elipsis))) -#else -# define PRINTF_ATTRIB(fmt, elipsis) -#endif - /** * @struct ostream_t * @@ -111,19 +104,6 @@ SQFS_INLINE const char *ostream_get_filename(ostream_t *strm) return strm->get_filename(strm); } -/** - * @brief Printf like function that appends to an output stream - * - * @memberof ostream_t - * - * @param strm The output stream to append to. - * @param fmt A printf style format string. - * - * @return The number of characters written on success, -1 on failure. - */ -SQFS_INTERNAL int ostream_printf(ostream_t *strm, const char *fmt, ...) - PRINTF_ATTRIB(2, 3); - /** * @brief Read data from an input stream and append it to an output stream * diff --git a/lib/io/Makemodule.am b/lib/io/Makemodule.am index b795788..71f01e8 100644 --- a/lib/io/Makemodule.am +++ b/lib/io/Makemodule.am @@ -1,6 +1,6 @@ libio_a_SOURCES = include/io/istream.h include/io/ostream.h include/io/xfrm.h \ include/io/file.h include/io/std.h \ - lib/io/src/internal.h lib/io/src/ostream.c lib/io/src/printf.c \ + lib/io/src/internal.h lib/io/src/ostream.c \ lib/io/src/istream.c lib/io/src/get_line.c lib/io/src/xfrm/ostream.c \ lib/io/src/xfrm/istream.c libio_a_CFLAGS = $(AM_CFLAGS) $(ZLIB_CFLAGS) $(XZ_CFLAGS) diff --git a/lib/io/src/printf.c b/lib/io/src/printf.c deleted file mode 100644 index 3850487..0000000 --- a/lib/io/src/printf.c +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * printf.c - * - * Copyright (C) 2019 David Oberhollenzer - */ -#include "internal.h" - -int ostream_printf(ostream_t *strm, const char *fmt, ...) -{ - char *temp = NULL; - va_list ap; - int ret; - - va_start(ap, fmt); - - ret = vasprintf(&temp, fmt, ap); - if (ret < 0) - perror(strm->get_filename(strm)); - va_end(ap); - - if (ret < 0) - return -1; - - if (strm->append(strm, temp, ret)) - ret = -1; - - free(temp); - return ret; -} diff --git a/lib/tar/src/write_header.c b/lib/tar/src/write_header.c index 5d98686..ed780b5 100644 --- a/lib/tar/src/write_header.c +++ b/lib/tar/src/write_header.c @@ -164,13 +164,21 @@ static int write_schily_xattr(ostream_t *fp, const struct stat *orig, return -1; for (it = xattr; it != NULL; it = it->next) { + char buffer[64]; + len = strlen(prefix) + strlen(it->key) + it->value_len + 3; len += prefix_digit_len(len); - if (ostream_printf(fp, PRI_SZ " %s%s=", - len, prefix, it->key) < 0) { + sprintf(buffer, PRI_SZ " ", len); + + if (ostream_append(fp, buffer, strlen(buffer))) + return -1; + if (ostream_append(fp, prefix, strlen(prefix))) + return -1; + if (ostream_append(fp, it->key, strlen(it->key))) + return -1; + if (ostream_append(fp, "=", 1)) return -1; - } if (ostream_append(fp, it->value, it->value_len)) return -1; if (ostream_append(fp, "\n", 1)) -- cgit v1.2.3