summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2016-01-15 15:20:41 +0100
committerJo-Philipp Wich <jow@openwrt.org>2016-01-15 15:20:41 +0100
commitad064f0b039839dd333bfe8e9631cbc5218410b0 (patch)
treec13911127dbab695710aa784b54b22e794f1a43c /libs
parent1a7b0b22a85d8294d7a2c196b708266c872dd054 (diff)
parentb130ca554f13e17c787a1c6fd09e67dd7727a4d3 (diff)
Merge pull request #563 from cshore/pull-request-app-uhttpd
Pull request app uhttpd
Diffstat (limited to 'libs')
-rw-r--r--libs/luci-lib-nixio/src/file.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libs/luci-lib-nixio/src/file.c b/libs/luci-lib-nixio/src/file.c
index b86e040e1..cfa35dfd1 100644
--- a/libs/luci-lib-nixio/src/file.c
+++ b/libs/luci-lib-nixio/src/file.c
@@ -79,6 +79,38 @@ static int nixio_open(lua_State *L) {
return 1;
}
+static int nixio_mkstemp(lua_State *L) {
+ const char *intemplate = luaL_checklstring(L, 1, NULL);
+ size_t len = lua_strlen(L, 1);
+ char *template = (char *)lua_newuserdata(L, 13 + len);
+ if (!template) {
+ return luaL_error(L, "out of memory");
+ }
+ snprintf(template, 13 + len, "/tmp/%s.XXXXXX", intemplate);
+
+ int fd;
+
+ do {
+ fd = mkstemp(template);
+ } while (fd == -1 && errno == EINTR);
+ if (fd == -1) {
+ return nixio__perror(L);
+ }
+ unlink(template);
+
+ int *udata = lua_newuserdata(L, sizeof(int));
+ if (!udata) {
+ return luaL_error(L, "out of memory");
+ }
+
+ *udata = fd;
+
+ luaL_getmetatable(L, NIXIO_FILE_META);
+ lua_setmetatable(L, -2);
+
+ return 1;
+}
+
static int nixio_open_flags(lua_State *L) {
int mode = 0;
const int j = lua_gettop(L);
@@ -366,6 +398,7 @@ static const luaL_reg R[] = {
{"dup", nixio_dup},
{"open", nixio_open},
{"open_flags", nixio_open_flags},
+ {"mkstemp", nixio_mkstemp},
{"pipe", nixio_pipe},
{NULL, NULL}
};