summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-06 10:53:42 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-06 11:00:48 +0200
commitabb3643d886210e41adff642a98afde49f09d3dc (patch)
tree96d5b34a4cd3777ace486017be800e178bb8ab92
parent1f17b40d0031ff960326c6fbd6d8e277f9356560 (diff)
downloadserenity-abb3643d886210e41adff642a98afde49f09d3dc.zip
tail: Shell programs should return 1 to indicate failure.
-rw-r--r--Userland/tail.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/Userland/tail.cpp b/Userland/tail.cpp
index 4a0ef12317..cf19e7b34e 100644
--- a/Userland/tail.cpp
+++ b/Userland/tail.cpp
@@ -10,7 +10,7 @@
int tail_from_pos(CFile& file, off_t startline, bool want_follow)
{
if (!file.seek(startline + 1))
- return -1;
+ return 1;
while (true) {
const auto& b = file.read(4096);
@@ -26,9 +26,8 @@ int tail_from_pos(CFile& file, off_t startline, bool want_follow)
}
}
- if (write(STDOUT_FILENO, b.pointer(), b.size()) < 0) {
- return -1;
- }
+ if (write(STDOUT_FILENO, b.pointer(), b.size()) < 0)
+ return 1;
}
return 0;
@@ -41,7 +40,7 @@ off_t find_seek_pos(CFile& file, int wanted_lines)
off_t pos = 0;
if (!file.seek(0, CIODevice::SeekMode::FromEndPosition, &pos)) {
fprintf(stderr, "Failed to find end of file: %s\n", file.error_string());
- return -1;
+ return 1;
}
off_t end = pos;
@@ -70,7 +69,7 @@ off_t find_seek_pos(CFile& file, int wanted_lines)
static void exit_because_we_wanted_lines()
{
fprintf(stderr, "Expected a line count after -n");
- exit(-1);
+ exit(1);
}
int main(int argc, char *argv[])
@@ -86,7 +85,7 @@ int main(int argc, char *argv[])
Vector<String> values = args.get_single_values();
if (values.size() != 1) {
args_parser.print_usage();
- return -1;
+ return 1;
}
int line_count = 0;
@@ -94,14 +93,14 @@ int main(int argc, char *argv[])
line_count = strtol(args.get("n").characters(), NULL, 10);
if (errno == EINVAL) {
args_parser.print_usage();
- return -1;
+ return 1;
}
}
CFile f(values[0]);
if (!f.open(CIODevice::ReadOnly)) {
fprintf(stderr, "Error opening file %s: %s\n", f.filename().characters(), strerror(errno));
- exit(-1);
+ exit(1);
}
bool flag_follow = args.is_present("f");