From dff2bd733fc2dac08d34f2cfad0e68aeb8e7a7a2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 24 May 2019 17:03:28 +0200 Subject: libarchive: treat one "FIXME: avoid seek" function old new delta xmalloc_read_with_initial_buf - 205 +205 setup_transformer_on_fd 154 150 -4 xmalloc_open_zipped_read_close 143 135 -8 xmalloc_read 201 10 -191 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 205/-203) Total: 2 bytes Signed-off-by: Denys Vlasenko --- libbb/read_printf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libbb/read_printf.c') diff --git a/libbb/read_printf.c b/libbb/read_printf.c index b6a17cc36..cb582c080 100644 --- a/libbb/read_printf.c +++ b/libbb/read_printf.c @@ -102,10 +102,9 @@ char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p) // Read (potentially big) files in one go. File size is estimated // by stat. Extra '\0' byte is appended. -void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) +void* FAST_FUNC xmalloc_read_with_initial_buf(int fd, size_t *maxsz_p, char *buf, size_t total) { - char *buf; - size_t size, rd_size, total; + size_t size, rd_size; size_t to_read; struct stat st; @@ -118,8 +117,6 @@ void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) /* In order to make such files readable, we add small const */ size = (st.st_size | 0x3ff) + 1; - total = 0; - buf = NULL; while (1) { if (to_read < size) size = to_read; @@ -148,6 +145,11 @@ void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) return buf; } +void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) +{ + return xmalloc_read_with_initial_buf(fd, maxsz_p, NULL, 0); +} + #ifdef USING_LSEEK_TO_GET_SIZE /* Alternatively, file size can be obtained by lseek to the end. * The code is slightly bigger. Retained in case fstat approach -- cgit v1.2.3