mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-25 13:13:07 +00:00
Return errno from lfs.mkdir on error
Change pushresult() to return true on success. Change make_link to keep returning 0.
This commit is contained in:
43
src/lfs.c
43
src/lfs.c
@@ -133,6 +133,13 @@ typedef struct dir_data {
|
|||||||
#define LSTAT_FUNC lstat
|
#define LSTAT_FUNC lstat
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define lfs_mkdir _mkdir
|
||||||
|
#else
|
||||||
|
#define lfs_mkdir(path) (mkdir((path), \
|
||||||
|
S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Utility functions
|
** Utility functions
|
||||||
*/
|
*/
|
||||||
@@ -147,13 +154,14 @@ static int pusherror(lua_State *L, const char *info)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pushresult(lua_State *L, int i, const char *info)
|
static int pushresult(lua_State *L, int res, const char *info) {
|
||||||
{
|
if (res == -1) {
|
||||||
if (i==-1)
|
|
||||||
return pusherror(L, info);
|
return pusherror(L, info);
|
||||||
lua_pushinteger(L, i);
|
} else {
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -417,13 +425,17 @@ static int file_unlock (lua_State *L) {
|
|||||||
** @param #2 Name of link.
|
** @param #2 Name of link.
|
||||||
** @param #3 True if link is symbolic (optional).
|
** @param #3 True if link is symbolic (optional).
|
||||||
*/
|
*/
|
||||||
static int make_link(lua_State *L)
|
static int make_link (lua_State *L) {
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
const char *oldpath = luaL_checkstring(L, 1);
|
const char *oldpath = luaL_checkstring(L, 1);
|
||||||
const char *newpath = luaL_checkstring(L, 2);
|
const char *newpath = luaL_checkstring(L, 2);
|
||||||
return pushresult(L,
|
int res = (lua_toboolean(L,3) ? symlink : link)(oldpath, newpath);
|
||||||
(lua_toboolean(L,3) ? symlink : link)(oldpath, newpath), NULL);
|
if (res == -1) {
|
||||||
|
return pusherror(L, NULL);
|
||||||
|
} else {
|
||||||
|
lua_pushinteger(L, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
errno = ENOSYS; /* = "Function not implemented" */
|
errno = ENOSYS; /* = "Function not implemented" */
|
||||||
return pushresult(L, -1, "make_link is not supported on Windows");
|
return pushresult(L, -1, "make_link is not supported on Windows");
|
||||||
@@ -437,20 +449,7 @@ static int make_link(lua_State *L)
|
|||||||
*/
|
*/
|
||||||
static int make_dir (lua_State *L) {
|
static int make_dir (lua_State *L) {
|
||||||
const char *path = luaL_checkstring(L, 1);
|
const char *path = luaL_checkstring(L, 1);
|
||||||
int fail;
|
return pushresult(L, lfs_mkdir(path), NULL);
|
||||||
#ifdef _WIN32
|
|
||||||
fail = _mkdir (path);
|
|
||||||
#else
|
|
||||||
fail = mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
|
|
||||||
S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
|
|
||||||
#endif
|
|
||||||
if (fail) {
|
|
||||||
lua_pushnil (L);
|
|
||||||
lua_pushfstring (L, "%s", strerror(errno));
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
lua_pushboolean (L, 1);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user