]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
bsdtar: remove tar_i64toa() 3294/head
authordatauwu <datauwu@users.noreply.github.com>
Thu, 16 Jul 2026 14:04:27 +0000 (22:04 +0800)
committerdatauwu <datauwu@users.noreply.github.com>
Fri, 17 Jul 2026 18:09:50 +0000 (02:09 +0800)
Format integer values directly at each call site and remove the custom
integer formatter.

This handles the full signed integer range and preserves unsigned byte
counters.

tar/bsdtar.h
tar/read.c
tar/util.c
tar/write.c

index 692b800bf811b29361b925212c92419da03799bd..29c67fc08295b38b3d037ddb6392eb9b4899173f 100644 (file)
@@ -196,7 +196,6 @@ int need_report(void);
 int    pathcmp(const char *a, const char *b);
 void   safe_fprintf(FILE * ARCHIVE_RESTRICT, const char * ARCHIVE_RESTRICT fmt, ...) __LA_PRINTF(2, 3);
 void   set_chdir(struct bsdtar *, const char *newdir);
-const char *tar_i64toa(int64_t);
 void   tar_mode_c(struct bsdtar *bsdtar);
 void   tar_mode_r(struct bsdtar *bsdtar);
 void   tar_mode_t(struct bsdtar *bsdtar);
index 57ae5200cf0d69d13da73093afb543918aa669d7..a50c7747d87a0cc94a8e8e22e7c8b18b570a2596 100644 (file)
@@ -121,16 +121,16 @@ progress_func(void *cookie)
                else
                        compression = (int)((uncomp - comp) * 100 / uncomp);
                fprintf(stderr,
-                   "In: %s bytes, compression %d%%;",
-                   tar_i64toa(comp), compression);
-               fprintf(stderr, "  Out: %d files, %s bytes\n",
-                   archive_file_count(a), tar_i64toa(uncomp));
+                   "In: %ju bytes, compression %d%%;",
+                   (uintmax_t)comp, compression);
+               fprintf(stderr, "  Out: %d files, %ju bytes\n",
+                   archive_file_count(a), (uintmax_t)uncomp);
        }
        if (entry != NULL) {
                safe_fprintf(stderr, "Current: %s",
                    archive_entry_pathname(entry));
-               fprintf(stderr, " (%s bytes)\n",
-                   tar_i64toa(archive_entry_size(entry)));
+               fprintf(stderr, " (%jd bytes)\n",
+                   (intmax_t)archive_entry_size(entry));
        }
 }
 
index 3fb0f9b02055bd396081219ca739bd0c589ccea7..730a9adb2ea26f72899d03d078989de24ef4c91a 100644 (file)
@@ -584,27 +584,6 @@ edit_mtime(struct bsdtar *bsdtar, struct archive_entry *entry)
                archive_entry_set_mtime(entry, bsdtar->mtime, 0);
 }
 
-/*
- * It would be nice to just use printf() for formatting large numbers,
- * but the compatibility problems are quite a headache.  Hence the
- * following simple utility function.
- */
-const char *
-tar_i64toa(int64_t n0)
-{
-       static char buff[24];
-       uint64_t n = n0 < 0 ? -n0 : n0;
-       char *p = buff + sizeof(buff);
-
-       *--p = '\0';
-       do {
-               *--p = '0' + (int)(n % 10);
-       } while (n /= 10);
-       if (n0 < 0)
-               *--p = '-';
-       return p;
-}
-
 /*
  * Like strcmp(), but try to be a little more aware of the fact that
  * we're comparing two paths.  Right now, it just handles leading
@@ -748,7 +727,9 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
                    (unsigned long)archive_entry_rdevminor(entry));
                p = tmp;
        } else {
-               p = tar_i64toa(archive_entry_size(entry));
+               snprintf(tmp, sizeof(tmp), "%jd",
+                   (intmax_t)archive_entry_size(entry));
+               p = tmp;
        }
        if (w + strlen(p) >= bsdtar->gs_width)
                bsdtar->gs_width = w + strlen(p) + 1;
index 593c2ef2d082155bcaed1e56733331b0a0026d6e..13ff4eac766e1a8efa6ba41b2a4e2fd5b1a0ad8f 100644 (file)
@@ -598,8 +598,8 @@ cleanup:
        bsdtar->diskreader = NULL;
 
        if (bsdtar->flags & OPTFLAG_TOTALS) {
-               fprintf(stderr, "Total bytes written: %s\n",
-                   tar_i64toa(archive_filter_bytes(a, -1)));
+               fprintf(stderr, "Total bytes written: %jd\n",
+                   (intmax_t)archive_filter_bytes(a, -1));
        }
 
        archive_write_free(a);
@@ -1043,21 +1043,20 @@ report_write(struct bsdtar *bsdtar, struct archive *a,
                fprintf(stderr, "\n");
        comp = archive_filter_bytes(a, -1);
        uncomp = archive_filter_bytes(a, 0);
-       fprintf(stderr, "In: %d files, %s bytes;",
-           archive_file_count(a), tar_i64toa(uncomp));
+       fprintf(stderr, "In: %d files, %ju bytes;",
+           archive_file_count(a), (uintmax_t)uncomp);
        if (comp >= uncomp)
                compression = 0;
        else
                compression = (int)((uncomp - comp) * 100 / uncomp);
        fprintf(stderr,
-           " Out: %s bytes, compression %d%%\n",
-           tar_i64toa(comp), compression);
-       /* Can't have two calls to tar_i64toa() pending, so split the output. */
-       safe_fprintf(stderr, "Current: %s (%s",
+           " Out: %ju bytes, compression %d%%\n",
+           (uintmax_t)comp, compression);
+       safe_fprintf(stderr, "Current: %s (%jd",
            archive_entry_pathname(entry),
-           tar_i64toa(progress));
-       fprintf(stderr, "/%s bytes)\n",
-           tar_i64toa(archive_entry_size(entry)));
+           (intmax_t)progress);
+       fprintf(stderr, "/%jd bytes)\n",
+           (intmax_t)archive_entry_size(entry));
 }
 
 static void