From d056382b5c00d1f618f5beb07fc460ef4178b7e1 Mon Sep 17 00:00:00 2001 From: Lorenzo Cogotti Date: Thu, 15 Dec 2022 19:34:49 +0100 Subject: [PATCH] [osx] Add isatty(). --- osx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osx.c b/osx.c index c3c24de..d3f7723 100644 --- a/osx.c +++ b/osx.c @@ -84,6 +84,7 @@ static int truncate(const char *path, __int64 size) } #define ftruncate(fd, size) _chsize_s(fd, size) +#define isatty(fd) _isatty(fd) #define fsync(fd) _commit(fd) static int flocking(FILE *fh, int mode, __int64 ofs, __int64 len) @@ -801,6 +802,15 @@ static int os_fadvise(lua_State *L) return os_result(L, ec, NULL); } +static int os_isatty(lua_State *L) +{ + luaL_Stream *stream = luaL_checkudata(L, 1, LUA_FILEHANDLE); + + int ec = isatty(fileno(stream->f)); + lua_pushboolean(L, ec != 0); + return 1; +} + /** * Commit any pending write to disk. * @@ -935,6 +945,7 @@ DF_OSXMOD_API int luaopen_osx(lua_State *L) { "setmode", os_setmode }, { "chsize", os_chsize }, { "fadvise", os_fadvise }, + { "isatty", os_isatty }, { "commit", os_commit }, { "locking", os_locking }, { NULL, NULL }