diff options
author | Richard Ipsum <richardipsum@fastmail.co.uk> | 2018-10-16 22:27:53 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2018-10-21 13:30:54 +0100 |
commit | d56bd1b8d20073f4d3f7849d8dada28af0a7e2ed (patch) | |
tree | 547034eaa7d09e22e7b6555e95038d03b9e36e2a | |
parent | 5cdba362a763b046a14a3a23f2f59d4cb803f16a (diff) | |
download | luxio-d56bd1b8d20073f4d3f7849d8dada28af0a7e2ed.tar.gz |
Bind access(2)
-rw-r--r-- | luxio.c | 13 | ||||
-rw-r--r-- | luxio_constants.inc.in | 6 | ||||
-rw-r--r-- | tests/test-access.lua | 34 |
3 files changed, 52 insertions, 1 deletions
@@ -1727,7 +1727,17 @@ STAT_IS(SOCK) #undef STAT_IS -/* TODO: access() 5.6.3 */ +static int +luxio_access(lua_State *L) +{ + const char *path = luaL_checkstring(L, 1); + mode_t mode = luaL_checkinteger(L, 2); + + lua_pushinteger(L, access(path, mode)); + lua_pushinteger(L, errno); + + return 2; +} /*** Change permissions of a file. @tparam string path @@ -4418,6 +4428,7 @@ luxio_functions[] = { { "stat", luxio_stat }, { "lstat", luxio_lstat }, { "fstat", luxio_fstat }, + { "access", luxio_access }, { "socket", luxio_socket }, { "listen", luxio_listen }, diff --git a/luxio_constants.inc.in b/luxio_constants.inc.in index 4c4a3dd..d96ee67 100644 --- a/luxio_constants.inc.in +++ b/luxio_constants.inc.in @@ -89,6 +89,12 @@ static const struct { E(S_IFCHR), E(S_IFIFO), + /* access constants */ + E(F_OK), + E(R_OK), + E(W_OK), + E(X_OK), + /* fcntl commands */ E(F_GETFD), E(F_SETFD), E(F_GETFL), E(F_SETFL), E(F_DUPFD), ? E(F_DUPFD_CLOEXEC), diff --git a/tests/test-access.lua b/tests/test-access.lua new file mode 100644 index 0000000..cbdacb2 --- /dev/null +++ b/tests/test-access.lua @@ -0,0 +1,34 @@ +local l = require "luxio" +local sio = require "luxio.simple" + +local path = "ENOENTpath" + +local r, errno = l.access(path, l.F_OK) +if r == -1 then + io.stderr:write(("%s does not exist (PASS)\n"):format(path)) +end + +path = "luxio-test-access-test-file" + +local r, errno = l.open(path, l.O_CREAT, sio.tomode("-rw-r--r--")) +if r == -1 then + io.stderr:write(("open: %s (FAIL)\n"):format(l.strerror(errno))) + os.exit(l.EXIT_FAILURE) +end + +local r, errno = l.access(path, l.bit.bor(l.R_OK, l.W_OK)) + +if r == -1 then + io.stderr:write(("access: %s (FAIL)\n"):format(l.strerror(errno))) + os.exit(l.EXIT_FAILURE) +end + +print(("Running user has read and write access to %s (PASS)"):format(path)) + +local r, errno = l.access(path, l.bit.bor(l.X_OK)) +if r == 0 then + io.stderr:write("Running user should not have execute perms") + os.exit(l.EXIT_FAILURE) +end + +print(("Running does not have execute access to %s (PASS)"):format(path)) |