summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-13 00:53:55 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-13 00:53:55 +0000
commit5de3065f5870526a68adee314fe181af976a9246 (patch)
tree8d6e0362cd3fad719451cb395d7f340fa21b85a7
parent3cf52d19581b2077480e7d2e63010baa1f5399c1 (diff)
downloadbusybox-w32-5de3065f5870526a68adee314fe181af976a9246.tar.gz
busybox-w32-5de3065f5870526a68adee314fe181af976a9246.tar.bz2
busybox-w32-5de3065f5870526a68adee314fe181af976a9246.zip
Fixed dd
-rw-r--r--coreutils/dd.c33
-rw-r--r--dd.c33
2 files changed, 32 insertions, 34 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 40288fd4d..ecf7e3a3d 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -20,7 +20,7 @@ const char dd_usage[] =
20usage: [if=name] [of=name] [bs=n] [count=n]\n\ 20usage: [if=name] [of=name] [bs=n] [count=n]\n\
21\tif=FILE\tread from FILE instead of stdin\n\ 21\tif=FILE\tread from FILE instead of stdin\n\
22\tof=FILE\twrite to FILE instead of stout\n\ 22\tof=FILE\twrite to FILE instead of stout\n\
23\tbs=n\tread and write N bytes at a time\n\ 23\tbs=n\tread and write N BYTES at a time\n\
24\tcount=n\tcopy only n input blocks\n\ 24\tcount=n\tcopy only n input blocks\n\
25\tskip=n\tskip n input blocks\n\ 25\tskip=n\tskip n input blocks\n\
26\n\ 26\n\
@@ -100,25 +100,25 @@ extern int dd_main (int argc, char **argv)
100 100
101 /* Parse any options */ 101 /* Parse any options */
102 while (argc) { 102 while (argc) {
103 if (inFile == NULL && (strncmp("if", *argv, 2) == 0)) 103 if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
104 inFile=*argv; 104 inFile=((strchr(*argv, '='))+1);
105 else if (outFile == NULL && (strncmp("of", *argv, 2) == 0)) 105 else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
106 outFile=*argv; 106 outFile=((strchr(*argv, '='))+1);
107 else if (strncmp("count", *argv, 5) == 0) { 107 else if (strncmp("count", *argv, 5) == 0) {
108 count = getNum (*argv); 108 count = getNum ((strchr(*argv, '='))+1);
109 if (count <= 0) { 109 if (count <= 0) {
110 fprintf (stderr, "Bad count value %ld\n", count); 110 fprintf (stderr, "Bad count value %ld\n", count);
111 goto usage; 111 goto usage;
112 } 112 }
113 } 113 }
114 else if (strncmp("bs", *argv, 2) == 0) { 114 else if (strncmp(*argv, "bs", 2) == 0) {
115 blockSize = getNum(*argv); 115 blockSize = getNum ((strchr(*argv, '='))+1);
116 if (blockSize <= 0) { 116 if (blockSize <= 0) {
117 fprintf (stderr, "Bad block size value %d\n", blockSize); 117 fprintf (stderr, "Bad block size value %d\n", blockSize);
118 goto usage; 118 goto usage;
119 } 119 }
120 } 120 }
121 else if (strncmp("skip", *argv, 4) == 0) { 121 else if (strncmp(*argv, "skip", 4) == 0) {
122 skipBlocks = atoi( *argv); 122 skipBlocks = atoi( *argv);
123 if (skipBlocks <= 0) { 123 if (skipBlocks <= 0) {
124 fprintf (stderr, "Bad skip value %d\n", skipBlocks); 124 fprintf (stderr, "Bad skip value %d\n", skipBlocks);
@@ -129,10 +129,9 @@ extern int dd_main (int argc, char **argv)
129 else { 129 else {
130 fprintf (stderr, "Got here. argv=%s\n", *argv); 130 fprintf (stderr, "Got here. argv=%s\n", *argv);
131 goto usage; 131 goto usage;
132 132 }
133 argc--; 133 argc--;
134 argv++; 134 argv++;
135 }
136 } 135 }
137 if ( inFile == NULL || outFile == NULL) 136 if ( inFile == NULL || outFile == NULL)
138 goto usage; 137 goto usage;
@@ -140,13 +139,13 @@ extern int dd_main (int argc, char **argv)
140 buf = malloc (blockSize); 139 buf = malloc (blockSize);
141 if (buf == NULL) { 140 if (buf == NULL) {
142 fprintf (stderr, "Cannot allocate buffer\n"); 141 fprintf (stderr, "Cannot allocate buffer\n");
143 return( FALSE); 142 exit( FALSE);
144 } 143 }
145 144
146 intotal = 0; 145 intotal = 0;
147 outTotal = 0; 146 outTotal = 0;
148 147
149 if (!inFile) 148 if (inFile == NULL)
150 inFd = STDIN; 149 inFd = STDIN;
151 else 150 else
152 inFd = open (inFile, 0); 151 inFd = open (inFile, 0);
@@ -154,10 +153,10 @@ extern int dd_main (int argc, char **argv)
154 if (inFd < 0) { 153 if (inFd < 0) {
155 perror (inFile); 154 perror (inFile);
156 free (buf); 155 free (buf);
157 return( FALSE); 156 exit( FALSE);
158 } 157 }
159 158
160 if (!outFile) 159 if (outFile == NULL)
161 outFd = STDOUT; 160 outFd = STDOUT;
162 else 161 else
163 outFd = creat (outFile, 0666); 162 outFd = creat (outFile, 0666);
@@ -166,10 +165,10 @@ extern int dd_main (int argc, char **argv)
166 perror (outFile); 165 perror (outFile);
167 close (inFd); 166 close (inFd);
168 free (buf); 167 free (buf);
169 return( FALSE); 168 exit( FALSE);
170 } 169 }
171 170
172 lseek(inFd, skipBlocks*blockSize, SEEK_SET); 171 //lseek(inFd, skipBlocks*blockSize, SEEK_SET);
173 while (outTotal < count * blockSize) { 172 while (outTotal < count * blockSize) {
174 inCc = read (inFd, buf, blockSize); 173 inCc = read (inFd, buf, blockSize);
175 if (inCc < 0) { 174 if (inCc < 0) {
diff --git a/dd.c b/dd.c
index 40288fd4d..ecf7e3a3d 100644
--- a/dd.c
+++ b/dd.c
@@ -20,7 +20,7 @@ const char dd_usage[] =
20usage: [if=name] [of=name] [bs=n] [count=n]\n\ 20usage: [if=name] [of=name] [bs=n] [count=n]\n\
21\tif=FILE\tread from FILE instead of stdin\n\ 21\tif=FILE\tread from FILE instead of stdin\n\
22\tof=FILE\twrite to FILE instead of stout\n\ 22\tof=FILE\twrite to FILE instead of stout\n\
23\tbs=n\tread and write N bytes at a time\n\ 23\tbs=n\tread and write N BYTES at a time\n\
24\tcount=n\tcopy only n input blocks\n\ 24\tcount=n\tcopy only n input blocks\n\
25\tskip=n\tskip n input blocks\n\ 25\tskip=n\tskip n input blocks\n\
26\n\ 26\n\
@@ -100,25 +100,25 @@ extern int dd_main (int argc, char **argv)
100 100
101 /* Parse any options */ 101 /* Parse any options */
102 while (argc) { 102 while (argc) {
103 if (inFile == NULL && (strncmp("if", *argv, 2) == 0)) 103 if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
104 inFile=*argv; 104 inFile=((strchr(*argv, '='))+1);
105 else if (outFile == NULL && (strncmp("of", *argv, 2) == 0)) 105 else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
106 outFile=*argv; 106 outFile=((strchr(*argv, '='))+1);
107 else if (strncmp("count", *argv, 5) == 0) { 107 else if (strncmp("count", *argv, 5) == 0) {
108 count = getNum (*argv); 108 count = getNum ((strchr(*argv, '='))+1);
109 if (count <= 0) { 109 if (count <= 0) {
110 fprintf (stderr, "Bad count value %ld\n", count); 110 fprintf (stderr, "Bad count value %ld\n", count);
111 goto usage; 111 goto usage;
112 } 112 }
113 } 113 }
114 else if (strncmp("bs", *argv, 2) == 0) { 114 else if (strncmp(*argv, "bs", 2) == 0) {
115 blockSize = getNum(*argv); 115 blockSize = getNum ((strchr(*argv, '='))+1);
116 if (blockSize <= 0) { 116 if (blockSize <= 0) {
117 fprintf (stderr, "Bad block size value %d\n", blockSize); 117 fprintf (stderr, "Bad block size value %d\n", blockSize);
118 goto usage; 118 goto usage;
119 } 119 }
120 } 120 }
121 else if (strncmp("skip", *argv, 4) == 0) { 121 else if (strncmp(*argv, "skip", 4) == 0) {
122 skipBlocks = atoi( *argv); 122 skipBlocks = atoi( *argv);
123 if (skipBlocks <= 0) { 123 if (skipBlocks <= 0) {
124 fprintf (stderr, "Bad skip value %d\n", skipBlocks); 124 fprintf (stderr, "Bad skip value %d\n", skipBlocks);
@@ -129,10 +129,9 @@ extern int dd_main (int argc, char **argv)
129 else { 129 else {
130 fprintf (stderr, "Got here. argv=%s\n", *argv); 130 fprintf (stderr, "Got here. argv=%s\n", *argv);
131 goto usage; 131 goto usage;
132 132 }
133 argc--; 133 argc--;
134 argv++; 134 argv++;
135 }
136 } 135 }
137 if ( inFile == NULL || outFile == NULL) 136 if ( inFile == NULL || outFile == NULL)
138 goto usage; 137 goto usage;
@@ -140,13 +139,13 @@ extern int dd_main (int argc, char **argv)
140 buf = malloc (blockSize); 139 buf = malloc (blockSize);
141 if (buf == NULL) { 140 if (buf == NULL) {
142 fprintf (stderr, "Cannot allocate buffer\n"); 141 fprintf (stderr, "Cannot allocate buffer\n");
143 return( FALSE); 142 exit( FALSE);
144 } 143 }
145 144
146 intotal = 0; 145 intotal = 0;
147 outTotal = 0; 146 outTotal = 0;
148 147
149 if (!inFile) 148 if (inFile == NULL)
150 inFd = STDIN; 149 inFd = STDIN;
151 else 150 else
152 inFd = open (inFile, 0); 151 inFd = open (inFile, 0);
@@ -154,10 +153,10 @@ extern int dd_main (int argc, char **argv)
154 if (inFd < 0) { 153 if (inFd < 0) {
155 perror (inFile); 154 perror (inFile);
156 free (buf); 155 free (buf);
157 return( FALSE); 156 exit( FALSE);
158 } 157 }
159 158
160 if (!outFile) 159 if (outFile == NULL)
161 outFd = STDOUT; 160 outFd = STDOUT;
162 else 161 else
163 outFd = creat (outFile, 0666); 162 outFd = creat (outFile, 0666);
@@ -166,10 +165,10 @@ extern int dd_main (int argc, char **argv)
166 perror (outFile); 165 perror (outFile);
167 close (inFd); 166 close (inFd);
168 free (buf); 167 free (buf);
169 return( FALSE); 168 exit( FALSE);
170 } 169 }
171 170
172 lseek(inFd, skipBlocks*blockSize, SEEK_SET); 171 //lseek(inFd, skipBlocks*blockSize, SEEK_SET);
173 while (outTotal < count * blockSize) { 172 while (outTotal < count * blockSize) {
174 inCc = read (inFd, buf, blockSize); 173 inCc = read (inFd, buf, blockSize);
175 if (inCc < 0) { 174 if (inCc < 0) {