| 1 | #include <wasi/api.h> |
| 2 | #include <__errno.h> |
| 3 | #include <__function___isatty.h> |
| 4 | |
| 5 | int __isatty(int fd) { |
| 6 | __wasi_fdstat_t statbuf; |
| 7 | int r = __wasi_fd_fdstat_get(fd, &statbuf); |
| 8 | if (r != 0) { |
| 9 | errno = r; |
| 10 | return 0; |
| 11 | } |
| 12 | |
| 13 | // A tty is a character device that we can't seek or tell on. |
| 14 | if (statbuf.fs_filetype != __WASI_FILETYPE_CHARACTER_DEVICE || |
| 15 | (statbuf.fs_rights_base & (__WASI_RIGHTS_FD_SEEK | __WASI_RIGHTS_FD_TELL)) != 0) { |
| 16 | errno = __WASI_ERRNO_NOTTY; |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | return 1; |
| 21 | } |
| 22 | extern __typeof(__isatty) isatty __attribute__((weak, alias("__isatty"))); |