diff options
author | Jo-Philipp Wich <jo@mein.io> | 2023-01-09 15:28:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 15:28:29 +0100 |
commit | 8dad974baa4696fcba85837fa70cde8b68dd7c12 (patch) | |
tree | 987c4127c3e5d774f6b5c31762c2281e63ca9114 | |
parent | 98637e08dba5ba472e78868378335a4a3694109f (diff) | |
parent | be30472bfdbbb410e8934b48a56d26c5c630d0f1 (diff) |
Merge pull request #137 from ynezz/ynezz/isatty
fs: add `isatty()` function
-rw-r--r-- | lib/fs.c | 18 | ||||
-rw-r--r-- | tests/custom/03_stdlib/40_proto | 1 |
2 files changed, 19 insertions, 0 deletions
@@ -353,6 +353,23 @@ uc_fs_tell(uc_vm_t *vm, size_t nargs) } static uc_value_t * +uc_fs_isatty(uc_vm_t *vm, size_t nargs) +{ + FILE **fp = uc_fn_this("fs.file"); + int fd; + + if (!fp || !*fp) + err_return(EBADF); + + fd = fileno(*fp); + + if (fd == -1) + err_return(errno); + + return ucv_boolean_new(isatty(fd)); +} + +static uc_value_t * uc_fs_flush(uc_vm_t *vm, size_t nargs) { return uc_fs_flush_common(vm, nargs, "fs.file"); @@ -1356,6 +1373,7 @@ static const uc_function_list_t file_fns[] = { { "flush", uc_fs_flush }, { "fileno", uc_fs_fileno }, { "error", uc_fs_error }, + { "isatty", uc_fs_isatty }, }; static const uc_function_list_t dir_fns[] = { diff --git a/tests/custom/03_stdlib/40_proto b/tests/custom/03_stdlib/40_proto index d7d0c2c..2a12966 100644 --- a/tests/custom/03_stdlib/40_proto +++ b/tests/custom/03_stdlib/40_proto @@ -38,6 +38,7 @@ When invoked with two arguments, returns the given value. Hello, World! [ { + "isatty": "function isatty(...) { [native code] }", "error": "function error(...) { [native code] }", "fileno": "function fileno(...) { [native code] }", "flush": "function flush(...) { [native code] }", |