summaryrefslogtreecommitdiff
path: root/luxio.c
diff options
context:
space:
mode:
Diffstat (limited to 'luxio.c')
-rw-r--r--luxio.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/luxio.c b/luxio.c
index 97323f1..e952c47 100644
--- a/luxio.c
+++ b/luxio.c
@@ -1365,7 +1365,28 @@ luxio_open(lua_State *L) /* 5.3.1 */
return 2;
}
-/* TODO: creat() 5.3.2 */
+/*** Create a file or device.
+
+Returns file descriptor on success. On error returns -1 with errno set
+appropriately.
+
+@tparam string path
+@tparam[opt] number mode, must be specified if creating.
+@treturn result File descriptor
+@treturn errno
+@function creat
+*/
+static int
+luxio_creat(lua_State *L)
+{
+ const char *pathname = luaL_checkstring(L, 1);
+ mode_t mode = luaL_optinteger(L, 2, 0);
+
+ lua_pushinteger(L, creat(pathname, mode));
+ lua_pushinteger(L, errno);
+
+ return 2;
+}
/*** Set file mode creation mask.
@tparam number mask
@@ -4406,6 +4427,7 @@ luxio_iconv(lua_State *L)
static const struct luaL_Reg
luxio_functions[] = {
{ "open", luxio_open },
+ { "creat", luxio_creat },
{ "close", luxio_close },
{ "read", luxio_read },
{ "write", luxio_write },