]> git.ipfire.org Git - thirdparty/util-linux.git/blame - text-utils/line.c
libblkid: check status for the current CDROM slot
[thirdparty/util-linux.git] / text-utils / line.c
CommitLineData
63cccae4
KZ
1/*
2 * line - read one line
3 *
4 * Gunnar Ritter, Freiburg i. Br., Germany, December 2000.
5 *
6 * Public Domain.
7 */
8
ba0c9030
SK
9/*
10 * This command is deprecated. The utility is in maintenance mode,
11 * meaning we keep them in source tree for backward compatibility
12 * only. Do not waste time making this command better, unless the
13 * fix is about security or other very critical issue.
14 *
15 * See Documentation/deprecated.txt for more information.
16 */
17
c2e1ebbe
SK
18#include <getopt.h>
19#include <stdio.h>
20#include <unistd.h>
63cccae4 21
c2e1ebbe
SK
22#include "c.h"
23#include "closestream.h"
24#include "nls.h"
25#include "widechar.h"
63cccae4 26
86be6a32 27static void __attribute__((__noreturn__)) usage(void)
63cccae4 28{
86be6a32 29 FILE *out = stdout;
c2e1ebbe
SK
30 fputs(USAGE_HEADER, out);
31 fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
451dbcfa
BS
32
33 fputs(USAGE_SEPARATOR, out);
34 fputs(_("Read one line.\n"), out);
35
c2e1ebbe 36 fputs(USAGE_OPTIONS, out);
f45f3ec3
RM
37 printf(USAGE_HELP_OPTIONS(16));
38 printf(USAGE_MAN_TAIL("line(1)"));
86be6a32 39 exit(EXIT_SUCCESS);
c2e1ebbe
SK
40}
41
42int main(int argc, char **argv)
43{
44 wint_t c;
45 int opt;
46 int status = EXIT_SUCCESS;
47
48 static const struct option longopts[] = {
49 {"version", no_argument, NULL, 'V'},
50 {"help", no_argument, NULL, 'h'},
51 {NULL, 0, NULL, 0}
52 };
53
54 setlocale(LC_ALL, "");
55 bindtextdomain(PACKAGE, LOCALEDIR);
56 textdomain(PACKAGE);
2c308875 57 close_stdout_atexit();
c2e1ebbe
SK
58
59 while ((opt = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
60 switch (opt) {
61 case 'V':
2c308875 62 print_version(EXIT_SUCCESS);
c2e1ebbe 63 case 'h':
86be6a32 64 usage();
c2e1ebbe 65 default:
677ec86c 66 errtryhelp(EXIT_FAILURE);
c2e1ebbe 67 }
63cccae4 68
e03f29b6 69 setvbuf(stdin, NULL, _IONBF, 0);
63cccae4 70 for (;;) {
c2e1ebbe
SK
71 c = getwchar();
72 if (c == WEOF) {
73 status = EXIT_FAILURE;
63cccae4
KZ
74 break;
75 }
76 if (c == '\n')
77 break;
c2e1ebbe 78 putwchar(c);
63cccae4 79 }
c2e1ebbe 80 putwchar(L'\n');
63cccae4 81
63cccae4
KZ
82 return status;
83}