Fix POWER7 Implies
[glibc.git] / io / tst-ttyname_r.c
blob8e2f30c9721e1a8818858fd731475f3415f5b2f1
1 #include <errno.h>
2 #include <error.h>
3 #include <fcntl.h>
4 #include <stdio.h>
5 #include <unistd.h>
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>
13 static int temp_fd;
15 static void
16 do_prepare (void)
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");
24 static int
25 do_test (void)
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)
32 printf ("1st ttyname_r returned with res %d\n", res);
33 ret++;
35 res = ttyname_r (temp_fd, buf, sizeof (buf));
36 if (res != ENOTTY)
38 printf ("2nd ttyname_r returned with res %d\n", res);
39 ret++;
41 return ret;