From 5e48211929b6842ece062bee871675c9be36102f Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 17 Dec 2023 04:00:06 -0600 Subject: [PATCH] Switch peek() family from int64_t to long long so base types are consistent on 32/64 bit, and switch some 64 bit constants to ULL for 32 bit. --- lib/lib.c | 15 ++++++++------- lib/lib.h | 6 +++--- toys/posix/file.c | 2 +- toys/posix/tar.c | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/lib.c b/lib/lib.c index 5bc8b7e8..a27c7bbf 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -106,7 +106,8 @@ void perror_exit_raw(char *msg) perror_exit("%s", msg); } -// Keep reading until full or EOF +// Keep reading until full or EOF. Note: assumes sigaction(SA_RESTART), +// otherwise SIGSTOP/SIGCONT can return 0 from read/write without EOF. ssize_t readall(int fd, void *buf, size_t len) { size_t count = 0; @@ -665,19 +666,19 @@ int highest_bit(unsigned long l) } // Inefficient, but deals with unaligned access -int64_t peek_le(void *ptr, unsigned size) +long long peek_le(void *ptr, unsigned size) { - int64_t ret = 0; + long long ret = 0; char *c = ptr; int i; - for (i=0; i4 && strstart(&s, "BZh") && isdigit(*s)) xprintf("bzip2 compressed data, block size = %c00k\n", *s); - else if (len>31 && peek_be(s, 7) == 0xfd377a585a0000UL) + else if (len>31 && peek_be(s, 7) == 0xfd377a585a0000ULL) xputs("xz compressed data"); else if (len>10 && strstart(&s, "\x1f\x8b")) xputs("gzip compressed data"); else if (len>32 && !smemcmp(s+1, "\xfa\xed\xfe", 3)) { diff --git a/toys/posix/tar.c b/toys/posix/tar.c index e760a43a..00cbe968 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -1063,7 +1063,7 @@ void tar_main(void) // detect gzip and bzip signatures if (SWAP_BE16(*(short *)hdr)==0x1f8b) toys.optflags |= FLAG_z; else if (!smemcmp(hdr, "BZh", 3)) toys.optflags |= FLAG_j; - else if (peek_be(hdr, 7) == 0xfd377a585a0000UL) toys.optflags |= FLAG_J; + else if (peek_be(hdr, 7) == 0xfd377a585a0000ULL) toys.optflags |= FLAG_J; else error_exit("Not tar"); // if we can seek back we don't need to loop and copy data -- 2.39.2