/* * fs.unlink */ static int fs_unlink(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); FSR__SET_OPT_CB(2, on_fs_callback) uv_fs_unlink(loop, req, path, cb); FSR__TEARDOWN }
/* * fs.fstat */ static int fs_fstat(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); FSR__SET_OPT_CB(2, on_fs_callback) uv_fs_fstat(loop, req, fd, cb); FSR__TEARDOWN }
/* * fs.rename */ static int fs_rename(lua_State* L) { FSR__SETUP const char *old_path = luaL_checkstring(L, 1); const char *new_path = luaL_checkstring(L, 2); FSR__SET_OPT_CB(3, on_fs_callback) uv_fs_rename(loop, req, old_path, new_path, cb); FSR__TEARDOWN }
/* * fs.ftruncate */ static int fs_ftruncate(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); int64_t file_size = luaL_checklong(L, 2); FSR__SET_OPT_CB(3, on_fs_callback) uv_fs_ftruncate(loop, req, fd, file_size, cb); FSR__TEARDOWN }
/* * fs.utime */ static int fs_utime(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); lua_Number atime = luaL_checknumber(L, 2); lua_Number mtime = luaL_checknumber(L, 3); FSR__SET_OPT_CB(4, on_fs_callback) uv_fs_utime(loop, req, path, atime, mtime, cb); FSR__TEARDOWN }
/* * fs.futime */ static int fs_futime(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); lua_Number atime = luaL_checknumber(L, 2); lua_Number mtime = luaL_checknumber(L, 3); FSR__SET_OPT_CB(4, on_fs_callback) uv_fs_futime(loop, req, fd, atime, mtime, cb); FSR__TEARDOWN }
/* * fs.mkdir */ static int fs_mkdir(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); const char *mode_str = luaL_optstring(L, 2, "0777"); int mode = strtol(mode_str, (char**) NULL, 8); FSR__SET_OPT_CB(3, on_fs_callback) uv_fs_mkdir(loop, req, path, mode, cb); FSR__TEARDOWN }
/* * fs.fchown */ static int fs_fchown(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); int uid = luaL_checkint(L, 2); int gid = luaL_checkint(L, 3); FSR__SET_OPT_CB(4, on_fs_callback) uv_fs_fchown(loop, req, fd, uid, gid, cb); FSR__TEARDOWN }
/* * fs.fchmod */ static int fs_fchmod(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); const char *mode_str = luaL_checkstring(L, 2); int mode = strtol(mode_str, (char**) NULL, 8); FSR__SET_OPT_CB(3, on_fs_callback) uv_fs_fchmod(loop, req, fd, mode, cb); FSR__TEARDOWN }
/* * fs.chown */ static int fs_chown(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); int uid = luaL_checkint(L, 2); int gid = luaL_checkint(L, 3); FSR__SET_OPT_CB(4, on_fs_callback) uv_fs_chown(loop, req, path, uid, gid, cb); FSR__TEARDOWN }
/* * fs.open */ static int fs_open(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); int flags = fs_checkflags(L, 2); const char *mode_str = luaL_optstring(L, 3, "0666"); int mode = strtol(mode_str, (char**) NULL, 8); FSR__SET_OPT_CB(4, on_fs_callback) uv_fs_open(loop, req, path, flags, mode, cb); FSR__TEARDOWN }
static int fs_exists(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); FSR__SET_OPT_CB(2, on_exists_callback) uv_fs_stat(loop, req, path, cb); lua_pushboolean(L, req->result != -1); if (!cb) { uv_fs_req_cleanup(req); } /* NOTE: remove "object" */ lua_remove(L, 1); return 1; }
/* * fs.read */ static int fs_read(lua_State* L) { FSR__SETUP int fd = luaL_checkint(L, 1); MemSlice *ms = lev_checkbuffer(L, 2); int64_t file_pos = luaL_optlong(L, 3, 0); file_pos--; /* Luaisms */ size_t file_until = luaL_optlong(L, 4, 0); if (file_until > ms->until) { file_until = ms->until; } FSR__SET_OPT_CB(5, on_fs_callback) uv_fs_read(loop, req, fd, ms->slice, (file_until ? file_until : ms->until), file_pos, cb); FSR__TEARDOWN }
static int fs_exists(lua_State* L) { FSR__SETUP const char *path = luaL_checkstring(L, 1); FSR__SET_OPT_CB(2, on_exists_callback) uv_fs_stat(loop, req, path, cb); /* NOTE: remove "object" */ lua_remove(L, 1); if (LUA_NOREF != holder->threadref) { /* we're in coroutine land */ return lua_yield(L, 0); } else {/* no coroutines */ if (!cb) { uv_fs_req_cleanup(req); } lua_pushboolean(L, req->result != -1); return 1; } return 0; /* unreachable */ }