From 4e95fbccfbbec3c1ebc10dc156a154a2953200dd Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 12 Oct 2018 18:10:52 +0100 Subject: Bind termident functions --- luxio.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'luxio.c') diff --git a/luxio.c b/luxio.c index 7016385..6507a00 100644 --- a/luxio.c +++ b/luxio.c @@ -980,8 +980,34 @@ luxio_unsetenv(lua_State *L) /* POSIX.1-2001 */ /* 4.7 Terminal identification ***********************************************/ -/* TODO: ctermid() 4.7.1 */ -/* TODO: ttyname(), ttyname_r(), isatty() 4.7.2 */ +static int +luxio_ctermid(lua_State *L) +{ + lua_pushstring(L, ctermid(NULL)); + return 1; +} + +static int +luxio_ttyname(lua_State *L) +{ + int fd = luaL_checkinteger(L, 1); + + lua_pushstring(L, ttyname(fd)); + lua_pushinteger(L, errno); + + return 2; +} + +static int +luxio_isatty(lua_State *L) +{ + int fd = luaL_checkinteger(L, 1); + + lua_pushboolean(L, isatty(fd)); + lua_pushinteger(L, errno); + + return 2; +} /* 4.8 Configurable system variables *****************************************/ @@ -4557,11 +4583,15 @@ luxio_functions[] = { { "iconv_open", luxio_iconv_open }, { "iconv_close", luxio_iconv_close }, { "iconv", luxio_iconv }, - + #if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L { "posix_fadvise", luxio_posix_fadvise }, #endif + { "ctermid", luxio_ctermid }, + { "ttyname", luxio_ttyname }, + { "isatty", luxio_isatty }, + { NULL, NULL } }; -- cgit v1.2.1