diff options
author | Ron Yorston <rmy@pobox.com> | 2019-05-27 11:56:52 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-05-27 11:56:52 +0100 |
commit | a61949401890cbb33a9d6c4571b51c53460ad438 (patch) | |
tree | 64dedaddb89896d5b1670a421af123670ca2120b /libbb/read_printf.c | |
parent | 03a7b173605a890e1db5177ecd5b8dd591081c41 (diff) | |
parent | bcb1fc3e6ca6fe902610f507eaf9b0b58a5c583a (diff) | |
download | busybox-w32-a61949401890cbb33a9d6c4571b51c53460ad438.tar.gz busybox-w32-a61949401890cbb33a9d6c4571b51c53460ad438.tar.bz2 busybox-w32-a61949401890cbb33a9d6c4571b51c53460ad438.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/read_printf.c')
-rw-r--r-- | libbb/read_printf.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libbb/read_printf.c b/libbb/read_printf.c index e47ac7afe..1e67d6542 100644 --- a/libbb/read_printf.c +++ b/libbb/read_printf.c | |||
@@ -107,10 +107,9 @@ char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p) | |||
107 | 107 | ||
108 | // Read (potentially big) files in one go. File size is estimated | 108 | // Read (potentially big) files in one go. File size is estimated |
109 | // by stat. Extra '\0' byte is appended. | 109 | // by stat. Extra '\0' byte is appended. |
110 | void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) | 110 | void* FAST_FUNC xmalloc_read_with_initial_buf(int fd, size_t *maxsz_p, char *buf, size_t total) |
111 | { | 111 | { |
112 | char *buf; | 112 | size_t size, rd_size; |
113 | size_t size, rd_size, total; | ||
114 | size_t to_read; | 113 | size_t to_read; |
115 | struct stat st; | 114 | struct stat st; |
116 | 115 | ||
@@ -123,8 +122,6 @@ void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) | |||
123 | /* In order to make such files readable, we add small const */ | 122 | /* In order to make such files readable, we add small const */ |
124 | size = (st.st_size | 0x3ff) + 1; | 123 | size = (st.st_size | 0x3ff) + 1; |
125 | 124 | ||
126 | total = 0; | ||
127 | buf = NULL; | ||
128 | while (1) { | 125 | while (1) { |
129 | if (to_read < size) | 126 | if (to_read < size) |
130 | size = to_read; | 127 | size = to_read; |
@@ -153,6 +150,11 @@ void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) | |||
153 | return buf; | 150 | return buf; |
154 | } | 151 | } |
155 | 152 | ||
153 | void* FAST_FUNC xmalloc_read(int fd, size_t *maxsz_p) | ||
154 | { | ||
155 | return xmalloc_read_with_initial_buf(fd, maxsz_p, NULL, 0); | ||
156 | } | ||
157 | |||
156 | #ifdef USING_LSEEK_TO_GET_SIZE | 158 | #ifdef USING_LSEEK_TO_GET_SIZE |
157 | /* Alternatively, file size can be obtained by lseek to the end. | 159 | /* Alternatively, file size can be obtained by lseek to the end. |
158 | * The code is slightly bigger. Retained in case fstat approach | 160 | * The code is slightly bigger. Retained in case fstat approach |