diff options
-rw-r--r-- | sysif.c | 24 | ||||
-rw-r--r-- | txr.1 | 33 |
2 files changed, 57 insertions, 0 deletions
@@ -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 } @@ -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 |