aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2001-04-11 05:01:09 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2001-04-11 05:01:09 +0000
commit48081f81bda9108672fa04fe57b3921cb24ba4b2 (patch)
tree669c6e9eb4c8911916995e827832594940e9c9d0
parent7dc8d227a57bc225bc1045a3a6cd6ee78e10852b (diff)
downloadbusybox-w32-48081f81bda9108672fa04fe57b3921cb24ba4b2.tar.gz
busybox-w32-48081f81bda9108672fa04fe57b3921cb24ba4b2.tar.bz2
busybox-w32-48081f81bda9108672fa04fe57b3921cb24ba4b2.zip
replace getOctal with strtol( , NULL, 8)
saves 100 Bytes
-rw-r--r--archival/tar.c36
-rw-r--r--tar.c36
2 files changed, 16 insertions, 56 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 9459dd6d5..15d050c5a 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -476,26 +476,6 @@ tarExtractSpecial(TarInfo *header, int extractFlag, int tostdoutFlag)
476 return( TRUE); 476 return( TRUE);
477} 477}
478 478
479/* Read an octal value in a field of the specified width, with optional
480 * spaces on both sides of the number and with an optional null character
481 * at the end. Returns -1 on an illegal format. */
482static long getOctal(const char *cp, int size)
483{
484 long val = 0;
485
486 for(;(size > 0) && (*cp == ' '); cp++, size--);
487 if ((size == 0) || !is_octal(*cp))
488 return -1;
489 for(; (size > 0) && is_octal(*cp); size--) {
490 val = val * 8 + *cp++ - '0';
491 }
492 for (;(size > 0) && (*cp == ' '); cp++, size--);
493 if ((size > 0) && *cp)
494 return -1;
495 return val;
496}
497
498
499/* Parse the tar header and fill in the nice struct with the details */ 479/* Parse the tar header and fill in the nice struct with the details */
500static int 480static int
501readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) 481readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
@@ -518,16 +498,16 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
518 } 498 }
519 } 499 }
520 500
521 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode)); 501 header->mode = strtol(rawHeader->mode, NULL, 8);
522 header->uid = getOctal(rawHeader->uid, sizeof(rawHeader->uid)); 502 header->uid = strtol(rawHeader->uid, NULL, 8);
523 header->gid = getOctal(rawHeader->gid, sizeof(rawHeader->gid)); 503 header->gid = strtol(rawHeader->gid, NULL, 8);
524 header->size = getOctal(rawHeader->size, sizeof(rawHeader->size)); 504 header->size = strtol(rawHeader->size, NULL, 8);
525 header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime)); 505 header->mtime = strtol(rawHeader->mtime, NULL, 8);
526 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum)); 506 chksum = strtol(rawHeader->chksum, NULL, 8);
527 header->type = rawHeader->typeflag; 507 header->type = rawHeader->typeflag;
528 header->linkname = rawHeader->linkname; 508 header->linkname = rawHeader->linkname;
529 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor)); 509 header->devmajor = strtol(rawHeader->devmajor, NULL, 8);
530 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor)); 510 header->devminor = strtol(rawHeader->devminor, NULL, 8);
531 511
532 /* Check the checksum */ 512 /* Check the checksum */
533 for (i = sizeof(*rawHeader); i-- != 0;) { 513 for (i = sizeof(*rawHeader); i-- != 0;) {
diff --git a/tar.c b/tar.c
index 9459dd6d5..15d050c5a 100644
--- a/tar.c
+++ b/tar.c
@@ -476,26 +476,6 @@ tarExtractSpecial(TarInfo *header, int extractFlag, int tostdoutFlag)
476 return( TRUE); 476 return( TRUE);
477} 477}
478 478
479/* Read an octal value in a field of the specified width, with optional
480 * spaces on both sides of the number and with an optional null character
481 * at the end. Returns -1 on an illegal format. */
482static long getOctal(const char *cp, int size)
483{
484 long val = 0;
485
486 for(;(size > 0) && (*cp == ' '); cp++, size--);
487 if ((size == 0) || !is_octal(*cp))
488 return -1;
489 for(; (size > 0) && is_octal(*cp); size--) {
490 val = val * 8 + *cp++ - '0';
491 }
492 for (;(size > 0) && (*cp == ' '); cp++, size--);
493 if ((size > 0) && *cp)
494 return -1;
495 return val;
496}
497
498
499/* Parse the tar header and fill in the nice struct with the details */ 479/* Parse the tar header and fill in the nice struct with the details */
500static int 480static int
501readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header) 481readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
@@ -518,16 +498,16 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
518 } 498 }
519 } 499 }
520 500
521 header->mode = getOctal(rawHeader->mode, sizeof(rawHeader->mode)); 501 header->mode = strtol(rawHeader->mode, NULL, 8);
522 header->uid = getOctal(rawHeader->uid, sizeof(rawHeader->uid)); 502 header->uid = strtol(rawHeader->uid, NULL, 8);
523 header->gid = getOctal(rawHeader->gid, sizeof(rawHeader->gid)); 503 header->gid = strtol(rawHeader->gid, NULL, 8);
524 header->size = getOctal(rawHeader->size, sizeof(rawHeader->size)); 504 header->size = strtol(rawHeader->size, NULL, 8);
525 header->mtime = getOctal(rawHeader->mtime, sizeof(rawHeader->mtime)); 505 header->mtime = strtol(rawHeader->mtime, NULL, 8);
526 chksum = getOctal(rawHeader->chksum, sizeof(rawHeader->chksum)); 506 chksum = strtol(rawHeader->chksum, NULL, 8);
527 header->type = rawHeader->typeflag; 507 header->type = rawHeader->typeflag;
528 header->linkname = rawHeader->linkname; 508 header->linkname = rawHeader->linkname;
529 header->devmajor = getOctal(rawHeader->devmajor, sizeof(rawHeader->devmajor)); 509 header->devmajor = strtol(rawHeader->devmajor, NULL, 8);
530 header->devminor = getOctal(rawHeader->devminor, sizeof(rawHeader->devminor)); 510 header->devminor = strtol(rawHeader->devminor, NULL, 8);
531 511
532 /* Check the checksum */ 512 /* Check the checksum */
533 for (i = sizeof(*rawHeader); i-- != 0;) { 513 for (i = sizeof(*rawHeader); i-- != 0;) {