]> git.e2factory.org Git - e2factory.git/commitdiff
Add chmod function
authorTobias Ulmer <tu@emlix.com>
Tue, 8 Oct 2013 12:25:40 +0000 (14:25 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:01:23 +0000 (15:01 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/le2lib.c

index 5a76abdcbd07477b260e42ae2cef1a7d3170ae42..0d958e50eabf8eeb4519ed5488440835a8b2e8f5 100644 (file)
@@ -738,6 +738,22 @@ do_uname_machine(lua_State *lua)
        return 1;
 }
 
+static int
+do_chmod(lua_State *L)
+{
+       const char *path = luaL_checkstring(L, 1);
+       mode_t mode = luaL_checkinteger(L, 2);
+
+       if (chmod(path, mode) != 0) {
+               lua_pushboolean(L, 0);
+               lua_pushstring(L, strerror(errno));
+
+               return 2;
+       }
+
+       lua_pushboolean(L, 1);
+       return 1;
+}
 
 /*
  * Hook that gets called once an interrupt has been requested.
@@ -780,6 +796,7 @@ laction(int i) {
 
 static luaL_Reg lib[] = {
        { "chdir", change_directory },
+       { "chmod", do_chmod },
        { "closefrom", closefrom },
        { "cwd", get_working_directory },
        { "directory", get_directory },