aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2016-04-25 16:56:26 -0300
committerHisham Muhammad <hisham@gobolinux.org>2016-04-25 16:56:26 -0300
commit436bc441fa34a086adfae776941e6e7c111a4582 (patch)
tree7e7d312bdc896ec440e4f38a59cef07ddf7c6e13
parente519c13036066efedbf8e8afbe78a579a75364fc (diff)
parentc1e9c70214f9731b32a9ed713963e0326d167aa0 (diff)
downloadluafilesystem-436bc441fa34a086adfae776941e6e7c111a4582.tar.gz
luafilesystem-436bc441fa34a086adfae776941e6e7c111a4582.tar.bz2
luafilesystem-436bc441fa34a086adfae776941e6e7c111a4582.zip
Merge pull request #68 from mpeterv/setmode-refactor
Minor refactoring of setmode
-rw-r--r--src/lfs.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/lfs.c b/src/lfs.c
index 866740f..159ca59 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -117,10 +117,10 @@ typedef struct dir_data {
117 117
118#ifdef _WIN32 118#ifdef _WIN32
119 #ifdef __BORLANDC__ 119 #ifdef __BORLANDC__
120 #define lfs_setmode(L,file,m) ((void)L, setmode(_fileno(file), m)) 120 #define lfs_setmode(file, m) (setmode(_fileno(file), m))
121 #define STAT_STRUCT struct stati64 121 #define STAT_STRUCT struct stati64
122 #else 122 #else
123 #define lfs_setmode(L,file,m) ((void)L, _setmode(_fileno(file), m)) 123 #define lfs_setmode(file, m) (_setmode(_fileno(file), m))
124 #define STAT_STRUCT struct _stati64 124 #define STAT_STRUCT struct _stati64
125 #endif 125 #endif
126#define STAT_FUNC _stati64 126#define STAT_FUNC _stati64
@@ -128,7 +128,7 @@ typedef struct dir_data {
128#else 128#else
129#define _O_TEXT 0 129#define _O_TEXT 0
130#define _O_BINARY 0 130#define _O_BINARY 0
131#define lfs_setmode(L,file,m) ((void)L, (void)file, (void)m, 0) 131#define lfs_setmode(file, m) ((void)file, (void)m, 0)
132#define STAT_STRUCT struct stat 132#define STAT_STRUCT struct stat
133#define STAT_FUNC stat 133#define STAT_FUNC stat
134#define LSTAT_FUNC lstat 134#define LSTAT_FUNC lstat
@@ -347,25 +347,20 @@ static int lfs_g_setmode (lua_State *L, FILE *f, int arg) {
347 static const int mode[] = {_O_BINARY, _O_TEXT}; 347 static const int mode[] = {_O_BINARY, _O_TEXT};
348 static const char *const modenames[] = {"binary", "text", NULL}; 348 static const char *const modenames[] = {"binary", "text", NULL};
349 int op = luaL_checkoption(L, arg, NULL, modenames); 349 int op = luaL_checkoption(L, arg, NULL, modenames);
350 int res = lfs_setmode(L, f, mode[op]); 350 int res = lfs_setmode(f, mode[op]);
351 if (res != -1) { 351 if (res != -1) {
352 int i; 352 int i;
353 lua_pushboolean(L, 1); 353 lua_pushboolean(L, 1);
354 for (i = 0; modenames[i] != NULL; i++) { 354 for (i = 0; modenames[i] != NULL; i++) {
355 if (mode[i] == res) { 355 if (mode[i] == res) {
356 lua_pushstring(L, modenames[i]); 356 lua_pushstring(L, modenames[i]);
357 goto exit; 357 return 2;
358 } 358 }
359 } 359 }
360 lua_pushnil(L); 360 lua_pushnil(L);
361 exit:
362 return 2; 361 return 2;
363 } else { 362 } else {
364 int en = errno; 363 return pusherror(L, NULL);
365 lua_pushnil(L);
366 lua_pushfstring(L, "%s", strerror(en));
367 lua_pushinteger(L, en);
368 return 3;
369 } 364 }
370} 365}
371 366