From 121ae680f1c897d8773041781a6a7bd0c85010fc Mon Sep 17 00:00:00 2001 From: tomas Date: Tue, 14 Mar 2006 13:39:38 +0000 Subject: [PATCH] Standardizing execution errors to nil followed by an error message --- src/lfs.c | 12 +++++++----- tests/test.lua | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lfs.c b/src/lfs.c index 18fff62..7c8f62a 100644 --- a/src/lfs.c +++ b/src/lfs.c @@ -14,7 +14,7 @@ ** lfs.touch (filepath [, atime [, mtime]]) ** lfs.unlock (fh) ** -** $Id: lfs.c,v 1.31 2006/03/13 00:06:24 tomas Exp $ +** $Id: lfs.c,v 1.32 2006/03/14 13:39:38 tomas Exp $ */ #include @@ -182,7 +182,7 @@ static int file_lock (lua_State *L) { lua_pushboolean (L, 1); return 1; } else { - lua_pushboolean (L, 0); + lua_pushnil (L); lua_pushfstring (L, "%s", strerror(errno)); return 2; } @@ -203,7 +203,7 @@ static int file_unlock (lua_State *L) { lua_pushboolean (L, 1); return 1; } else { - lua_pushboolean (L, 0); + lua_pushnil (L); lua_pushfstring (L, "%s", strerror(errno)); return 2; } @@ -221,12 +221,13 @@ static int make_dir (lua_State *L) { fail = mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH ); #endif - lua_pushboolean (L, !fail); if (fail) { + lua_pushnil (L); lua_pushfstring (L, "%s", strerror(errno)); return 2; } umask (oldmask); + lua_pushboolean (L, 1); return 1; } @@ -240,11 +241,12 @@ static int remove_dir (lua_State *L) { fail = rmdir (path); - lua_pushboolean (L, !fail); if (fail) { + lua_pushnil (L); lua_pushfstring (L, "%s", strerror(errno)); return 2; } + lua_pushboolean (L, 1); return 1; } diff --git a/tests/test.lua b/tests/test.lua index 1f4eb09..8da5d16 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -64,7 +64,7 @@ assert (new_att.modification == attrib.modification) -- Remove new file and directory assert (os.remove (tmpfile), "could not remove new file") assert (lfs.rmdir (tmpdir), "could not remove new directory") -assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == false, "could create a directory inside a non-existent one") +assert (lfs.mkdir (tmpdir..sep.."lfs_tmp_dir") == nil, "could create a directory inside a non-existent one") -- Trying to get attributes of a non-existent file assert (lfs.attributes ("this couldn't be an actual file") == nil, "could get attributes of a non-existent file")