From 1385899416a4396385ad421ae1f532be7103738a Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 8 Oct 2006 12:49:22 +0000 Subject: attempt to regularize atoi mess. --- archival/libunarchive/Kbuild | 2 +- archival/libunarchive/get_header_ar.c | 12 ++++---- archival/libunarchive/get_header_tar.c | 45 ++++++++++++++--------------- archival/libunarchive/get_header_tar_bz2.c | 6 ++-- archival/libunarchive/get_header_tar_gz.c | 6 ++-- archival/libunarchive/get_header_tar_lzma.c | 5 ++-- archival/libunarchive/seek_by_char.c | 23 --------------- archival/libunarchive/seek_by_jump.c | 2 +- archival/libunarchive/seek_by_read.c | 19 ++++++++++++ 9 files changed, 57 insertions(+), 63 deletions(-) delete mode 100644 archival/libunarchive/seek_by_char.c create mode 100644 archival/libunarchive/seek_by_read.c (limited to 'archival/libunarchive') diff --git a/archival/libunarchive/Kbuild b/archival/libunarchive/Kbuild index c5f1bfbfe..4e1454184 100644 --- a/archival/libunarchive/Kbuild +++ b/archival/libunarchive/Kbuild @@ -21,7 +21,7 @@ lib-y:= \ \ archive_xread_all_eof.o \ \ - seek_by_char.o \ + seek_by_read.o \ seek_by_jump.o \ \ data_align.o \ diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c index cabb4101b..7372ada32 100644 --- a/archival/libunarchive/get_header_ar.c +++ b/archival/libunarchive/get_header_ar.c @@ -46,14 +46,14 @@ char get_header_ar(archive_handle_t *archive_handle) /* align the headers based on the header magic */ if ((ar.formatted.magic[0] != '`') || (ar.formatted.magic[1] != '\n')) { - bb_error_msg_and_die("Invalid ar header"); + bb_error_msg_and_die("invalid ar header"); } - typed->mode = strtol(ar.formatted.mode, NULL, 8); - typed->mtime = atoi(ar.formatted.date); - typed->uid = atoi(ar.formatted.uid); - typed->gid = atoi(ar.formatted.gid); - typed->size = atoi(ar.formatted.size); + typed->mode = xstrtoul(ar.formatted.mode, 8); + typed->mtime = xatou(ar.formatted.date); + typed->uid = xatou(ar.formatted.uid); + typed->gid = xatou(ar.formatted.gid); + typed->size = xatoul(ar.formatted.size); /* long filenames have '/' as the first character */ if (ar.formatted.name[0] == '/') { diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 0c622f44a..d3cd96d0c 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c @@ -62,10 +62,10 @@ char get_header_tar(archive_handle_t *archive_handle) * Read until the end to empty the pipe from gz or bz2 */ while (full_read(archive_handle->src_fd, tar.raw, 512) == 512); - return(EXIT_FAILURE); + return EXIT_FAILURE; } end = 1; - return(EXIT_SUCCESS); + return EXIT_SUCCESS; } end = 0; @@ -76,19 +76,18 @@ char get_header_tar(archive_handle_t *archive_handle) #ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0) #endif - bb_error_msg_and_die("Invalid tar magic"); + bb_error_msg_and_die("invalid tar magic"); } /* Do checksum on headers */ for (i = 0; i < 148 ; i++) { sum += tar.raw[i]; } sum += ' ' * 8; - for (i = 156; i < 512 ; i++) { + for (i = 156; i < 512 ; i++) { sum += tar.raw[i]; } - if (sum != strtol(tar.formatted.chksum, NULL, 8)) { - bb_error_msg("Invalid tar header checksum"); - return(EXIT_FAILURE); + if (sum != xstrtoul(tar.formatted.chksum, 8)) { + bb_error_msg_and_die("invalid tar header checksum"); } #ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS @@ -102,8 +101,7 @@ char get_header_tar(archive_handle_t *archive_handle) } else #endif { - file_header->name = xstrndup(tar.formatted.name,100); - + file_header->name = xstrndup(tar.formatted.name, 100); if (tar.formatted.prefix[0]) { char *temp = file_header->name; file_header->name = concat_path_file(tar.formatted.prefix, temp); @@ -111,17 +109,18 @@ char get_header_tar(archive_handle_t *archive_handle) } } - file_header->uid = strtol(tar.formatted.uid, NULL, 8); - file_header->gid = strtol(tar.formatted.gid, NULL, 8); - file_header->size = strtol(tar.formatted.size, NULL, 8); - file_header->mtime = strtol(tar.formatted.mtime, NULL, 8); - file_header->link_name = (tar.formatted.linkname[0] != '\0') ? - xstrdup(tar.formatted.linkname) : NULL; - file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8), - strtol(tar.formatted.devminor, NULL, 8)); + file_header->uid = xstrtoul(tar.formatted.uid, 8); + file_header->gid = xstrtoul(tar.formatted.gid, 8); + // TODO: LFS support + file_header->size = xstrtoul(tar.formatted.size, 8); + file_header->mtime = xstrtoul(tar.formatted.mtime, 8); + file_header->link_name = tar.formatted.linkname[0] ? + xstrdup(tar.formatted.linkname) : NULL; + file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8), + xstrtoul(tar.formatted.devminor, 8)); /* Set bits 0-11 of the files mode */ - file_header->mode = 07777 & strtol(tar.formatted.mode, NULL, 8); + file_header->mode = 07777 & xstrtoul(tar.formatted.mode, 8); /* Set bits 12-15 of the files mode */ switch (tar.formatted.typeflag) { @@ -161,7 +160,7 @@ char get_header_tar(archive_handle_t *archive_handle) xread(archive_handle->src_fd, longname, file_header->size); archive_handle->offset += file_header->size; - return(get_header_tar(archive_handle)); + return get_header_tar(archive_handle); } case 'K': { linkname = xzalloc(file_header->size + 1); @@ -169,7 +168,7 @@ char get_header_tar(archive_handle_t *archive_handle) archive_handle->offset += file_header->size; file_header->name = linkname; - return(get_header_tar(archive_handle)); + return get_header_tar(archive_handle); } case 'D': /* GNU dump dir */ case 'M': /* Continuation of multi volume archive*/ @@ -179,10 +178,10 @@ char get_header_tar(archive_handle_t *archive_handle) #endif case 'g': /* pax global header */ case 'x': /* pax extended header */ - bb_error_msg("Ignoring extension type %c", tar.formatted.typeflag); + bb_error_msg("ignoring extension type %c", tar.formatted.typeflag); break; default: - bb_error_msg("Unknown typeflag: 0x%x", tar.formatted.typeflag); + bb_error_msg("unknown typeflag: 0x%x", tar.formatted.typeflag); } { /* Strip trailing '/' in directories */ /* Must be done after mode is set as '/' is used to check if its a directory */ @@ -204,5 +203,5 @@ char get_header_tar(archive_handle_t *archive_handle) free(file_header->link_name); - return(EXIT_SUCCESS); + return EXIT_SUCCESS; } diff --git a/archival/libunarchive/get_header_tar_bz2.c b/archival/libunarchive/get_header_tar_bz2.c index a8b630814..e3cb328fc 100644 --- a/archival/libunarchive/get_header_tar_bz2.c +++ b/archival/libunarchive/get_header_tar_bz2.c @@ -16,12 +16,12 @@ char get_header_tar_bz2(archive_handle_t *archive_handle) { /* Cant lseek over pipe's */ - archive_handle->seek = seek_by_char; + archive_handle->seek = seek_by_read; archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream); archive_handle->offset = 0; - while (get_header_tar(archive_handle) == EXIT_SUCCESS); + while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; /* Can only do one file at a time */ - return(EXIT_FAILURE); + return EXIT_FAILURE; } diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c index 24e4f9c9f..af059a187 100644 --- a/archival/libunarchive/get_header_tar_gz.c +++ b/archival/libunarchive/get_header_tar_gz.c @@ -13,7 +13,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle) unsigned char magic[2]; /* Cant lseek over pipe's */ - archive_handle->seek = seek_by_char; + archive_handle->seek = seek_by_read; xread(archive_handle->src_fd, &magic, 2); if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { @@ -24,8 +24,8 @@ char get_header_tar_gz(archive_handle_t *archive_handle) archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); archive_handle->offset = 0; - while (get_header_tar(archive_handle) == EXIT_SUCCESS); + while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; /* Can only do one file at a time */ - return(EXIT_FAILURE); + return EXIT_FAILURE; } diff --git a/archival/libunarchive/get_header_tar_lzma.c b/archival/libunarchive/get_header_tar_lzma.c index e38583fef..06b8daa0f 100644 --- a/archival/libunarchive/get_header_tar_lzma.c +++ b/archival/libunarchive/get_header_tar_lzma.c @@ -11,13 +11,12 @@ char get_header_tar_lzma(archive_handle_t * archive_handle) { /* Can't lseek over pipes */ - archive_handle->seek = seek_by_char; + archive_handle->seek = seek_by_read; archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma); archive_handle->offset = 0; - while (get_header_tar(archive_handle) == EXIT_SUCCESS); + while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; /* Can only do one file at a time */ return EXIT_FAILURE; } - diff --git a/archival/libunarchive/seek_by_char.c b/archival/libunarchive/seek_by_char.c deleted file mode 100644 index f4d8c2f2b..000000000 --- a/archival/libunarchive/seek_by_char.c +++ /dev/null @@ -1,23 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. - */ - -#include - -#include "unarchive.h" -#include "libbb.h" - - - -/* If we are reading through a pipe(), or from stdin then we cant lseek, - * we must read and discard the data to skip over it. - * - * TODO: rename to seek_by_read - */ -void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size) -{ - if (jump_size) { - bb_copyfd_size(archive_handle->src_fd, -1, jump_size); - } -} diff --git a/archival/libunarchive/seek_by_jump.c b/archival/libunarchive/seek_by_jump.c index 231360fa3..e1917dd2a 100644 --- a/archival/libunarchive/seek_by_jump.c +++ b/archival/libunarchive/seek_by_jump.c @@ -16,7 +16,7 @@ void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amo if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) { #ifdef CONFIG_FEATURE_UNARCHIVE_TAPE if (errno == ESPIPE) { - seek_by_char(archive_handle, amount); + seek_by_read(archive_handle, amount); } else #endif bb_perror_msg_and_die("Seek failure"); diff --git a/archival/libunarchive/seek_by_read.c b/archival/libunarchive/seek_by_read.c new file mode 100644 index 000000000..03cbb9ecc --- /dev/null +++ b/archival/libunarchive/seek_by_read.c @@ -0,0 +1,19 @@ +/* vi: set sw=4 ts=4: */ +/* + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ + +#include + +#include "unarchive.h" +#include "libbb.h" + +/* If we are reading through a pipe(), or from stdin then we cant lseek, + * we must read and discard the data to skip over it. + */ +void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size) +{ + if (jump_size) { + bb_copyfd_size(archive_handle->src_fd, -1, jump_size); + } +} -- cgit v1.2.3