aboutsummaryrefslogtreecommitdiff
path: root/dd.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>1999-11-19 05:31:45 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>1999-11-19 05:31:45 +0000
commit9854b38d81f9a8c0c5feb245d070b378415a82c2 (patch)
treeeb5564c774b9ef03dc095e7c06e8adb2a8ede1c8 /dd.c
parent1fede547092c5302a27d5c668a47335b36fcdf53 (diff)
downloadbusybox-w32-9854b38d81f9a8c0c5feb245d070b378415a82c2.tar.gz
busybox-w32-9854b38d81f9a8c0c5feb245d070b378415a82c2.tar.bz2
busybox-w32-9854b38d81f9a8c0c5feb245d070b378415a82c2.zip
Stuf
git-svn-id: svn://busybox.net/trunk/busybox@109 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'dd.c')
-rw-r--r--dd.c37
1 files changed, 13 insertions, 24 deletions
diff --git a/dd.c b/dd.c
index 39c6a6263..64948571c 100644
--- a/dd.c
+++ b/dd.c
@@ -32,6 +32,7 @@
32#include <stdio.h> 32#include <stdio.h>
33#include <fcntl.h> 33#include <fcntl.h>
34#include <errno.h> 34#include <errno.h>
35#include <inttypes.h>
35 36
36static const char dd_usage[] = 37static const char dd_usage[] =
37"dd [if=name] [of=name] [bs=n] [count=n]\n\n" 38"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
@@ -92,27 +93,20 @@ static long getNum (const char *cp)
92 93
93extern int dd_main (int argc, char **argv) 94extern int dd_main (int argc, char **argv)
94{ 95{
95 const char *inFile; 96 const char *inFile = NULL;
96 const char *outFile; 97 const char *outFile = NULL;
97 char *cp; 98 char *cp;
98 int inFd; 99 int inFd;
99 int outFd; 100 int outFd;
100 int inCc = 0; 101 int inCc = 0;
101 int outCc; 102 int outCc;
102 int skipBlocks; 103 size_t blockSize = 512;
103 int blockSize; 104 //uintmax_t skipBlocks = 0;
104 long count; 105 uintmax_t count = (uintmax_t)-1;
105 long intotal; 106 uintmax_t intotal;
106 long outTotal; 107 uintmax_t outTotal;
107 unsigned char *buf; 108 unsigned char *buf;
108 109
109 inFile = NULL;
110 outFile = NULL;
111 blockSize = 512;
112 skipBlocks = 0;
113 count = 1;
114
115
116 argc--; 110 argc--;
117 argv++; 111 argv++;
118 112
@@ -125,14 +119,14 @@ extern int dd_main (int argc, char **argv)
125 else if (strncmp("count", *argv, 5) == 0) { 119 else if (strncmp("count", *argv, 5) == 0) {
126 count = getNum ((strchr(*argv, '='))+1); 120 count = getNum ((strchr(*argv, '='))+1);
127 if (count <= 0) { 121 if (count <= 0) {
128 fprintf (stderr, "Bad count value %ld\n", count); 122 fprintf (stderr, "Bad count value %s\n", *argv);
129 goto usage; 123 goto usage;
130 } 124 }
131 } 125 }
132 else if (strncmp(*argv, "bs", 2) == 0) { 126 else if (strncmp(*argv, "bs", 2) == 0) {
133 blockSize = getNum ((strchr(*argv, '='))+1); 127 blockSize = getNum ((strchr(*argv, '='))+1);
134 if (blockSize <= 0) { 128 if (blockSize <= 0) {
135 fprintf (stderr, "Bad block size value %d\n", blockSize); 129 fprintf (stderr, "Bad block size value %s\n", *argv);
136 goto usage; 130 goto usage;
137 } 131 }
138 } 132 }
@@ -162,13 +156,8 @@ extern int dd_main (int argc, char **argv)
162 intotal = 0; 156 intotal = 0;
163 outTotal = 0; 157 outTotal = 0;
164 158
165 if (inFile == NULL) { 159 if (inFile == NULL)
166 struct stat statBuf;
167 inFd = fileno(stdin); 160 inFd = fileno(stdin);
168 if (fstat(inFd, &statBuf) < 0)
169 exit( FALSE);
170 count = statBuf.st_size;
171 }
172 else 161 else
173 inFd = open (inFile, 0); 162 inFd = open (inFile, 0);
174 163
@@ -227,9 +216,9 @@ extern int dd_main (int argc, char **argv)
227 close (outFd); 216 close (outFd);
228 free (buf); 217 free (buf);
229 218
230 printf ("%ld+%d records in\n", intotal / blockSize, 219 printf ("%ld+%d records in\n", (long)(intotal / blockSize),
231 (intotal % blockSize) != 0); 220 (intotal % blockSize) != 0);
232 printf ("%ld+%d records out\n", outTotal / blockSize, 221 printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
233 (outTotal % blockSize) != 0); 222 (outTotal % blockSize) != 0);
234 exit( TRUE); 223 exit( TRUE);
235 usage: 224 usage: