aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/pposix.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-07-04 15:11:07 +0200
committerKim Alvefur <zash@zash.se>2021-07-04 15:11:07 +0200
commitb93398ce799df5c165163c96e91d6a8205f0a83c (patch)
treedddb5a0bd6c133f2b81c9c6210e50bad10c39e31 /util-src/pposix.c
parent6f60a98b166796f0be7515ec8636027972e34f92 (diff)
downloadprosody-b93398ce799df5c165163c96e91d6a8205f0a83c.tar.gz
prosody-b93398ce799df5c165163c96e91d6a8205f0a83c.zip
util.pposix: Bind isatty(3)
Useful for disabling certain behavior, ANSI colors etc when not connected to a terminal.
Diffstat (limited to 'util-src/pposix.c')
-rw-r--r--util-src/pposix.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c
index 856905b0..87be7e9a 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -812,6 +812,13 @@ static int lc_atomic_append(lua_State *L) {
return 3;
}
+static int lc_isatty(lua_State *L) {
+ FILE *f = *(FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE);
+ const int fd = fileno(f);
+ lua_pushboolean(L, isatty(fd));
+ return 1;
+}
+
/* Register functions */
int luaopen_util_pposix(lua_State *L) {
@@ -853,6 +860,8 @@ int luaopen_util_pposix(lua_State *L) {
{ "atomic_append", lc_atomic_append },
+ { "isatty", lc_isatty },
+
{ NULL, NULL }
};