added count flag in dd, also fixed help message and suffixes parser
This commit is contained in:
parent
c908b952f0
commit
f7ad6c896a
|
@ -1,6 +1,8 @@
|
|||
#ifndef _HUMAN_H
|
||||
#define _HUMAN_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
char *mu_humansize(off_t n) {
|
||||
static char buf[16];
|
||||
char *postfixes = "BKMGTPE";
|
||||
|
|
|
@ -41,22 +41,22 @@ off_t strtonum(char *str) {
|
|||
if (!strcmp(p, "b"))
|
||||
res *= 512;
|
||||
|
||||
else if (!strcmp(p, "MB"))
|
||||
else if (!strcmp(p, "m"))
|
||||
res *= 1000000;
|
||||
|
||||
else if (!strcmp(p, "M"))
|
||||
res *= 1048576;
|
||||
|
||||
else if (!strcmp(p, "KB"))
|
||||
else if (!strcmp(p, "K"))
|
||||
res *= 1024;
|
||||
|
||||
else if (!strcmp(p, "kB"))
|
||||
else if (!strcmp(p, "k"))
|
||||
res *= 1000;
|
||||
|
||||
else if (!strcmp(p, "G"))
|
||||
else if (!strcmp(p, "g"))
|
||||
res *= 1000000000;
|
||||
|
||||
else if (!strcmp(p, "GB"))
|
||||
else if (!strcmp(p, "G"))
|
||||
res *= 1073741824;
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,7 @@ int main(int argc, char **argv) {
|
|||
char *ifp = "-";
|
||||
char *ofp = "-";
|
||||
|
||||
off_t count = -1;
|
||||
off_t skip = 0;
|
||||
off_t seek = 0;
|
||||
|
||||
|
@ -104,7 +105,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
char *val = strchr(arg, '=');
|
||||
if (val == NULL) {
|
||||
printf("dd\n\t[if=InputFile]\n\t[of=OutputFile]\n\nN and BYTES may be followed by the following multiplicative\nsuffixes: w=2, b=512, kB=1000, K=1024, MB=1000*1000,\nM=1024*1024, GB=1000*1000*1000, G=1024*1024*1024\n");
|
||||
printf("dd\n\t[if=InputFile] [of=OutputFile]\n\t[bs=obs and obs]\n\t[ibs=Input buffer size]\n\t[obs=Output buffer size]\n\t[seek=Skip N obs-sized output blocks]\n\t[skip=Skip N ibs-sized output blocks]\n\t[count=Copy only N input blocks]\n\nN and BYTES may be followed by the following multiplicative\nsuffixes: w=2, b=512, k=1000, K=1024, m=1000*1000,\nM=1024*1024, g=1000*1000*1000, G=1024*1024*1024\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -181,19 +182,25 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* dd */
|
||||
while (1) {
|
||||
off_t n = read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
if (count == infull + inpart)
|
||||
break;
|
||||
|
||||
if (ibs == n)
|
||||
off_t n = read(ifd, ibuf, ibs);
|
||||
if (n <= 0)
|
||||
break;
|
||||
|
||||
else if (ibs == n)
|
||||
infull++;
|
||||
|
||||
else
|
||||
inpart++;
|
||||
|
||||
if (ibs == obs)
|
||||
if (ibs == obs) {
|
||||
if (copy(ofd, ibuf, n, ibs))
|
||||
goto CLOSE;
|
||||
}
|
||||
|
||||
else {}
|
||||
}
|
||||
|
||||
/* End */
|
||||
|
|
|
@ -43,11 +43,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
for (int i = 0; i < argc; i++) {
|
||||
double val = 0;
|
||||
if (!strcmp(argv[i], "-r"))
|
||||
r_flag = 1;
|
||||
if (argv[i][0] == '-') {
|
||||
if (strstr(argv[i], "r"))
|
||||
r_flag = 1;
|
||||
|
||||
else if (!strcmp(argv[i], "-n"))
|
||||
ret = '\r';
|
||||
if (strstr(argv[i], "n"))
|
||||
ret = '\r';
|
||||
}
|
||||
|
||||
else if (parse_double(argv[i], &val)) {
|
||||
if (val > max)
|
||||
|
|
Loading…
Reference in New Issue