summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorRob Landley2006-07-16 08:14:35 +0000
committerRob Landley2006-07-16 08:14:35 +0000
commit534374755d618c9c36c9940c82756241c4b25a67 (patch)
treefac906b4fa40a68c53cecf20215a7a25b3b1cab6 /archival
parentafb94ecf2bb6c53ce2a381d6ce45a426243c76d9 (diff)
downloadbusybox-534374755d618c9c36c9940c82756241c4b25a67.zip
busybox-534374755d618c9c36c9940c82756241c4b25a67.tar.gz
Cleaup read() and write() variants, plus a couple of new functions like
xlseek and fdlength() for the new mkswap.
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c2
-rw-r--r--archival/gunzip.c4
-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
-rw-r--r--archival/rpm.c2
-rw-r--r--archival/rpm2cpio.c6
-rw-r--r--archival/tar.c12
-rw-r--r--archival/uncompress.c2
-rw-r--r--archival/unzip.c61
19 files changed, 55 insertions, 108 deletions
diff --git a/archival/ar.c b/archival/ar.c
index 3bb7587..fd2ab99 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -88,7 +88,7 @@ int ar_main(int argc, char **argv)
llist_add_to(&(archive_handle->accept), argv[optind++]);
}
- archive_xread_all(archive_handle, magic, 7);
+ xread(archive_handle->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
bb_error_msg_and_die("Invalid ar magic");
}
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 069666f..bd6047e 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -112,10 +112,10 @@ int gunzip_main(int argc, char **argv)
}
/* do the decompression, and cleanup */
- if (bb_xread_char(src_fd) == 0x1f) {
+ if (xread_char(src_fd) == 0x1f) {
unsigned char magic2;
- magic2 = bb_xread_char(src_fd);
+ magic2 = xread_char(src_fd);
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
if (magic2 == 0x9d) {
status = uncompress(src_fd, dst_fd);
diff --git a/archival/libunarchive/Makefile.in b/archival/libunarchive/Makefile.in
index 928e5bf..46c50f8 100644
--- a/archival/libunarchive/Makefile.in
+++ b/archival/libunarchive/Makefile.in
@@ -29,7 +29,6 @@ LIBUNARCHIVE-y:= \
header_list.o \
header_verbose_list.o \
\
- archive_xread_all.o \
archive_xread_all_eof.o \
\
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 bed8641..0000000
--- a/archival/libunarchive/archive_xread_all.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "unarchive.h"
-#include "libbb.h"
-
-void archive_xread_all(const archive_handle_t *archive_handle, void *buf, const size_t count)
-{
- ssize_t size;
-
- size = bb_full_read(archive_handle->src_fd, buf, count);
- if (size != count) {
- bb_error_msg_and_die("Short read");
- }
- return;
-}
diff --git a/archival/libunarchive/archive_xread_all_eof.c b/archival/libunarchive/archive_xread_all_eof.c
index df9c88a..e03fb0c 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
{
ssize_t size;
- size = bb_full_read(archive_handle->src_fd, buf, count);
+ size = full_read(archive_handle->src_fd, buf, count);
if ((size != 0) && (size != count)) {
bb_perror_msg_and_die("Short read, read %ld of %ld", (long)size, (long)count);
}
diff --git a/archival/libunarchive/check_header_gzip.c b/archival/libunarchive/check_header_gzip.c
index 79477c6..77e1e6a 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)
} formated;
} header;
- bb_xread_all(src_fd, header.raw, 8);
+ xread(src_fd, header.raw, 8);
/* Check the compression method */
if (header.formated.method != 8) {
@@ -32,10 +32,10 @@ void check_header_gzip(int src_fd)
/* bit 2 set: extra field present */
unsigned char extra_short;
- extra_short = bb_xread_char(src_fd) + (bb_xread_char(src_fd) << 8);
+ extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
while (extra_short > 0) {
/* Ignore extra field */
- bb_xread_char(src_fd);
+ xread_char(src_fd);
extra_short--;
}
}
@@ -43,19 +43,19 @@ void check_header_gzip(int src_fd)
/* Discard original name if any */
if (header.formated.flags & 0x08) {
/* bit 3 set: original file name present */
- while(bb_xread_char(src_fd) != 0);
+ while(xread_char(src_fd) != 0);
}
/* Discard file comment if any */
if (header.formated.flags & 0x10) {
/* bit 4 set: file comment present */
- while(bb_xread_char(src_fd) != 0);
+ while(xread_char(src_fd) != 0);
}
/* Read the header checksum */
if (header.formated.flags & 0x02) {
- bb_xread_char(src_fd);
- bb_xread_char(src_fd);
+ xread_char(src_fd);
+ xread_char(src_fd);
}
return;
diff --git a/archival/libunarchive/data_extract_to_buffer.c b/archival/libunarchive/data_extract_to_buffer.c
index fe76971..95cb8f5 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)
archive_handle->buffer = xzalloc(size + 1);
- archive_xread_all(archive_handle, archive_handle->buffer, size);
+ xread(archive_handle->src_fd, archive_handle->buffer, size);
}
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c
index 81764a4..0c4ab6d 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)
insize = 0;
- inbuf[0] = bb_xread_char(fd_in);
+ inbuf[0] = xread_char(fd_in);
maxbits = inbuf[0] & BIT_MASK;
block_mode = inbuf[0] & BLOCK_MODE;
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 46a2693..8f33e6e 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
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
* to the front of the bytebuffer, leave 4 bytes free at end of tail
* so we can easily top up buffer in check_trailer_gzip() */
- if (!(bytebuffer_size = bb_xread(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8))) {
+ if (1 > (bytebuffer_size = safe_read(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8)))
bb_error_msg_and_die("unexpected end of file");
- }
bytebuffer_size += 4;
bytebuffer_offset = 4;
}
@@ -862,7 +861,7 @@ int inflate_unzip(int in, int out)
while(1) {
int ret = inflate_get_next_window();
- nwrote = bb_full_write(out, gunzip_window, gunzip_outbuf_count);
+ nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
if (nwrote == -1) {
bb_perror_msg("write");
return -1;
@@ -896,7 +895,7 @@ int inflate_gunzip(int in, int out)
/* top up the input buffer with the rest of the trailer */
count = bytebuffer_size - bytebuffer_offset;
if (count < 8) {
- bb_xread_all(in, &bytebuffer[bytebuffer_size], 8 - count);
+ xread(in, &bytebuffer[bytebuffer_size], 8 - count);
bytebuffer_size += 8 - count;
}
for (count = 0; count != 4; count++) {
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 44d9642..48d7a5a 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)
if (ar.raw[0] == '\n') {
/* fix up the header, we started reading 1 byte too early */
memmove(ar.raw, &ar.raw[1], 59);
- ar.raw[59] = bb_xread_char(archive_handle->src_fd);
+ ar.raw[59] = xread_char(archive_handle->src_fd);
archive_handle->offset++;
}
archive_handle->offset += 60;
@@ -68,7 +68,7 @@ char get_header_ar(archive_handle_t *archive_handle)
* in static variable long_names for use in future entries */
ar_long_name_size = typed->size;
ar_long_names = xmalloc(ar_long_name_size);
- bb_xread_all(archive_handle->src_fd, ar_long_names, ar_long_name_size);
+ xread(archive_handle->src_fd, ar_long_names, ar_long_name_size);
archive_handle->offset += ar_long_name_size;
/* This ar entries data section only contained filenames for other records
* 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 725c491..28c7435 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)
}
file_header->name = (char *) xzalloc(namesize + 1);
- archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */
+ /* Read in filename */
+ xread(archive_handle->src_fd, file_header->name, namesize);
archive_handle->offset += namesize;
/* Update offset amount and skip padding before file contents */
@@ -103,7 +104,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
if (S_ISLNK(file_header->mode)) {
file_header->link_name = (char *) xzalloc(file_header->size + 1);
- archive_xread_all(archive_handle, file_header->link_name, file_header->size);
+ xread(archive_handle->src_fd, file_header->link_name, file_header->size);
archive_handle->offset += file_header->size;
file_header->size = 0; /* Stop possible seeks in future */
} else {
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 1cbde95..4394d23 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)
/* Align header */
data_align(archive_handle, 512);
- if (bb_full_read(archive_handle->src_fd, tar.raw, 512) != 512) {
- /* Assume end of file */
- bb_error_msg_and_die("Short header");
- //return(EXIT_FAILURE);
- }
+ xread(archive_handle->src_fd, tar.raw, 512);
archive_handle->offset += 512;
/* If there is no filename its an empty header */
@@ -69,7 +65,7 @@ char get_header_tar(archive_handle_t *archive_handle)
/* This is the second consecutive empty header! End of archive!
* Read until the end to empty the pipe from gz or bz2
*/
- while (bb_full_read(archive_handle->src_fd, tar.raw, 512) == 512);
+ while (full_read(archive_handle->src_fd, tar.raw, 512) == 512);
return(EXIT_FAILURE);
}
end = 1;
@@ -166,14 +162,14 @@ char get_header_tar(archive_handle_t *archive_handle)
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
case 'L': {
longname = xzalloc(file_header->size + 1);
- archive_xread_all(archive_handle, longname, file_header->size);
+ xread(archive_handle->src_fd, longname, file_header->size);
archive_handle->offset += file_header->size;
return(get_header_tar(archive_handle));
}
case 'K': {
linkname = xzalloc(file_header->size + 1);
- archive_xread_all(archive_handle, linkname, file_header->size);
+ xread(archive_handle->src_fd, linkname, file_header->size);
archive_handle->offset += file_header->size;
file_header->name = linkname;
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c
index 3e1f466..ad26f46 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)
/* Cant lseek over pipe's */
archive_handle->seek = seek_by_char;
- archive_xread_all(archive_handle, &magic, 2);
+ xread(archive_handle->src_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("Invalid gzip magic");
}
diff --git a/archival/libunarchive/unpack_ar_archive.c b/archival/libunarchive/unpack_ar_archive.c
index 47cf812..eed5283 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)
{
char magic[7];
- archive_xread_all(ar_archive, magic, 7);
+ xread(ar_archive->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
bb_error_msg_and_die("Invalid ar magic");
}
diff --git a/archival/rpm.c b/archival/rpm.c
index 0755789..3b70439 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -193,7 +193,7 @@ void extract_cpio_gz(int fd) {
archive_handle->src_fd = fd;
archive_handle->offset = 0;
- bb_xread_all(archive_handle->src_fd, &magic, 2);
+ xread(archive_handle->src_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("Invalid gzip magic");
}
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 51807c7..6aae150 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -40,7 +40,7 @@ static void skip_header(int rpm_fd)
{
struct rpm_header header;
- bb_xread_all(rpm_fd, &header, sizeof(struct rpm_header));
+ xread(rpm_fd, &header, sizeof(struct rpm_header));
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
bb_error_msg_and_die("Invalid RPM header magic"); /* Invalid magic */
}
@@ -66,7 +66,7 @@ int rpm2cpio_main(int argc, char **argv)
rpm_fd = bb_xopen(argv[1], O_RDONLY);
}
- bb_xread_all(rpm_fd, &lead, sizeof(struct rpm_lead));
+ xread(rpm_fd, &lead, sizeof(struct rpm_lead));
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
bb_error_msg_and_die("Invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
}
@@ -78,7 +78,7 @@ int rpm2cpio_main(int argc, char **argv)
/* Skip the main header */
skip_header(rpm_fd);
- bb_xread_all(rpm_fd, &magic, 2);
+ xread(rpm_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("Invalid gzip magic");
}
diff --git a/archival/tar.c b/archival/tar.c
index 5b7c142..426176b 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -269,9 +269,9 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
putOctal(header.chksum, 7, chksum);
/* Now write the header out to disk */
- if ((size =
- bb_full_write(tbInfo->tarFd, (char *) &header,
- sizeof(struct TarHeader))) < 0) {
+ if ((size = full_write(tbInfo->tarFd, (char *) &header,
+ sizeof(struct TarHeader))) < 0)
+ {
bb_error_msg(bb_msg_io_error, real_name);
return (FALSE);
}
@@ -475,7 +475,7 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
while (1) {
char buf;
- int n = bb_full_read(gzipStatusPipe[0], &buf, 1);
+ int n = full_read(gzipStatusPipe[0], &buf, 1);
if (n == 0 && vfork_exec_errno != 0) {
errno = vfork_exec_errno;
@@ -562,8 +562,8 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
archive_handle->seek = seek_by_char;
/* do the decompression, and cleanup */
- if (bb_xread_char(archive_handle->src_fd) != 0x1f ||
- bb_xread_char(archive_handle->src_fd) != 0x9d)
+ if (xread_char(archive_handle->src_fd) != 0x1f ||
+ xread_char(archive_handle->src_fd) != 0x9d)
{
bb_error_msg_and_die("Invalid magic");
}
diff --git a/archival/uncompress.c b/archival/uncompress.c
index b282fe8..801293f 100644
--- a/archival/uncompress.c
+++ b/archival/uncompress.c
@@ -70,7 +70,7 @@ int uncompress_main(int argc, char **argv)
}
/* do the decompression, and cleanup */
- if ((bb_xread_char(src_fd) != 0x1f) || (bb_xread_char(src_fd) != 0x9d)) {
+ if ((xread_char(src_fd) != 0x1f) || (xread_char(src_fd) != 0x9d)) {
bb_error_msg_and_die("Invalid magic");
}
diff --git a/archival/unzip.c b/archival/unzip.c
index 8ba39e9..632cc85 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -32,28 +32,10 @@
#include "unarchive.h"
#include "busybox.h"
-#if BB_BIG_ENDIAN
-static inline unsigned short
-__swap16(unsigned short x) {
- return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8);
-}
-
-static inline uint32_t
-__swap32(uint32_t x) {
- return (((x & 0xFF) << 24) |
- ((x & 0xFF00) << 8) |
- ((x & 0xFF0000) >> 8) |
- ((x & 0xFF000000) >> 24));
-}
-#else /* it's little-endian */
-# define __swap16(x) (x)
-# define __swap32(x) (x)
-#endif /* BB_BIG_ENDIAN */
-
-#define ZIP_FILEHEADER_MAGIC __swap32(0x04034b50)
-#define ZIP_CDS_MAGIC __swap32(0x02014b50)
-#define ZIP_CDS_END_MAGIC __swap32(0x06054b50)
-#define ZIP_DD_MAGIC __swap32(0x08074b50)
+#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
+#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
+#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
+#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
extern unsigned int gunzip_crc;
extern unsigned int gunzip_bytes_out;
@@ -83,13 +65,6 @@ static void unzip_skip(int fd, off_t skip)
}
}
-static void unzip_read(int fd, void *buf, size_t count)
-{
- if (bb_xread(fd, buf, count) != count) {
- bb_error_msg_and_die(bb_msg_read_error);
- }
-}
-
static void unzip_create_leading_dirs(char *fn)
{
/* Create all leading directories */
@@ -248,7 +223,7 @@ int unzip_main(int argc, char **argv)
unsigned int magic;
/* Check magic number */
- unzip_read(src_fd, &magic, 4);
+ xread(src_fd, &magic, 4);
if (magic == ZIP_CDS_MAGIC) {
break;
} else if (magic != ZIP_FILEHEADER_MAGIC) {
@@ -256,19 +231,17 @@ int unzip_main(int argc, char **argv)
}
/* Read the file header */
- unzip_read(src_fd, zip_header.raw, 26);
-#if BB_BIG_ENDIAN
- zip_header.formated.version = __swap16(zip_header.formated.version);
- zip_header.formated.flags = __swap16(zip_header.formated.flags);
- zip_header.formated.method = __swap16(zip_header.formated.method);
- zip_header.formated.modtime = __swap16(zip_header.formated.modtime);
- zip_header.formated.moddate = __swap16(zip_header.formated.moddate);
- zip_header.formated.crc32 = __swap32(zip_header.formated.crc32);
- zip_header.formated.cmpsize = __swap32(zip_header.formated.cmpsize);
- zip_header.formated.ucmpsize = __swap32(zip_header.formated.ucmpsize);
- zip_header.formated.filename_len = __swap16(zip_header.formated.filename_len);
- zip_header.formated.extra_len = __swap16(zip_header.formated.extra_len);
-#endif /* BB_BIG_ENDIAN */
+ xread(src_fd, zip_header.raw, 26);
+ zip_header.formated.version = SWAP_LE32(zip_header.formated.version);
+ zip_header.formated.flags = SWAP_LE32(zip_header.formated.flags);
+ zip_header.formated.method = SWAP_LE32(zip_header.formated.method);
+ zip_header.formated.modtime = SWAP_LE32(zip_header.formated.modtime);
+ zip_header.formated.moddate = SWAP_LE32(zip_header.formated.moddate);
+ zip_header.formated.crc32 = SWAP_LE32(zip_header.formated.crc32);
+ zip_header.formated.cmpsize = SWAP_LE32(zip_header.formated.cmpsize);
+ zip_header.formated.ucmpsize = SWAP_LE32(zip_header.formated.ucmpsize);
+ zip_header.formated.filename_len = SWAP_LE32(zip_header.formated.filename_len);
+ zip_header.formated.extra_len = SWAP_LE32(zip_header.formated.extra_len);
if ((zip_header.formated.method != 0) && (zip_header.formated.method != 8)) {
bb_error_msg_and_die("Unsupported compression method %d", zip_header.formated.method);
}
@@ -276,7 +249,7 @@ int unzip_main(int argc, char **argv)
/* Read filename */
free(dst_fn);
dst_fn = xzalloc(zip_header.formated.filename_len + 1);
- unzip_read(src_fd, dst_fn, zip_header.formated.filename_len);
+ xread(src_fd, dst_fn, zip_header.formated.filename_len);
/* Skip extra header bytes */
unzip_skip(src_fd, zip_header.formated.extra_len);