Skip to content

Commit

Permalink
attempt to regularize atoi mess.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Vlasenko committed Oct 8, 2006
1 parent 5625415 commit 1385899
Show file tree
Hide file tree
Showing 98 changed files with 803 additions and 849 deletions.
3 changes: 0 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ Minor stuff:
-> fprintf(stderr, "unalias: %s not found\n", *argptr);
---
possible code duplication ingroup() and is_a_group_member()
---
unify itoa: netstat.c, hush.c, lash.c, msh.c
Put one single, robust version into e.g. safe_strtol.c
---
Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c
---
Expand Down
4 changes: 2 additions & 2 deletions applets/applets.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ static void parse_config_file(void)

sct->m_uid = strtoul(s, &e2, 10);
if (*e2 || (s == e2)) {
struct passwd *pwd;
if (!(pwd = getpwnam(s))) {
struct passwd *pwd = getpwnam(s);
if (!pwd) {
parse_error("user");
}
sct->m_uid = pwd->pw_uid;
Expand Down
2 changes: 1 addition & 1 deletion archival/cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int cpio_main(int argc, char **argv)
/* Initialise */
archive_handle = init_handle();
archive_handle->src_fd = STDIN_FILENO;
archive_handle->seek = seek_by_char;
archive_handle->seek = seek_by_read;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;

opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename);
Expand Down
2 changes: 1 addition & 1 deletion archival/libunarchive/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
12 changes: 6 additions & 6 deletions archival/libunarchive/get_header_ar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '/') {
Expand Down
45 changes: 22 additions & 23 deletions archival/libunarchive/get_header_tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -102,26 +101,26 @@ 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);
free(temp);
}
}

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) {
Expand Down Expand Up @@ -161,15 +160,15 @@ 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);
xread(archive_handle->src_fd, linkname, file_header->size);
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*/
Expand All @@ -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 */
Expand All @@ -204,5 +203,5 @@ char get_header_tar(archive_handle_t *archive_handle)

free(file_header->link_name);

return(EXIT_SUCCESS);
return EXIT_SUCCESS;
}
6 changes: 3 additions & 3 deletions archival/libunarchive/get_header_tar_bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions archival/libunarchive/get_header_tar_gz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
}
5 changes: 2 additions & 3 deletions archival/libunarchive/get_header_tar_lzma.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

2 changes: 1 addition & 1 deletion archival/libunarchive/seek_by_jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
#include "unarchive.h"
#include "libbb.h"



/* If we are reading through a pipe(), or from stdin then we cant lseek,
/* 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)
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);
Expand Down
2 changes: 1 addition & 1 deletion archival/rpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void extract_cpio_gz(int fd) {

/* Initialise */
archive_handle = init_handle();
archive_handle->seek = seek_by_char;
archive_handle->seek = seek_by_read;
//archive_handle->action_header = header_list;
archive_handle->action_data = data_extract_all;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
Expand Down
4 changes: 2 additions & 2 deletions archival/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
static char get_header_tar_Z(archive_handle_t *archive_handle)
{
/* Cant lseek over pipe's */
archive_handle->seek = seek_by_char;
archive_handle->seek = seek_by_read;

/* do the decompression, and cleanup */
if (xread_char(archive_handle->src_fd) != 0x1f ||
Expand Down Expand Up @@ -805,7 +805,7 @@ int tar_main(int argc, char **argv)

if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
tar_handle->src_fd = fileno(tar_stream);
tar_handle->seek = seek_by_char;
tar_handle->seek = seek_by_read;
} else {
tar_handle->src_fd = xopen3(tar_filename, flags, 0666);
}
Expand Down
11 changes: 6 additions & 5 deletions archival/unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ typedef union {
} formatted ATTRIBUTE_PACKED;
} zip_header_t;

/* This one never works with LARGEFILE-sized skips */
static void unzip_skip(int fd, off_t skip)
{
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
bb_error_msg_and_die("Seek failure");
bb_error_msg_and_die("seek failure");
}
}
}
Expand All @@ -65,7 +66,7 @@ static void unzip_create_leading_dirs(char *fn)
/* Create all leading directories */
char *name = xstrdup(fn);
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */
bb_error_msg_and_die("exiting"); /* bb_make_directory is noisy */
}
free(name);
}
Expand All @@ -76,7 +77,7 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
/* Method 0 - stored (not compressed) */
int size = zip_header->formatted.ucmpsize;
if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) {
bb_error_msg_and_die("Cannot complete extraction");
bb_error_msg_and_die("cannot complete extraction");
}

} else {
Expand All @@ -86,12 +87,12 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
inflate_cleanup();
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
bb_error_msg("Invalid compressed data--crc error");
bb_error_msg("invalid compressed data--%s error", "crc");
return 1;
}
/* Validate decompression - size */
if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
bb_error_msg("Invalid compressed data--length error");
bb_error_msg("invalid compressed data--%s error", "length");
return 1;
}
}
Expand Down
7 changes: 1 addition & 6 deletions console-tools/chvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "busybox.h"

/* From <linux/vt.h> */
Expand All @@ -29,7 +24,7 @@ int chvt_main(int argc, char **argv)
}

fd = get_console_fd();
num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
num = xatoul_range(argv[1], 1, 63);
if ((-1 == ioctl(fd, VT_ACTIVATE, num))
|| (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
bb_perror_msg_and_die("ioctl");
Expand Down
19 changes: 6 additions & 13 deletions console-tools/deallocvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

/* no options, no getopt */

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "busybox.h"

/* From <linux/vt.h> */
Expand All @@ -26,15 +21,13 @@ int deallocvt_main(int argc, char *argv[])
int num = 0;

switch (argc) {
case 2:
if ((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) {
bb_error_msg_and_die("0: illegal VT number");
}
case 2:
num = xatoul_range(argv[1], 1, 63);
/* Fallthrough */
case 1:
break;
default:
bb_show_usage();
case 1:
break;
default:
bb_show_usage();
}

if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) {
Expand Down
Loading

0 comments on commit 1385899

Please sign in to comment.