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
do_prepare(void)16 do_prepare (void)
17 {
18   char *temp_file;
19   temp_fd = create_temp_file ("tst-ttyname_r.", &temp_file);
20   if (temp_fd == -1)
21     error (1, errno, "cannot create temporary file");
22 }
23 
24 static int
do_test(void)25 do_test (void)
26 {
27   int ret = 0;
28   char buf[sysconf (_SC_TTY_NAME_MAX) + 1];
29   int res = ttyname_r (-1, buf, sizeof (buf));
30   if (res != EBADF)
31     {
32       printf ("1st ttyname_r returned with res %d\n", res);
33       ret++;
34     }
35   res = ttyname_r (temp_fd, buf, sizeof (buf));
36   if (res != ENOTTY)
37     {
38       printf ("2nd ttyname_r returned with res %d\n", res);
39       ret++;
40     }
41   return ret;
42 }
43