1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <ttyent.h>
6 
7 #define STRING_OR_NULL(x) ((x) ? (x) : "null")
8 
test1()9 void test1() {
10   struct ttyent *typ = getttyent();
11 
12   printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
13          STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
14          typ->ty_status, STRING_OR_NULL(typ->ty_window),
15          STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
16 
17   endttyent();
18 }
19 
test2()20 void test2() {
21   struct ttyent *typ = getttynam("console");
22 
23   printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
24          STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
25          typ->ty_status, STRING_OR_NULL(typ->ty_window),
26          STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
27 
28   endttyent();
29 }
30 
test3()31 void test3() {
32   if (!setttyent())
33     exit(1);
34 
35   struct ttyent *typ = getttyent();
36 
37   printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
38          STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
39          typ->ty_status, STRING_OR_NULL(typ->ty_window),
40          STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
41 
42   endttyent();
43 }
44 
test4()45 void test4() {
46   if (!setttyentpath(_PATH_TTYS))
47     exit(1);
48 
49   struct ttyent *typ = getttyent();
50 
51   printf("%s %s %s %d %s %s %s\n", STRING_OR_NULL(typ->ty_name),
52          STRING_OR_NULL(typ->ty_getty), STRING_OR_NULL(typ->ty_type),
53          typ->ty_status, STRING_OR_NULL(typ->ty_window),
54          STRING_OR_NULL(typ->ty_comment), STRING_OR_NULL(typ->ty_class));
55 
56   endttyent();
57 }
58 
main(void)59 int main(void) {
60   printf("ttyent\n");
61 
62   test1();
63   test2();
64   test3();
65   test4();
66 
67   // CHECK: ttyent
68 
69   return 0;
70 }
71