From eb9e6d3c802e628ad28dd0bfb3c108a663fc702d Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 11 Mar 2016 18:07:40 +0100 Subject: [PATCH] Fixes #3342 --- radio/src/targets/simu/simpgmspace.cpp | 11 ++++++----- radio/src/thirdparty/Lua/src/liolib.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 945d4a5be..7d0a29217 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -18,7 +18,7 @@ * GNU General Public License for more details. */ -#include "../../opentx.h" +#include "opentx.h" #include #include #include @@ -386,7 +386,7 @@ void StopSimu() { main_thread_running = 0; #if !defined(CPUARM) - pthread_join(main_thread_pid, NULL); + pthread_join(main_thread_pid, NULL); #endif } @@ -771,12 +771,13 @@ FRESULT f_mount (FATFS* ,const TCHAR*, BYTE opt) FRESULT f_open (FIL * fil, const TCHAR *name, BYTE flag) { - char *path = convertSimuPath(name); + char * path = convertSimuPath(name); char * realPath = findTrueFileName(path); + fil->fs = 0; if (!(flag & FA_WRITE)) { struct stat tmp; if (stat(realPath, &tmp)) { - TRACE("f_open(%s) = INVALID_NAME", path); + TRACE("f_open(%s) = INVALID_NAME (FIL %p)", path, fil); return FR_INVALID_NAME; } fil->fsize = tmp.st_size; @@ -788,7 +789,7 @@ FRESULT f_open (FIL * fil, const TCHAR *name, BYTE flag) TRACE("f_open(%s, %x) = %p (FIL %p)", path, flag, fil->fs, fil); return FR_OK; } - TRACE("f_open(%s) = error %d (%s)", path, errno, strerror(errno)); + TRACE("f_open(%s) = error %d (%s) (FIL %p)", path, errno, strerror(errno), fil); return FR_INVALID_NAME; } diff --git a/radio/src/thirdparty/Lua/src/liolib.c b/radio/src/thirdparty/Lua/src/liolib.c index 2bdb89ebf..33545a968 100644 --- a/radio/src/thirdparty/Lua/src/liolib.c +++ b/radio/src/thirdparty/Lua/src/liolib.c @@ -253,9 +253,14 @@ static int io_open (lua_State *L) { else if (*md == 'a') mode = FA_WRITE | FA_OPEN_ALWAYS; // always open file (create it if necessary) FRESULT result = f_open(&p->f, filename, mode); - if (result == FR_OK && *md == 'a') - result = f_lseek(&p->f, f_size(&p->f)); // seek to the end of the file - return result == FR_OK ? 1 : 0; + if (result == FR_OK) { + if (*md == 'a') + f_lseek(&p->f, f_size(&p->f)); // seek to the end of the file + return 1; + } + else { + return luaL_fileresult(L, 0, filename); + } #else const char *mode = md; /* to traverse/check mode */ luaL_argcheck(L, lua_checkmode(mode), 2, "invalid mode");