1 /* Test isatty() function.
2 Copyright (C) 2011-2018 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #include "signature.h"
22 SIGNATURE_CHECK (isatty
, int, (int));
29 /* The name of the "always silent" device. */
30 #if defined _WIN32 && ! defined __CYGWIN__
31 /* Native Windows API. */
32 # define DEV_NULL "NUL"
35 # define DEV_NULL "/dev/null"
41 const char *file
= "test-isatty.txt";
43 /* Test behaviour for invalid file descriptors. */
46 ASSERT (isatty (-1) == 0);
47 ASSERT (errno
== EBADF
48 || errno
== 0 /* seen on IRIX 6.5, Solaris 10 */
54 ASSERT (isatty (99) == 0);
55 ASSERT (errno
== EBADF
56 || errno
== 0 /* seen on IRIX 6.5, Solaris 10 */
60 /* Test behaviour for regular files. */
64 fd
= open (file
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0644);
66 ASSERT (write (fd
, "hello", 5) == 5);
67 ASSERT (close (fd
) == 0);
69 fd
= open (file
, O_RDONLY
);
71 ASSERT (! isatty (fd
));
72 ASSERT (close (fd
) == 0);
75 /* Test behaviour for pipes. */
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);
86 /* Test behaviour for /dev/null. */
90 fd
= open (DEV_NULL
, O_RDONLY
);
92 ASSERT (! isatty (fd
));
93 ASSERT (close (fd
) == 0);
96 ASSERT (unlink (file
) == 0);