aboutsummaryrefslogtreecommitdiff
path: root/archival/libunarchive
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-07-16 08:14:35 +0000
committerRob Landley <rob@landley.net>2006-07-16 08:14:35 +0000
commit534374755d618c9c36c9940c82756241c4b25a67 (patch)
treefac906b4fa40a68c53cecf20215a7a25b3b1cab6 /archival/libunarchive
parentafb94ecf2bb6c53ce2a381d6ce45a426243c76d9 (diff)
downloadbusybox-w32-534374755d618c9c36c9940c82756241c4b25a67.tar.gz
busybox-w32-534374755d618c9c36c9940c82756241c4b25a67.tar.bz2
busybox-w32-534374755d618c9c36c9940c82756241c4b25a67.zip
Cleaup read() and write() variants, plus a couple of new functions like
xlseek and fdlength() for the new mkswap.
Diffstat (limited to 'archival/libunarchive')
-rw-r--r--archival/libunarchive/Makefile.in1
-rw-r--r--archival/libunarchive/archive_xread_all.c21
-rw-r--r--archival/libunarchive/archive_xread_all_eof.c2
-rw-r--r--archival/libunarchive/check_header_gzip.c14
-rw-r--r--archival/libunarchive/data_extract_to_buffer.c2
-rw-r--r--archival/libunarchive/decompress_uncompress.c2
-rw-r--r--archival/libunarchive/decompress_unzip.c7
-rw-r--r--archival/libunarchive/get_header_ar.c4
-rw-r--r--archival/libunarchive/get_header_cpio.c5
-rw-r--r--archival/libunarchive/get_header_tar.c12
-rw-r--r--archival/libunarchive/get_header_tar_gz.c2
-rw-r--r--archival/libunarchive/unpack_ar_archive.c2
12 files changed, 24 insertions, 50 deletions
diff --git a/archival/libunarchive/Makefile.in b/archival/libunarchive/Makefile.in
index 928e5bf8b..46c50f81d 100644
--- a/archival/libunarchive/Makefile.in
+++ b/archival/libunarchive/Makefile.in
@@ -29,7 +29,6 @@ LIBUNARCHIVE-y:= \
29 header_list.o \ 29 header_list.o \
30 header_verbose_list.o \ 30 header_verbose_list.o \
31\ 31\
32 archive_xread_all.o \
33 archive_xread_all_eof.o \ 32 archive_xread_all_eof.o \
34\ 33\
35 seek_by_char.o \ 34 seek_by_char.o \
diff --git a/archival/libunarchive/archive_xread_all.c b/archival/libunarchive/archive_xread_all.c
deleted file mode 100644
index bed8641a2..000000000
--- a/archival/libunarchive/archive_xread_all.c
+++ /dev/null
@@ -1,21 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include "unarchive.h"
10#include "libbb.h"
11
12void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count)
13{
14 ssize_t size;
15
16 size = bb_full_read(archive_handle->src_fd, buf, count);
17 if (size != count) {
18 bb_error_msg_and_die("Short read");
19 }
20 return;
21}
diff --git a/archival/libunarchive/archive_xread_all_eof.c b/archival/libunarchive/archive_xread_all_eof.c
index df9c88a56..e03fb0caa 100644
--- a/archival/libunarchive/archive_xread_all_eof.c
+++ b/archival/libunarchive/archive_xread_all_eof.c
@@ -13,7 +13,7 @@ ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *b
13{ 13{
14 ssize_t size; 14 ssize_t size;
15 15
16 size = bb_full_read(archive_handle->src_fd, buf, count); 16 size = full_read(archive_handle->src_fd, buf, count);
17 if ((size != 0) && (size != count)) { 17 if ((size != 0) && (size != count)) {
18 bb_perror_msg_and_die("Short read, read %ld of %ld", (long)size, (long)count); 18 bb_perror_msg_and_die("Short read, read %ld of %ld", (long)size, (long)count);
19 } 19 }
diff --git a/archival/libunarchive/check_header_gzip.c b/archival/libunarchive/check_header_gzip.c
index 79477c610..77e1e6a46 100644
--- a/archival/libunarchive/check_header_gzip.c
+++ b/archival/libunarchive/check_header_gzip.c
@@ -20,7 +20,7 @@ void check_header_gzip(int src_fd)
20 } formated; 20 } formated;
21 } header; 21 } header;
22 22
23 bb_xread_all(src_fd, header.raw, 8); 23 xread(src_fd, header.raw, 8);
24 24
25 /* Check the compression method */ 25 /* Check the compression method */
26 if (header.formated.method != 8) { 26 if (header.formated.method != 8) {
@@ -32,10 +32,10 @@ void check_header_gzip(int src_fd)
32 /* bit 2 set: extra field present */ 32 /* bit 2 set: extra field present */
33 unsigned char extra_short; 33 unsigned char extra_short;
34 34
35 extra_short = bb_xread_char(src_fd) + (bb_xread_char(src_fd) << 8); 35 extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
36 while (extra_short > 0) { 36 while (extra_short > 0) {
37 /* Ignore extra field */ 37 /* Ignore extra field */
38 bb_xread_char(src_fd); 38 xread_char(src_fd);
39 extra_short--; 39 extra_short--;
40 } 40 }
41 } 41 }
@@ -43,19 +43,19 @@ void check_header_gzip(int src_fd)
43 /* Discard original name if any */ 43 /* Discard original name if any */
44 if (header.formated.flags & 0x08) { 44 if (header.formated.flags & 0x08) {
45 /* bit 3 set: original file name present */ 45 /* bit 3 set: original file name present */
46 while(bb_xread_char(src_fd) != 0); 46 while(xread_char(src_fd) != 0);
47 } 47 }
48 48
49 /* Discard file comment if any */ 49 /* Discard file comment if any */
50 if (header.formated.flags & 0x10) { 50 if (header.formated.flags & 0x10) {
51 /* bit 4 set: file comment present */ 51 /* bit 4 set: file comment present */
52 while(bb_xread_char(src_fd) != 0); 52 while(xread_char(src_fd) != 0);
53 } 53 }
54 54
55 /* Read the header checksum */ 55 /* Read the header checksum */
56 if (header.formated.flags & 0x02) { 56 if (header.formated.flags & 0x02) {
57 bb_xread_char(src_fd); 57 xread_char(src_fd);
58 bb_xread_char(src_fd); 58 xread_char(src_fd);
59 } 59 }
60 60
61 return; 61 return;
diff --git a/archival/libunarchive/data_extract_to_buffer.c b/archival/libunarchive/data_extract_to_buffer.c
index fe76971df..95cb8f576 100644
--- a/archival/libunarchive/data_extract_to_buffer.c
+++ b/archival/libunarchive/data_extract_to_buffer.c
@@ -14,5 +14,5 @@ void data_extract_to_buffer(archive_handle_t *archive_handle)
14 14
15 archive_handle->buffer = xzalloc(size + 1); 15 archive_handle->buffer = xzalloc(size + 1);
16 16
17 archive_xread_all(archive_handle, archive_handle->buffer, size); 17 xread(archive_handle->src_fd, archive_handle->buffer, size);
18} 18}
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c
index 81764a47f..0c4ab6dda 100644
--- a/archival/libunarchive/decompress_uncompress.c
+++ b/archival/libunarchive/decompress_uncompress.c
@@ -116,7 +116,7 @@ int uncompress(int fd_in, int fd_out)
116 116
117 insize = 0; 117 insize = 0;
118 118
119 inbuf[0] = bb_xread_char(fd_in); 119 inbuf[0] = xread_char(fd_in);
120 120
121 maxbits = inbuf[0] & BIT_MASK; 121 maxbits = inbuf[0] & BIT_MASK;
122 block_mode = inbuf[0] & BLOCK_MODE; 122 block_mode = inbuf[0] & BLOCK_MODE;
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 46a26933b..8f33e6e6c 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -116,9 +116,8 @@ static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current
116 /* Leave the first 4 bytes empty so we can always unwind the bitbuffer 116 /* Leave the first 4 bytes empty so we can always unwind the bitbuffer
117 * to the front of the bytebuffer, leave 4 bytes free at end of tail 117 * to the front of the bytebuffer, leave 4 bytes free at end of tail
118 * so we can easily top up buffer in check_trailer_gzip() */ 118 * so we can easily top up buffer in check_trailer_gzip() */
119 if (!(bytebuffer_size = bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8))) { 119 if (1 > (bytebuffer_size = safe_read(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8)))
120 bb_error_msg_and_die("unexpected end of file"); 120 bb_error_msg_and_die("unexpected end of file");
121 }
122 bytebuffer_size += 4; 121 bytebuffer_size += 4;
123 bytebuffer_offset = 4; 122 bytebuffer_offset = 4;
124 } 123 }
@@ -862,7 +861,7 @@ int inflate_unzip(int in, int out)
862 861
863 while(1) { 862 while(1) {
864 int ret = inflate_get_next_window(); 863 int ret = inflate_get_next_window();
865 nwrote = bb_full_write(out, gunzip_window, gunzip_outbuf_count); 864 nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
866 if (nwrote == -1) { 865 if (nwrote == -1) {
867 bb_perror_msg("write"); 866 bb_perror_msg("write");
868 return -1; 867 return -1;
@@ -896,7 +895,7 @@ int inflate_gunzip(int in, int out)
896 /* top up the input buffer with the rest of the trailer */ 895 /* top up the input buffer with the rest of the trailer */
897 count = bytebuffer_size - bytebuffer_offset; 896 count = bytebuffer_size - bytebuffer_offset;
898 if (count < 8) { 897 if (count < 8) {
899 bb_xread_all(in, &bytebuffer[bytebuffer_size], 8 - count); 898 xread(in, &bytebuffer[bytebuffer_size], 8 - count);
900 bytebuffer_size += 8 - count; 899 bytebuffer_size += 8 - count;
901 } 900 }
902 for (count = 0; count != 4; count++) { 901 for (count = 0; count != 4; count++) {
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 44d964287..48d7a5ad8 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -43,7 +43,7 @@ char get_header_ar(archive_handle_t *archive_handle)
43 if (ar.raw[0] == '\n') { 43 if (ar.raw[0] == '\n') {
44 /* fix up the header, we started reading 1 byte too early */ 44 /* fix up the header, we started reading 1 byte too early */
45 memmove(ar.raw, &ar.raw[1], 59); 45 memmove(ar.raw, &ar.raw[1], 59);
46 ar.raw[59] = bb_xread_char(archive_handle->src_fd); 46 ar.raw[59] = xread_char(archive_handle->src_fd);
47 archive_handle->offset++; 47 archive_handle->offset++;
48 } 48 }
49 archive_handle->offset += 60; 49 archive_handle->offset += 60;
@@ -68,7 +68,7 @@ char get_header_ar(archive_handle_t *archive_handle)
68 * in static variable long_names for use in future entries */ 68 * in static variable long_names for use in future entries */
69 ar_long_name_size = typed->size; 69 ar_long_name_size = typed->size;
70 ar_long_names = xmalloc(ar_long_name_size); 70 ar_long_names = xmalloc(ar_long_name_size);
71 bb_xread_all(archive_handle->src_fd, ar_long_names, ar_long_name_size); 71 xread(archive_handle->src_fd, ar_long_names, ar_long_name_size);
72 archive_handle->offset += ar_long_name_size; 72 archive_handle->offset += ar_long_name_size;
73 /* This ar entries data section only contained filenames for other records 73 /* This ar entries data section only contained filenames for other records
74 * they are stored in the static ar_long_names for future reference */ 74 * they are stored in the static ar_long_names for future reference */
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 725c4911a..28c743589 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -76,7 +76,8 @@ char get_header_cpio(archive_handle_t *archive_handle)
76 } 76 }
77 77
78 file_header->name = (char *) xzalloc(namesize + 1); 78 file_header->name = (char *) xzalloc(namesize + 1);
79 archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */ 79 /* Read in filename */
80 xread(archive_handle->src_fd, file_header->name, namesize);
80 archive_handle->offset += namesize; 81 archive_handle->offset += namesize;
81 82
82 /* Update offset amount and skip padding before file contents */ 83 /* Update offset amount and skip padding before file contents */
@@ -103,7 +104,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
103 104
104 if (S_ISLNK(file_header->mode)) { 105 if (S_ISLNK(file_header->mode)) {
105 file_header->link_name = (char *) xzalloc(file_header->size + 1); 106 file_header->link_name = (char *) xzalloc(file_header->size + 1);
106 archive_xread_all(archive_handle, file_header->link_name, file_header->size); 107 xread(archive_handle->src_fd, file_header->link_name, file_header->size);
107 archive_handle->offset += file_header->size; 108 archive_handle->offset += file_header->size;
108 file_header->size = 0; /* Stop possible seeks in future */ 109 file_header->size = 0; /* Stop possible seeks in future */
109 } else { 110 } else {
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 1cbde9543..4394d23ee 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -56,11 +56,7 @@ char get_header_tar(archive_handle_t *archive_handle)
56 /* Align header */ 56 /* Align header */
57 data_align(archive_handle, 512); 57 data_align(archive_handle, 512);
58 58
59 if (bb_full_read(archive_handle->src_fd, tar.raw, 512) != 512) { 59 xread(archive_handle->src_fd, tar.raw, 512);
60 /* Assume end of file */
61 bb_error_msg_and_die("Short header");
62 //return(EXIT_FAILURE);
63 }
64 archive_handle->offset += 512; 60 archive_handle->offset += 512;
65 61
66 /* If there is no filename its an empty header */ 62 /* If there is no filename its an empty header */
@@ -69,7 +65,7 @@ char get_header_tar(archive_handle_t *archive_handle)
69 /* This is the second consecutive empty header! End of archive! 65 /* This is the second consecutive empty header! End of archive!
70 * Read until the end to empty the pipe from gz or bz2 66 * Read until the end to empty the pipe from gz or bz2
71 */ 67 */
72 while (bb_full_read(archive_handle->src_fd, tar.raw, 512) == 512); 68 while (full_read(archive_handle->src_fd, tar.raw, 512) == 512);
73 return(EXIT_FAILURE); 69 return(EXIT_FAILURE);
74 } 70 }
75 end = 1; 71 end = 1;
@@ -166,14 +162,14 @@ char get_header_tar(archive_handle_t *archive_handle)
166#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS 162#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
167 case 'L': { 163 case 'L': {
168 longname = xzalloc(file_header->size + 1); 164 longname = xzalloc(file_header->size + 1);
169 archive_xread_all(archive_handle, longname, file_header->size); 165 xread(archive_handle->src_fd, longname, file_header->size);
170 archive_handle->offset += file_header->size; 166 archive_handle->offset += file_header->size;
171 167
172 return(get_header_tar(archive_handle)); 168 return(get_header_tar(archive_handle));
173 } 169 }
174 case 'K': { 170 case 'K': {
175 linkname = xzalloc(file_header->size + 1); 171 linkname = xzalloc(file_header->size + 1);
176 archive_xread_all(archive_handle, linkname, file_header->size); 172 xread(archive_handle->src_fd, linkname, file_header->size);
177 archive_handle->offset += file_header->size; 173 archive_handle->offset += file_header->size;
178 174
179 file_header->name = linkname; 175 file_header->name = linkname;
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c
index 3e1f466a7..ad26f465a 100644
--- a/archival/libunarchive/get_header_tar_gz.c
+++ b/archival/libunarchive/get_header_tar_gz.c
@@ -15,7 +15,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
15 /* Cant lseek over pipe's */ 15 /* Cant lseek over pipe's */
16 archive_handle->seek = seek_by_char; 16 archive_handle->seek = seek_by_char;
17 17
18 archive_xread_all(archive_handle, &magic, 2); 18 xread(archive_handle->src_fd, &magic, 2);
19 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { 19 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
20 bb_error_msg_and_die("Invalid gzip magic"); 20 bb_error_msg_and_die("Invalid gzip magic");
21 } 21 }
diff --git a/archival/libunarchive/unpack_ar_archive.c b/archival/libunarchive/unpack_ar_archive.c
index 47cf812ef..eed528391 100644
--- a/archival/libunarchive/unpack_ar_archive.c
+++ b/archival/libunarchive/unpack_ar_archive.c
@@ -12,7 +12,7 @@ void unpack_ar_archive(archive_handle_t *ar_archive)
12{ 12{
13 char magic[7]; 13 char magic[7];
14 14
15 archive_xread_all(ar_archive, magic, 7); 15 xread(ar_archive->src_fd, magic, 7);
16 if (strncmp(magic, "!<arch>", 7) != 0) { 16 if (strncmp(magic, "!<arch>", 7) != 0) {
17 bb_error_msg_and_die("Invalid ar magic"); 17 bb_error_msg_and_die("Invalid ar magic");
18 } 18 }