summaryrefslogtreecommitdiff
path: root/src/unistd
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-02 15:03:13 -0500
committerJakob Kaivo <jkk@ung.org>2019-03-02 15:03:13 -0500
commit26eb259d69ca2e8be905349c930818756f404601 (patch)
treed9c2fdcd3cb3a79fea68c839830694b53ca93c9c /src/unistd
parent9f7b74c64bf2730c2a23e66693b49bd98e5bf28b (diff)
document and implement in terms of tcgetattr()
Diffstat (limited to 'src/unistd')
-rw-r--r--src/unistd/isatty.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c
index 1b502d75..cc27576f 100644
--- a/src/unistd/isatty.c
+++ b/src/unistd/isatty.c
@@ -1,13 +1,31 @@
#include "stddef.h"
#include "sys/types.h"
#include <unistd.h>
-#include "errno.h"
-#include "nonstd/syscall.h"
+#include "termios.h"
+
+/** test for a terminal device **/
int isatty(int fildes)
{
- SYSCALL("isatty", int, -1, fildes, 0, 0, 0, 0, 0);
+ struct termios tios;
+ if (tcgetattr(fildes, &tios) == 0) {
+ /* errno set by tcgetattr() */
+ #if 0
+ errno = EBADF; /* ARGUMENT(fildes) is not a valid file descriptor */
+ errno = ENOTTY; /* ARGUMENT(fildes) is not associated with a terminal */
+ #endif
+ return 1;
+ }
+ return 0;
}
+
+/***
+checks whether the file descriptor ARGUMENT(fildes) is associated with a
+terminal device.
+***/
+
/*
+RETURN(ZERO, ARGUMENT(fildes) is not a terminal)
+RETURN(ONE, ARGUMENT(fildes) is a terminal device)
POSIX(1)
*/