summaryrefslogtreecommitdiff
path: root/src/tail.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-01-04 21:00:22 +0000
committerJim Meyering <jim@meyering.net>2004-01-04 21:00:22 +0000
commitebca34437017619df2065ace62d35dc03c6c57eb (patch)
treeaaabef3c2add653ea8a9b4c44cd2ddbde078579c /src/tail.c
parent5ff0d49b279a12983a28046668686ce9ac0951d3 (diff)
downloadcoreutils-ebca34437017619df2065ace62d35dc03c6c57eb.tar.xz
(main): Warn about following stdin.
Fail when following by name but no names are specified.
Diffstat (limited to 'src/tail.c')
-rw-r--r--src/tail.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/tail.c b/src/tail.c
index 4364ec1ed..7f992d896 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1,5 +1,5 @@
/* tail -- output the last part of file(s)
- Copyright (C) 1989, 90, 91, 1995-2003 Free Software Foundation, Inc.
+ Copyright (C) 1989, 90, 91, 1995-2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1699,7 +1699,6 @@ main (int argc, char **argv)
--n_units;
}
-
if (optind < argc)
{
n_files = argc - optind;
@@ -1712,6 +1711,25 @@ main (int argc, char **argv)
file = &dummy_stdin;
}
+ {
+ bool found_hyphen = false;
+
+ for (i = 0; i < n_files; i++)
+ if (STREQ (file[i], "-"))
+ found_hyphen = true;
+
+ /* When following by name, there must be a name. */
+ if (found_hyphen && follow_mode == Follow_name)
+ error (EXIT_FAILURE, 0, _("cannot follow %s by name"), quote ("-"));
+
+ /* When following forever, warn if any file is `-'.
+ This is only a warning, since tail's output (before a failing seek,
+ and that from any non-stdin files) might still be useful. */
+ if (forever && found_hyphen)
+ error (0, 0, _("warning: following standard input"
+ " indefinitely is ineffective"));
+ }
+
F = xmalloc (n_files * sizeof (F[0]));
for (i = 0; i < n_files; i++)
F[i].name = file[i];