getty: handle variable number of arguments, only tty required

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-05-30 11:55:21 +02:00
1 parent e349abb897
commit 654f8aeb19
1 file changed
+28 -5
+28 -5
View File
@@ -222,14 +222,37 @@ restart:
return do_login(name); return do_login(name);
} }
int main(int argc, char *argv[]) static int usage(int rc)
{ {
if (argc < 4) { warnx("usage: getty [-h?] tty [speed [term]]");
warnx("usage: getty tty speed term"); return rc;
return 1;
} }
return getty(argv[1], atoi(argv[2]), argv[3], NULL); int main(int argc, char *argv[])
{
char *tty, *speed = "0", *term = NULL;
int c;
while ((c = getopt(argc, argv, "h?")) != EOF) {
switch(c) {
case 'h':
case '?':
return usage(0);
default:
return usage(1);
}
}
if (optind >= argc)
return usage(1);
tty = argv[optind++];
if (optind < argc)
speed = argv[optind++];
if (optind < argc)
term = argv[optind++];
return getty(tty, atoi(speed), term, NULL);
} }
/** /**