Commit d4ae67d0 authored by jfollas's avatar jfollas
Browse files

Changed filename length error handling per TerryE's suggestion

parent 44786a22
...@@ -20,8 +20,8 @@ static int file_open( lua_State* L ) ...@@ -20,8 +20,8 @@ static int file_open( lua_State* L )
} }
const char *fname = luaL_checklstring( L, 1, &len ); const char *fname = luaL_checklstring( L, 1, &len );
if( len > FS_NAME_MAX_LENGTH ) luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
return luaL_error(L, "filename too long");
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
file_fd = fs_open(fname, fs_mode2flag(mode)); file_fd = fs_open(fname, fs_mode2flag(mode));
...@@ -118,9 +118,8 @@ static int file_seek (lua_State *L) ...@@ -118,9 +118,8 @@ static int file_seek (lua_State *L)
static int file_exists( lua_State* L ) static int file_exists( lua_State* L )
{ {
size_t len; size_t len;
const char *fname = luaL_checklstring( L, 1, &len ); const char *fname = luaL_checklstring( L, 1, &len );
if( len > FS_NAME_MAX_LENGTH ) luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
return luaL_error(L, "filename too long");
spiffs_stat stat; spiffs_stat stat;
int rc = SPIFFS_stat(&fs, (char *)fname, &stat); int rc = SPIFFS_stat(&fs, (char *)fname, &stat);
...@@ -134,9 +133,8 @@ static int file_exists( lua_State* L ) ...@@ -134,9 +133,8 @@ static int file_exists( lua_State* L )
static int file_remove( lua_State* L ) static int file_remove( lua_State* L )
{ {
size_t len; size_t len;
const char *fname = luaL_checklstring( L, 1, &len ); const char *fname = luaL_checklstring( L, 1, &len );
if( len > FS_NAME_MAX_LENGTH ) luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
return luaL_error(L, "filename too long");
file_close(L); file_close(L);
SPIFFS_remove(&fs, (char *)fname); SPIFFS_remove(&fs, (char *)fname);
return 0; return 0;
...@@ -173,12 +171,10 @@ static int file_rename( lua_State* L ) ...@@ -173,12 +171,10 @@ static int file_rename( lua_State* L )
} }
const char *oldname = luaL_checklstring( L, 1, &len ); const char *oldname = luaL_checklstring( L, 1, &len );
if( len > FS_NAME_MAX_LENGTH ) luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
return luaL_error(L, "filename too long");
const char *newname = luaL_checklstring( L, 2, &len );
const char *newname = luaL_checklstring( L, 2, &len ); luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 2, "filename too long");
if( len > FS_NAME_MAX_LENGTH )
return luaL_error(L, "filename too long");
if(SPIFFS_OK==myspiffs_rename( oldname, newname )){ if(SPIFFS_OK==myspiffs_rename( oldname, newname )){
lua_pushboolean(L, 1); lua_pushboolean(L, 1);
...@@ -325,7 +321,6 @@ static const LUA_REG_TYPE file_map[] = { ...@@ -325,7 +321,6 @@ static const LUA_REG_TYPE file_map[] = {
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) }, { LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) }, { LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
{ LSTRKEY( "flush" ), LFUNCVAL( file_flush ) }, { LSTRKEY( "flush" ), LFUNCVAL( file_flush ) },
//{ LSTRKEY( "check" ), LFUNCVAL( file_check ) },
{ LSTRKEY( "rename" ), LFUNCVAL( file_rename ) }, { LSTRKEY( "rename" ), LFUNCVAL( file_rename ) },
{ LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) }, { LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) },
{ LSTRKEY( "exists" ), LFUNCVAL( file_exists ) }, { LSTRKEY( "exists" ), LFUNCVAL( file_exists ) },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment