summaryrefslogtreecommitdiff
path: root/luxio.c
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2018-10-12 18:10:54 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-10-21 13:39:56 +0100
commit80bbeba5ca28d9901fa1b66ae4cb08ba58018bb8 (patch)
tree054b30adb69ad166089ef8bff63c4b67d8c272f3 /luxio.c
parent301de4c825ae109cc3a7c780d662863ada62753b (diff)
downloadluxio-80bbeba5ca28d9901fa1b66ae4cb08ba58018bb8.tar.bz2
Bind creat(2)
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 },