Cleaup read() and write() variants, plus a couple of new functions like
xlseek and fdlength() for the new mkswap.
This commit is contained 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 \
|
||||
|
@@ -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;
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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++) {
|
||||
|
@@ -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 */
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
|
@@ -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");
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user