summaryrefslogtreecommitdiff
path: root/luxio.c
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2018-10-12 18:10:52 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-10-21 13:39:31 +0100
commit4e95fbccfbbec3c1ebc10dc156a154a2953200dd (patch)
tree825e257955beae7640e280a02098a423fbc3bacf /luxio.c
parent6cdd1f9a9f10ae7fb63441341727a367ca4c5475 (diff)
downloadluxio-4e95fbccfbbec3c1ebc10dc156a154a2953200dd.tar.bz2
Bind termident functions
Diffstat (limited to 'luxio.c')
-rw-r--r--luxio.c36
1 files changed, 33 insertions, 3 deletions
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 }
};