diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-22 11:49:05 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2013-01-22 13:16:36 +0100 |
commit | 4c264373c100af4cf9f3c350ad923d47135bb5c5 (patch) | |
tree | 5670216bde292aa39cc55f607a0a17c582e745de /lem/io/unix.c | |
parent | 4e417a67f146f79bafccacb79e58ed15e6d96177 (diff) | |
download | lem-4c264373c100af4cf9f3c350ad923d47135bb5c5.tar.gz lem-4c264373c100af4cf9f3c350ad923d47135bb5c5.tar.xz lem-4c264373c100af4cf9f3c350ad923d47135bb5c5.zip |
io: add optional 3rd permission arg to io.open()
Diffstat (limited to 'lem/io/unix.c')
-rw-r--r-- | lem/io/unix.c | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/lem/io/unix.c b/lem/io/unix.c index b860a17..25e1b00 100644 --- a/lem/io/unix.c +++ b/lem/io/unix.c @@ -224,41 +224,21 @@ unix_listen(lua_State *T) { size_t len; const char *path = luaL_checklstring(T, 1, &len); - int mode = (int)luaL_optnumber(T, 2, -1); + int perm = io_optperm(T, 2); int backlog = (int)luaL_optnumber(T, 3, MAXPENDING); struct unix_create *u; if (len >= UNIX_PATH_MAX) return luaL_argerror(T, 1, "path too long"); - if (mode != -1) { - int octal = 0; - int i; - - for (i = 1; i <= 64; i *= 8) { - int digit = mode % 10; - if (digit > 7) - goto mode_error; - - octal += digit * i; - mode /= 10; - } - if (mode != 0) - goto mode_error; - - mode = octal; - } - u = lem_xmalloc(sizeof(struct unix_create)); u->path = path; u->len = len; - u->sock = mode; + u->sock = perm; u->err = backlog; lem_async_do(&u->a, T, unix_listen_work, unix_listen_reap); lua_settop(T, 1); lua_pushvalue(T, lua_upvalueindex(1)); return lua_yield(T, 2); -mode_error: - return luaL_argerror(T, 2, "invalid mode"); } |