1*3675e147SDavid Carlier // RUN: %clangxx -O0 -g %s -o %t
2*3675e147SDavid Carlier //
3*3675e147SDavid Carlier // REQUIRES: freebsd, netbsd
4*3675e147SDavid Carlier 
5*3675e147SDavid Carlier #include <assert.h>
6*3675e147SDavid Carlier #include <stdlib.h>
7*3675e147SDavid Carlier #include <ttyent.h>
8*3675e147SDavid Carlier 
9*3675e147SDavid Carlier #include <assert.h>
10*3675e147SDavid Carlier #include <stdlib.h>
11*3675e147SDavid Carlier #include <ttyent.h>
12*3675e147SDavid Carlier 
test1()13*3675e147SDavid Carlier void test1() {
14*3675e147SDavid Carlier   struct ttyent *typ = getttyent();
15*3675e147SDavid Carlier   assert(typ && typ->ty_name != nullptr);
16*3675e147SDavid Carlier   assert(typ->ty_type != nullptr);
17*3675e147SDavid Carlier   endttyent();
18*3675e147SDavid Carlier }
19*3675e147SDavid Carlier 
test2()20*3675e147SDavid Carlier void test2() {
21*3675e147SDavid Carlier   struct ttyent *typ = getttynam("console");
22*3675e147SDavid Carlier   assert(typ && typ->ty_name != nullptr);
23*3675e147SDavid Carlier   assert(typ->ty_type != nullptr);
24*3675e147SDavid Carlier   endttyent();
25*3675e147SDavid Carlier }
26*3675e147SDavid Carlier 
test3()27*3675e147SDavid Carlier void test3() {
28*3675e147SDavid Carlier   if (!setttyent())
29*3675e147SDavid Carlier     exit(1);
30*3675e147SDavid Carlier 
31*3675e147SDavid Carlier   struct ttyent *typ = getttyent();
32*3675e147SDavid Carlier   assert(typ && typ->ty_name != nullptr);
33*3675e147SDavid Carlier   assert(typ->ty_type != nullptr);
34*3675e147SDavid Carlier   endttyent();
35*3675e147SDavid Carlier }
36*3675e147SDavid Carlier 
37*3675e147SDavid Carlier #if defined(__NetBSD__)
test4()38*3675e147SDavid Carlier void test4() {
39*3675e147SDavid Carlier   if (!setttyentpath(_PATH_TTYS))
40*3675e147SDavid Carlier     exit(1);
41*3675e147SDavid Carlier 
42*3675e147SDavid Carlier   struct ttyent *typ = getttyent();
43*3675e147SDavid Carlier   assert(typ && typ->ty_name != nullptr);
44*3675e147SDavid Carlier   assert(typ->ty_type != nullptr);
45*3675e147SDavid Carlier   assert(typ->ty_class != nullptr);
46*3675e147SDavid Carlier 
47*3675e147SDavid Carlier   endttyent();
48*3675e147SDavid Carlier }
49*3675e147SDavid Carlier #endif
50*3675e147SDavid Carlier 
main(void)51*3675e147SDavid Carlier int main(void) {
52*3675e147SDavid Carlier   test1();
53*3675e147SDavid Carlier   test2();
54*3675e147SDavid Carlier   test3();
55*3675e147SDavid Carlier #if defined(__NetBSD__)
56*3675e147SDavid Carlier   test4();
57*3675e147SDavid Carlier #endif
58*3675e147SDavid Carlier 
59*3675e147SDavid Carlier   return 0;
60*3675e147SDavid Carlier }
61