From 18310f1ce3fd2e2fd4ddce6da8ee6867f4196157 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Sun, 10 Sep 2000 04:39:37 +0000 Subject: [PATCH] =?utf8?q?Using=20seek=3D=3F=20used=20to=20cause=20part=20?= =?utf8?q?of=20the=20original=20file=20to=20be=20zero'ed,=20i=20think=20th?= =?utf8?q?is=20was=20caused=20by=20opening=20the=20file=20in=20truncate=20?= =?utf8?q?mode.?= --- coreutils/dd.c | 9 ++++----- dd.c | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/coreutils/dd.c b/coreutils/dd.c index 395f8c1e3..a7c8a2266 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -57,6 +57,7 @@ extern int dd_main(int argc, char **argv) uintmax_t totalSize; uintmax_t readSize; unsigned char buf[BUFSIZ]; + off_t jumped; argc--; argv++; @@ -117,7 +118,7 @@ extern int dd_main(int argc, char **argv) if (outFile == NULL) outFd = fileno(stdout); else - outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666); + outFd = open(outFile, O_WRONLY | O_CREAT, 0666); if (outFd < 0) { /* Note that we are not freeing buf or closing @@ -129,10 +130,9 @@ extern int dd_main(int argc, char **argv) fatalError( outFile); } - lseek(inFd, skipBlocks * blockSize, SEEK_SET); - lseek(outFd, seekBlocks * blockSize, SEEK_SET); + lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); + jumped = lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); totalSize=count*blockSize; - printf("totalsize is %d\n",(int) totalSize); while ((readSize = totalSize - inTotal) > 0) { if (readSize > BUFSIZ) readSize=BUFSIZ; @@ -148,7 +148,6 @@ extern int dd_main(int argc, char **argv) #ifdef BB_FEATURE_CLEAN_UP close(inFd); close(outFd); - free(buf); #endif printf("%ld+%d records in\n", (long) (inTotal / blockSize), diff --git a/dd.c b/dd.c index 395f8c1e3..a7c8a2266 100644 --- a/dd.c +++ b/dd.c @@ -57,6 +57,7 @@ extern int dd_main(int argc, char **argv) uintmax_t totalSize; uintmax_t readSize; unsigned char buf[BUFSIZ]; + off_t jumped; argc--; argv++; @@ -117,7 +118,7 @@ extern int dd_main(int argc, char **argv) if (outFile == NULL) outFd = fileno(stdout); else - outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666); + outFd = open(outFile, O_WRONLY | O_CREAT, 0666); if (outFd < 0) { /* Note that we are not freeing buf or closing @@ -129,10 +130,9 @@ extern int dd_main(int argc, char **argv) fatalError( outFile); } - lseek(inFd, skipBlocks * blockSize, SEEK_SET); - lseek(outFd, seekBlocks * blockSize, SEEK_SET); + lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); + jumped = lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); totalSize=count*blockSize; - printf("totalsize is %d\n",(int) totalSize); while ((readSize = totalSize - inTotal) > 0) { if (readSize > BUFSIZ) readSize=BUFSIZ; @@ -148,7 +148,6 @@ extern int dd_main(int argc, char **argv) #ifdef BB_FEATURE_CLEAN_UP close(inFd); close(outFd); - free(buf); #endif printf("%ld+%d records in\n", (long) (inTotal / blockSize), -- 2.25.1