diff options
| author | Erik Andersen <andersen@codepoet.org> | 2000-02-07 05:29:42 +0000 |
|---|---|---|
| committer | Erik Andersen <andersen@codepoet.org> | 2000-02-07 05:29:42 +0000 |
| commit | fac10d7c59f7db0facd5fb94de273310b9ec86e6 (patch) | |
| tree | dccf8f905fc5807239883da9fca6597037d487fc /coreutils/dd.c | |
| parent | 50bc101b7d6e847a9a0621ca3eb28c7117d095e5 (diff) | |
| download | busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.gz busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.tar.bz2 busybox-w32-fac10d7c59f7db0facd5fb94de273310b9ec86e6.zip | |
A few minor updates. ;-)
Seriously though, read the Changelog for busybox 0.42,
which this is about to become...
-Erik
Diffstat (limited to 'coreutils/dd.c')
| -rw-r--r-- | coreutils/dd.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index bc01eedbf..3e1024a60 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
| @@ -40,15 +40,16 @@ typedef unsigned long long int uintmax_t; | |||
| 40 | #endif | 40 | #endif |
| 41 | 41 | ||
| 42 | static const char dd_usage[] = | 42 | static const char dd_usage[] = |
| 43 | "dd [if=name] [of=name] [bs=n] [count=n]\n\n" | 43 | "dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n" |
| 44 | "Copy a file, converting and formatting according to options\n\n" | 44 | "Copy a file, converting and formatting according to options\n\n" |
| 45 | "\tif=FILE\tread from FILE instead of stdin\n" | 45 | "\tif=FILE\tread from FILE instead of stdin\n" |
| 46 | "\tof=FILE\twrite to FILE instead of stout\n" | 46 | "\tof=FILE\twrite to FILE instead of stdout\n" |
| 47 | "\tbs=n\tread and write N BYTES at a time\n" | 47 | "\tbs=n\tread and write n bytes at a time\n" |
| 48 | "\tcount=n\tcopy only n input blocks\n" | 48 | "\tcount=n\tcopy only n input blocks\n" |
| 49 | //"\tskip=n\tskip n input blocks\n" | 49 | "\tskip=n\tskip n input blocks\n" |
| 50 | "\tseek=n\tskip n output blocks\n" | ||
| 50 | "\n" | 51 | "\n" |
| 51 | "BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n"; | 52 | "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"; |
| 52 | 53 | ||
| 53 | 54 | ||
| 54 | 55 | ||
| @@ -61,8 +62,9 @@ extern int dd_main (int argc, char **argv) | |||
| 61 | int outFd; | 62 | int outFd; |
| 62 | int inCc = 0; | 63 | int inCc = 0; |
| 63 | int outCc; | 64 | int outCc; |
| 64 | size_t blockSize = 512; | 65 | long blockSize = 512; |
| 65 | //uintmax_t skipBlocks = 0; | 66 | uintmax_t skipBlocks = 0; |
| 67 | uintmax_t seekBlocks = 0; | ||
| 66 | uintmax_t count = (uintmax_t)-1; | 68 | uintmax_t count = (uintmax_t)-1; |
| 67 | uintmax_t intotal; | 69 | uintmax_t intotal; |
| 68 | uintmax_t outTotal; | 70 | uintmax_t outTotal; |
| @@ -91,16 +93,22 @@ extern int dd_main (int argc, char **argv) | |||
| 91 | goto usage; | 93 | goto usage; |
| 92 | } | 94 | } |
| 93 | } | 95 | } |
| 94 | #if 0 | ||
| 95 | else if (strncmp(*argv, "skip", 4) == 0) { | 96 | else if (strncmp(*argv, "skip", 4) == 0) { |
| 96 | skipBlocks = atoi( *argv); | 97 | skipBlocks = getNum ((strchr(*argv, '='))+1); |
| 97 | if (skipBlocks <= 0) { | 98 | if (skipBlocks <= 0) { |
| 98 | fprintf (stderr, "Bad skip value %d\n", skipBlocks); | 99 | fprintf (stderr, "Bad skip value %s\n", *argv); |
| 100 | goto usage; | ||
| 101 | } | ||
| 102 | |||
| 103 | } | ||
| 104 | else if (strncmp(*argv, "seek", 4) == 0) { | ||
| 105 | seekBlocks = getNum ((strchr(*argv, '='))+1); | ||
| 106 | if (seekBlocks <= 0) { | ||
| 107 | fprintf (stderr, "Bad seek value %s\n", *argv); | ||
| 99 | goto usage; | 108 | goto usage; |
| 100 | } | 109 | } |
| 101 | 110 | ||
| 102 | } | 111 | } |
| 103 | #endif | ||
| 104 | else { | 112 | else { |
| 105 | goto usage; | 113 | goto usage; |
| 106 | } | 114 | } |
| @@ -131,7 +139,7 @@ extern int dd_main (int argc, char **argv) | |||
| 131 | if (outFile == NULL) | 139 | if (outFile == NULL) |
| 132 | outFd = fileno(stdout); | 140 | outFd = fileno(stdout); |
| 133 | else | 141 | else |
| 134 | outFd = creat (outFile, 0666); | 142 | outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 135 | 143 | ||
| 136 | if (outFd < 0) { | 144 | if (outFd < 0) { |
| 137 | perror (outFile); | 145 | perror (outFile); |
| @@ -140,10 +148,11 @@ extern int dd_main (int argc, char **argv) | |||
| 140 | exit( FALSE); | 148 | exit( FALSE); |
| 141 | } | 149 | } |
| 142 | 150 | ||
| 143 | //lseek(inFd, skipBlocks*blockSize, SEEK_SET); | 151 | lseek(inFd, skipBlocks*blockSize, SEEK_SET); |
| 152 | lseek(outFd, seekBlocks*blockSize, SEEK_SET); | ||
| 144 | // | 153 | // |
| 145 | //TODO: Convert to using fullRead & fullWrite | 154 | //TODO: Convert to using fullRead & fullWrite |
| 146 | // from utilitity.c | 155 | // from utility.c |
| 147 | // -Erik | 156 | // -Erik |
| 148 | while (outTotal < count * blockSize) { | 157 | while (outTotal < count * blockSize) { |
| 149 | inCc = read (inFd, buf, blockSize); | 158 | inCc = read (inFd, buf, blockSize); |
