From ece39a9a1859be150e874754755213e264f3be8a Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 22 Apr 2018 11:47:44 +0200 Subject: [PATCH] mlibc: Add isatty. * lib/libc.c (isatty): New function. * include/unistd.h: Declare it. --- include/unistd.h | 1 + lib/libc.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/unistd.h b/include/unistd.h index 5c6426e3..1c4086ad 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -51,6 +51,7 @@ int access (char const *s, int mode); int close (int fd); int execvp (char const *file, char *const argv[]); char *getcwd (char *buf, size_t size); +int isatty (int fd); off_t lseek (int fd, off_t offset, int whence); int read (int fd, void* buf, size_t n); int unlink (char const *file_name); diff --git a/lib/libc.c b/lib/libc.c index bfef3eec..97565c31 100644 --- a/lib/libc.c +++ b/lib/libc.c @@ -18,6 +18,7 @@ * along with Mes. If not, see . */ +#include #include #include @@ -419,4 +420,11 @@ sprintf (char *str, char const* format, ...) va_end (ap); return r; } + +int +isatty (int fd) +{ + return ioctl (fd, TCGETS, 0) == -14; // MAGIC +} + #endif //!POSIX