aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/other/fsync.c4
-rw-r--r--toys/other/truncate.c6
-rw-r--r--toys/posix/cmp.c10
-rw-r--r--toys/posix/grep.c9
-rw-r--r--toys/posix/sed.c4
-rw-r--r--toys/posix/tail.c4
-rw-r--r--toys/posix/tee.c4
7 files changed, 19 insertions, 22 deletions
diff --git a/toys/other/fsync.c b/toys/other/fsync.c
index e6f6c8d9..bd73f398 100644
--- a/toys/other/fsync.c
+++ b/toys/other/fsync.c
@@ -28,6 +28,6 @@ static void do_fsync(int fd, char *name)
void fsync_main(void)
{
- loopfiles_rw(toys.optargs, O_RDONLY|O_NOATIME|O_NOCTTY|O_CLOEXEC,
- 0, 0, do_fsync);
+ loopfiles_rw(toys.optargs, O_RDONLY|O_NOATIME|O_NOCTTY|O_CLOEXEC|WARN_ONLY,
+ 0, do_fsync);
}
diff --git a/toys/other/truncate.c b/toys/other/truncate.c
index bfe1f10c..6092d5a9 100644
--- a/toys/other/truncate.c
+++ b/toys/other/truncate.c
@@ -53,13 +53,13 @@ static void do_truncate(int fd, char *name)
void truncate_main(void)
{
- int cr = !(toys.optflags&1);
+ int cr = !(toys.optflags&FLAG_c);
if (-1 != (TT.type = stridx("+-<>/%", *TT.s))) TT.s++;
TT.size = atolx(TT.s);
// Create files with mask rwrwrw.
// Nonexistent files are only an error if we're supposed to create them.
- loopfiles_rw(toys.optargs, O_WRONLY|O_CLOEXEC|(cr ? O_CREAT : 0), 0666, cr,
- do_truncate);
+ loopfiles_rw(toys.optargs, O_WRONLY|O_CLOEXEC|(cr ? O_CREAT|WARN_ONLY : 0),
+ 0666, do_truncate);
}
diff --git a/toys/posix/cmp.c b/toys/posix/cmp.c
index 527fbfda..f4c34091 100644
--- a/toys/posix/cmp.c
+++ b/toys/posix/cmp.c
@@ -43,6 +43,8 @@ static void do_cmp(int fd, char *name)
return;
}
+ toys.exitval = 0;
+
for (;;) {
len1 = readall(TT.fd, toybuf, size);
len2 = readall(fd, buf2, size);
@@ -54,11 +56,9 @@ static void do_cmp(int fd, char *name)
if (toys.optflags & FLAG_l)
printf("%ld %o %o\n", byte_no, toybuf[i], buf2[i]);
else {
- if (!(toys.optflags & FLAG_s)) {
+ if (!(toys.optflags & FLAG_s))
printf("%s %s differ: char %ld, line %ld\n",
TT.name, name, byte_no, line_no);
- toys.exitval++;
- }
goto out;
}
}
@@ -79,6 +79,8 @@ out:
void cmp_main(void)
{
- loopfiles_rw(toys.optargs, O_CLOEXEC, 0, toys.optflags&FLAG_s, do_cmp);
+ toys.exitval = 2;
+ loopfiles_rw(toys.optargs, O_CLOEXEC|(WARN_ONLY*!(toys.optflags&FLAG_s)), 0,
+ do_cmp);
}
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 6423ea6b..2fe6ac27 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -81,17 +81,12 @@ static void outline(char *line, char dash, char *name, long lcount, long bcount,
static void do_grep(int fd, char *name)
{
struct double_list *dlb = 0;
- FILE *file = fdopen(fd, "r");
+ FILE *file = xfdopen(fd, "r");
long lcount = 0, mcount = 0, offset = 0, after = 0, before = 0;
char *bars = 0;
if (!fd) name = "(standard input)";
- if (!file) {
- perror_msg_raw(name);
- return;
- }
-
// Loop through lines of input
for (;;) {
char *line = 0, *start;
@@ -368,5 +363,5 @@ void grep_main(void)
if (!strcmp(*ss, "-")) do_grep(0, *ss);
else dirtree_read(*ss, do_grep_r);
}
- } else loopfiles_rw(ss, O_RDONLY, 0, 1, do_grep);
+ } else loopfiles_rw(ss, O_RDONLY|WARN_ONLY, 0, do_grep);
}
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index c62d2d10..744edf7b 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -1010,8 +1010,8 @@ void sed_main(void)
TT.fdout = 1;
TT.remember = xstrdup("");
- // Inflict pattern upon input files
- loopfiles_rw(args, O_RDONLY, 0, 0, do_sed);
+ // Inflict pattern upon input files. Long version because !O_CLOEXEC
+ loopfiles_rw(args, O_RDONLY|WARN_ONLY, 0, do_sed);
if (!(toys.optflags & FLAG_i)) process_line(0, 0);
diff --git a/toys/posix/tail.c b/toys/posix/tail.c
index 787e116e..22b5ac6d 100644
--- a/toys/posix/tail.c
+++ b/toys/posix/tail.c
@@ -242,8 +242,8 @@ void tail_main(void)
if ((TT.ffd = inotify_init()) < 0) perror_exit("inotify_init");
TT.files = xmalloc(toys.optc*8);
}
- loopfiles_rw(args, O_RDONLY|(O_CLOEXEC*!(toys.optflags&FLAG_f)),
- 0, 0, do_tail);
+ loopfiles_rw(args, O_RDONLY|WARN_ONLY|(O_CLOEXEC*!(toys.optflags&FLAG_f)),
+ 0, do_tail);
if ((toys.optflags & FLAG_f) && TT.file_no) {
int len, last_fd = TT.files[(TT.file_no-1)*2], i, fd;
diff --git a/toys/posix/tee.c b/toys/posix/tee.c
index d5591b67..6167c8ad 100644
--- a/toys/posix/tee.c
+++ b/toys/posix/tee.c
@@ -49,8 +49,8 @@ void tee_main(void)
// Open output files
loopfiles_rw(toys.optargs,
- O_RDWR|O_CREAT|((toys.optflags & FLAG_a)?O_APPEND:O_TRUNC),
- 0666, 0, do_tee_open);
+ O_RDWR|O_CREAT|WARN_ONLY|((toys.optflags & FLAG_a)?O_APPEND:O_TRUNC),
+ 0666, do_tee_open);
for (;;) {
struct fd_list *fdl;