summaryrefslogtreecommitdiff
path: root/luxio.c
diff options
context:
space:
mode:
Diffstat (limited to 'luxio.c')
-rw-r--r--luxio.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/luxio.c b/luxio.c
index 0e418ec..acf8e54 100644
--- a/luxio.c
+++ b/luxio.c
@@ -898,6 +898,43 @@ luxio_link(lua_State *L) /* 5.3.4 */
return 2;
}
+/**% symlink
+ * retval = symlink(oldpath, newpath);
+ * retval, errno = symlink(oldpath, newpath)
+ */
+static int
+luxio_symlink(lua_State *L) /* POSIX.1-2001, Unknown location */
+{
+ const char *oldpath = luaL_checkstring(L, 1);
+ const char *newpath = luaL_checkstring(L, 2);
+
+ lua_pushinteger(L, symlink(oldpath, newpath));
+ lua_pushinteger(L, errno);
+
+ return 2;
+}
+
+/**% readlink
+ * retval, target = readlink(path)
+ * retval, errno = readlink(path)
+ */
+static int
+luxio_readlink(lua_State *L) /* POSIX.1-2001, Unknown location */
+{
+ char buffer[PATH_MAX];
+ ssize_t ret;
+ const char *path = luaL_checkstring(L, 1);
+
+ lua_pushinteger(L, (ret = readlink(path, buffer, PATH_MAX)));
+ if (ret > 0) {
+ lua_pushinteger(L, errno);
+ } else {
+ lua_pushstring(L, buffer);
+ }
+
+ return 2;
+}
+
/**# Special file creation ***************************************************/
/**% mkdir
@@ -2936,6 +2973,8 @@ luxio_functions[] = {
{ "rename", luxio_rename },
{ "link", luxio_link },
{ "unlink", luxio_unlink },
+ { "symlink", luxio_symlink },
+ { "readlink", luxio_readlink },
#ifdef HAVE_SENDFILE
{ "sendfile", luxio_sendfile },
#endif