1 | #include <errno.h> |
2 | #include <error.h> |
3 | #include <fcntl.h> |
4 | #include <stdio.h> |
5 | #include <unistd.h> |
6 | |
7 | static void do_prepare (void); |
8 | #define PREPARE(argc, argv) do_prepare () |
9 | static int do_test (void); |
10 | #define TEST_FUNCTION do_test () |
11 | #include <test-skeleton.c> |
12 | |
13 | static int temp_fd; |
14 | |
15 | static void |
16 | do_prepare (void) |
17 | { |
18 | char *temp_file; |
19 | temp_fd = create_temp_file (base: "tst-ttyname_r." , filename: &temp_file); |
20 | if (temp_fd == -1) |
21 | error (status: 1, errno, format: "cannot create temporary file" ); |
22 | } |
23 | |
24 | static int |
25 | do_test (void) |
26 | { |
27 | int ret = 0; |
28 | char buf[sysconf (_SC_TTY_NAME_MAX) + 1]; |
29 | int res = ttyname_r (fd: -1, buf: buf, buflen: sizeof (buf)); |
30 | if (res != EBADF) |
31 | { |
32 | printf (format: "1st ttyname_r returned with res %d\n" , res); |
33 | ret++; |
34 | } |
35 | res = ttyname_r (fd: temp_fd, buf: buf, buflen: sizeof (buf)); |
36 | if (res != ENOTTY) |
37 | { |
38 | printf (format: "2nd ttyname_r returned with res %d\n" , res); |
39 | ret++; |
40 | } |
41 | return ret; |
42 | } |
43 | |