This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include <unistd.h>
20
21 #include "signature.h"
22 SIGNATURE_CHECK (isatty, int, (int));
23
24 #include <errno.h>
25 #include <fcntl.h>
26
27 #include "macros.h"
28
29
30 #if defined _WIN32 && ! defined __CYGWIN__
31
32 # define DEV_NULL "NUL"
33 #else
34
35 # define DEV_NULL "/dev/null"
36 #endif
37
38 int
39 main (void)
40 {
41 const char *file = "test-isatty.txt";
42
43
44 {
45 errno = 0;
46 ASSERT (isatty (-1) == 0);
47 ASSERT (errno == EBADF
48 || errno == 0
49 );
50 }
51 {
52 close (99);
53 errno = 0;
54 ASSERT (isatty (99) == 0);
55 ASSERT (errno == EBADF
56 || errno == 0
57 );
58 }
59
60
61 {
62 int fd;
63
64 fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
65 ASSERT (0 <= fd);
66 ASSERT (write (fd, "hello", 5) == 5);
67 ASSERT (close (fd) == 0);
68
69 fd = open (file, O_RDONLY);
70 ASSERT (0 <= fd);
71 ASSERT (! isatty (fd));
72 ASSERT (close (fd) == 0);
73 }
74
75
76 {
77 int fd[2];
78
79 ASSERT (pipe (fd) == 0);
80 ASSERT (! isatty (fd[0]));
81 ASSERT (! isatty (fd[1]));
82 ASSERT (close (fd[0]) == 0);
83 ASSERT (close (fd[1]) == 0);
84 }
85
86
87 {
88 int fd;
89
90 fd = open (DEV_NULL, O_RDONLY);
91 ASSERT (0 <= fd);
92 ASSERT (! isatty (fd));
93 ASSERT (close (fd) == 0);
94 }
95
96 ASSERT (unlink (file) == 0);
97
98 return 0;
99 }