X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Fdd.c;h=9c7d872b195511354a2f59982cbccd455844b841;hb=cbb0a4b40d32a653957d2c9ecb6fe1a70b30d907;hp=0d5b3e8ab9867bc7918208da17b763275e4b72de;hpb=e49d5ecbbe51718fa925b6890a735e5937cc2aa2;p=oweals%2Fbusybox.git diff --git a/coreutils/dd.c b/coreutils/dd.c index 0d5b3e8ab..9c7d872b1 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -57,8 +57,8 @@ static const char dd_usage[] = extern int dd_main(int argc, char **argv) { - const char *inFile = NULL; - const char *outFile = NULL; + char *inFile = NULL; + char *outFile = NULL; char *cp; int inFd; int outFd; @@ -114,11 +114,7 @@ extern int dd_main(int argc, char **argv) argv++; } - buf = malloc(blockSize); - if (buf == NULL) { - fprintf(stderr, "Cannot allocate buffer\n"); - exit(FALSE); - } + buf = xmalloc(blockSize); intotal = 0; outTotal = 0; @@ -129,9 +125,12 @@ extern int dd_main(int argc, char **argv) inFd = open(inFile, 0); if (inFd < 0) { - perror(inFile); - free(buf); - exit(FALSE); + /* Note that we are not freeing buf or closing + * files here to save a few bytes. This exits + * here anyways... */ + + /* free(buf); */ + fatalError( inFile); } if (outFile == NULL) @@ -140,10 +139,13 @@ extern int dd_main(int argc, char **argv) outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (outFd < 0) { - perror(outFile); - close(inFd); - free(buf); - exit(FALSE); + /* Note that we are not freeing buf or closing + * files here to save a few bytes. This exits + * here anyways... */ + + /* close(inFd); + free(buf); */ + fatalError( outFile); } lseek(inFd, skipBlocks * blockSize, SEEK_SET); @@ -184,9 +186,13 @@ extern int dd_main(int argc, char **argv) perror(inFile); cleanup: + /* Note that we are not freeing memory or closing + * files here, to save a few bytes. */ +#if 0 close(inFd); close(outFd); free(buf); +#endif printf("%ld+%d records in\n", (long) (intotal / blockSize), (intotal % blockSize) != 0);