int main(int argc, char **argv) { const char *filename; long lines; int ch; struct stat st; off_t size = 0; static const struct option longopts[] = { { "lines", required_argument, 0, 'n' }, { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, { NULL, 0, 0, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); lines = old_style_option(&argc, argv); if (lines < 0) lines = DEFAULT_LINES; while ((ch = getopt_long(argc, argv, "n:N:Vh", longopts, NULL)) != -1) switch((char)ch) { case 'n': case 'N': lines = strtol_or_err(optarg, _("failed to parse number of lines")); break; case 'V': printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING); exit(EXIT_SUCCESS); case 'h': usage(stdout); default: usage(stderr); } if (argc == optind) errx(EXIT_FAILURE, _("no input file specified")); filename = argv[optind]; if (stat(filename, &st) != 0) err(EXIT_FAILURE, _("stat failed %s"), filename); size = st.st_size;; tailf(filename, lines); #ifdef HAVE_INOTIFY_INIT if (!watch_file_inotify(filename, &size)) #endif watch_file(filename, &size); return EXIT_SUCCESS; }
int main(int argc, char **argv) { const char *filename; size_t lines; int ch; struct stat st; static const struct option longopts[] = { { "lines", required_argument, 0, 'n' }, { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, { NULL, 0, 0, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); if (!old_style_option(&argc, argv, &lines)) lines = DEFAULT_LINES; while ((ch = getopt_long(argc, argv, "n:N:Vh", longopts, NULL)) != -1) switch ((char)ch) { case 'n': case 'N': lines = strtoul_or_err(optarg, _("failed to parse number of lines")); break; case 'V': printf(UTIL_LINUX_VERSION); exit(EXIT_SUCCESS); case 'h': usage(stdout); default: usage(stderr); } if (argc == optind) errx(EXIT_FAILURE, _("no input file specified")); filename = argv[optind]; if (stat(filename, &st) != 0) err(EXIT_FAILURE, _("stat of %s failed"), filename); if (!S_ISREG(st.st_mode)) errx(EXIT_FAILURE, _("%s: is not a file"), filename); if (st.st_size) tailf(filename, lines, &st); #ifdef HAVE_INOTIFY_INIT if (!watch_file_inotify(filename, &st)) #endif watch_file(filename, &st); return EXIT_SUCCESS; }