summaryrefslogtreecommitdiff
path: root/luxio.c
diff options
context:
space:
mode:
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 }
};