summaryrefslogtreecommitdiffstats
path: root/sysif.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-05-11 06:23:26 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-05-11 06:23:26 -0700
commit74c257cc189dff497bf92d6652a95031011aa8f2 (patch)
tree9326d6503f33cf2b772337160d3604576e166c3e /sysif.c
parent6f2fc8ea8ee264361b0471f612922134aeee0f20 (diff)
downloadtxr-74c257cc189dff497bf92d6652a95031011aa8f2.tar.gz
txr-74c257cc189dff497bf92d6652a95031011aa8f2.tar.bz2
txr-74c257cc189dff497bf92d6652a95031011aa8f2.zip
Expose isatty function.
* sysif.c (isatty_wrap): New function. (sysif_init): Register isatty intrinsic. * txr.1: Documented.
Diffstat (limited to 'sysif.c')
-rw-r--r--sysif.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sysif.c b/sysif.c
index 4b8f8b29..518f145f 100644
--- a/sysif.c
+++ b/sysif.c
@@ -2128,6 +2128,26 @@ static val realpath_wrap(val path)
}
#endif
+#if HAVE_ISATTY
+static val isatty_wrap(val spec)
+{
+ val fdval;
+ val self = lit("isatty");
+
+ if (streamp(spec))
+ fdval = stream_get_prop(spec, fd_k);
+ else
+ fdval = spec;
+
+ if (fdval) {
+ int fd = c_int(fdval, self);
+ return if2(fd && isatty(fd) > 0, t);
+ }
+
+ return nil;
+}
+#endif
+
void sysif_init(void)
{
prot1(&at_exit_list);
@@ -2684,4 +2704,8 @@ void sysif_init(void)
#if HAVE_REALPATH
reg_fun(intern(lit("realpath"), user_package), func_n1(realpath_wrap));
#endif
+
+#if HAVE_ISATTY
+ reg_fun(intern(lit("isatty"), user_package), func_n1(isatty_wrap));
+#endif
}