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