summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--sysif.c24
-rw-r--r--txr.133
2 files changed, 57 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
}
diff --git a/txr.1 b/txr.1
index 20aee8d8..4b6e998c 100644
--- a/txr.1
+++ b/txr.1
@@ -60589,6 +60589,39 @@ only entries which polled positive. The
.code cdr
of every pair now holds a bitmask of the events which were to have occurred.
+.coNP Function @ isatty
+.synb
+.mets (isatty << stream )
+.mets (isatty << fileno )
+.syne
+.desc
+The
+.code isatty
+function provides access to the underlying POSIX function of the same name.
+
+If the argument is a
+.meta stream
+object which has a
+.code :fd
+property, then the file descriptor number is retrieved. The behavior is
+then as if that descriptor number were passed as the
+.meta fileno
+argument.
+
+If the argument is not a
+.metn stream ,
+it must be a
+.metn fileno :
+an integer in the representation range of the C type
+.codn int .
+
+The POSIX
+.code isatty
+is invoked on this integer. If it that returns 1, then
+.code t
+is returned, otherwise
+.codn nil .
+
.SS* Unix File Control
.coNP Variables @, o-accmode @, o-rdonly @, o-wronly @, o-rdwr @, o-creat @, o-noctty @, o-trunc @, o-append @, o-nonblock @, o-sync @, o-async @, o-directory @, o-nofollow @, o-cloexec @, o-direct @ o-noatime and @ o-path