fixed xargs and dd

This commit is contained in:
Your Name 2024-02-13 14:16:31 +03:00
parent 25599584fb
commit 1a7b13daf2
4 changed files with 43 additions and 14 deletions

View File

@ -1,4 +1,5 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

View File

@ -10,7 +10,7 @@ int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
return 0;
if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') {
fprintf(stderr, "%s: Denied\n", prog_name);
fprintf(stderr, "%s: Access denied\n", prog_name);
return 1;
}

View File

@ -36,7 +36,7 @@ int openfile(int flag, char *path, int mode) {
off_t strtonum(char *str) {
char *p = NULL;
off_t res = strtoll(str, &p, 10);
off_t res = strtoll(str, &p, 0);
if (str != p) {
if (!strcmp(p, "b"))
res *= 512;
@ -60,7 +60,7 @@ off_t strtonum(char *str) {
res *= 1073741824;
}
if (res <= 1)
if (res < 0)
res = 0;
return res;
@ -181,6 +181,8 @@ int main(int argc, char **argv) {
}
/* dd */
off_t opos = 0;
while (1) {
if (count == infull + inpart)
break;
@ -200,7 +202,31 @@ int main(int argc, char **argv) {
goto CLOSE;
}
else {}
else {
char *tmp = ibuf;
while (n) {
off_t i = obs - opos;
if (i > n)
i = n;
memcpy(obuf + opos, tmp, i);
n -= i;
tmp += i;
opos += i;
if (opos == obs) {
if (copy(ofd, obuf, obs, obs))
goto CLOSE;
opos = 0;
}
}
}
}
if (opos != 0) {
if (copy(ofd, obuf, obs, obs))
goto CLOSE;
}
/* End */

View File

@ -60,8 +60,10 @@ int stdin_read(void) {
*p = '\0';
p = arg;
if (add_arg(arg, chars))
break;
if (add_arg(arg, chars)) {
fprintf(stderr, "xargs: argument line too long\n");
exit(1);
}
args_passed++;
}