aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-08-04 10:16:59 -0500
committerRob Landley <rob@landley.net>2016-08-04 10:16:59 -0500
commit027a73a903af306449710ce12bc09e0e3550c6c9 (patch)
treea415cb11fa6f2b34e63b8259fc52342aaa8fec75 /toys/posix
parent145b7024b5fbb74f16d5e403fb004ff8209bc4a0 (diff)
downloadtoybox-027a73a903af306449710ce12bc09e0e3550c6c9.tar.gz
Make xopen() skip stdin/stdout/stderr, add xopen_stdio() if you want stdout,
add xopenro() that takes one argument and understands "-" means stdin, and switch over lots of users.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/comm.c3
-rw-r--r--toys/posix/cut.c8
-rw-r--r--toys/posix/find.c2
-rw-r--r--toys/posix/grep.c2
-rw-r--r--toys/posix/nohup.c2
-rw-r--r--toys/posix/patch.c4
-rw-r--r--toys/posix/sed.c3
-rw-r--r--toys/posix/uudecode.c2
-rw-r--r--toys/posix/uuencode.c2
9 files changed, 13 insertions, 15 deletions
diff --git a/toys/posix/comm.c b/toys/posix/comm.c
index 6c726cf6..ded262f5 100644
--- a/toys/posix/comm.c
+++ b/toys/posix/comm.c
@@ -48,8 +48,7 @@ void comm_main(void)
if (toys.optflags == 7) return;
for (i = 0; i < 2; i++) {
- file[i] = strcmp("-", toys.optargs[i])
- ? xopen(toys.optargs[i], O_RDONLY) : 0;
+ file[i] = xopenro(toys.optargs[i]);
line[i] = get_line(file[i]);
}
diff --git a/toys/posix/cut.c b/toys/posix/cut.c
index 1acefe2b..13be5e74 100644
--- a/toys/posix/cut.c
+++ b/toys/posix/cut.c
@@ -77,13 +77,13 @@ static void parse_list(char *list)
if (!ctoken) break;
if (!*ctoken) continue;
- //Get start position.
+ // Get start position.
if (*(dtoken = strsep(&ctoken, "-"))) {
start = atolx_range(dtoken, 0, INT_MAX);
start = (start?(start-1):start);
}
- //Get end position.
+ // Get end position.
if (!ctoken) end = -1; //case e.g. 1,2,3
else if (*ctoken) {//case e.g. N-M
end = atolx_range(ctoken, 0, INT_MAX);
@@ -94,7 +94,7 @@ static void parse_list(char *list)
add_to_list(start, end);
TT.nelem++;
}
- //if list is missing in command line.
+ // if list is missing in command line.
if (!TT.nelem) error_exit("missing positions list");
}
@@ -112,7 +112,7 @@ static void get_data(void)
if(strcmp(*argv, "-") == 0) TT.do_cut(0); //for stdin
else {
int fd = open(*argv, O_RDONLY, 0);
- if(fd < 0) {//if file not present then continue with other files.
+ if (fd < 0) {//if file not present then continue with other files.
perror_msg_raw(*argv);
continue;
}
diff --git a/toys/posix/find.c b/toys/posix/find.c
index a1821ca3..02f7702d 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -454,7 +454,7 @@ static int do_find(struct dirtree *new)
ss += len;
aa->arglen = len;
aa->dir = !!strchr(s, 'd');
- if (TT.topdir == -1) TT.topdir = xopen(".", 0);
+ if (TT.topdir == -1) TT.topdir = xopenro(".");
// collect names and execute commands
} else {
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 9e50a7ca..6423ea6b 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -359,7 +359,7 @@ void grep_main(void)
toys.exitval = 1;
if (toys.optflags & FLAG_s) {
close(2);
- xopen("/dev/null", O_RDWR);
+ xopen_stdio("/dev/null", O_RDWR);
}
if (toys.optflags & FLAG_r) {
diff --git a/toys/posix/nohup.c b/toys/posix/nohup.c
index 4d6d59f6..b302cbe4 100644
--- a/toys/posix/nohup.c
+++ b/toys/posix/nohup.c
@@ -36,7 +36,7 @@ void nohup_main(void)
}
if (isatty(0)) {
close(0);
- open("/dev/null", O_RDONLY);
+ xopen_stdio("/dev/null", O_RDONLY);
}
xexec(toys.optargs);
}
diff --git a/toys/posix/patch.c b/toys/posix/patch.c
index 2c73d958..fbad1fb9 100644
--- a/toys/posix/patch.c
+++ b/toys/posix/patch.c
@@ -265,7 +265,7 @@ void patch_main(void)
strip = 0;
char *oldname = NULL, *newname = NULL;
- if (TT.infile) TT.filepatch = xopen(TT.infile, O_RDONLY);
+ if (TT.infile) TT.filepatch = xopenro(TT.infile);
TT.filein = TT.fileout = -1;
if (TT.dir) xchdir(TT.dir);
@@ -402,7 +402,7 @@ void patch_main(void)
TT.filein = xcreate(name, O_CREAT|O_EXCL|O_RDWR, 0666);
} else {
printf("patching %s\n", name);
- TT.filein = xopen(name, O_RDONLY);
+ TT.filein = xopenro(name);
}
if (toys.optflags & FLAG_dry_run)
TT.fileout = xopen("/dev/null", O_RDWR);
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 063c20c3..71988248 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -1026,8 +1026,7 @@ void sed_main(void)
// so handle all -e, then all -f. (At least the behavior's consistent.)
for (al = TT.e; al; al = al->next) parse_pattern(&al->arg, strlen(al->arg));
- for (al = TT.f; al; al = al->next)
- do_lines(strcmp(al->arg, "-") ? xopen(al->arg, O_RDONLY) : 0,parse_pattern);
+ for (al = TT.f; al; al = al->next) do_lines(xopenro(al->arg), parse_pattern);
parse_pattern(0, 0);
dlist_terminate(TT.pattern);
if (TT.nextlen) error_exit("no }");
diff --git a/toys/posix/uudecode.c b/toys/posix/uudecode.c
index fd557eca..238e27e9 100644
--- a/toys/posix/uudecode.c
+++ b/toys/posix/uudecode.c
@@ -30,7 +30,7 @@ void uudecode_main(void)
char *line = 0, mode[16],
*class[] = {"begin%*[ ]%15s%*[ ]%n", "begin-base64%*[ ]%15s%*[ ]%n"};
- if (toys.optc) ifd = xopen(*toys.optargs, O_RDONLY);
+ if (toys.optc) ifd = xopenro(*toys.optargs);
while (!idx) {
free(line);
diff --git a/toys/posix/uuencode.c b/toys/posix/uuencode.c
index 34ca7013..06709d5e 100644
--- a/toys/posix/uuencode.c
+++ b/toys/posix/uuencode.c
@@ -26,7 +26,7 @@ void uuencode_main(void)
int i, m = toys.optflags & FLAG_m, fd = 0;
- if (toys.optc > 1) fd = xopen(toys.optargs[0], O_RDONLY);
+ if (toys.optc > 1) fd = xopenro(toys.optargs[0]);
base64_init(toybuf);