Changed filename length error handling per TerryE's suggestion
This commit is contained in:
parent
44786a22ff
commit
d4ae67d0b4
|
@ -20,8 +20,8 @@ static int file_open( lua_State* L )
|
|||
}
|
||||
|
||||
const char *fname = luaL_checklstring( L, 1, &len );
|
||||
if( len > FS_NAME_MAX_LENGTH )
|
||||
return luaL_error(L, "filename too long");
|
||||
luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
|
||||
|
||||
const char *mode = luaL_optstring(L, 2, "r");
|
||||
|
||||
file_fd = fs_open(fname, fs_mode2flag(mode));
|
||||
|
@ -118,9 +118,8 @@ static int file_seek (lua_State *L)
|
|||
static int file_exists( lua_State* L )
|
||||
{
|
||||
size_t len;
|
||||
const char *fname = luaL_checklstring( L, 1, &len );
|
||||
if( len > FS_NAME_MAX_LENGTH )
|
||||
return luaL_error(L, "filename too long");
|
||||
const char *fname = luaL_checklstring( L, 1, &len );
|
||||
luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
|
||||
|
||||
spiffs_stat stat;
|
||||
int rc = SPIFFS_stat(&fs, (char *)fname, &stat);
|
||||
|
@ -134,9 +133,8 @@ static int file_exists( lua_State* L )
|
|||
static int file_remove( lua_State* L )
|
||||
{
|
||||
size_t len;
|
||||
const char *fname = luaL_checklstring( L, 1, &len );
|
||||
if( len > FS_NAME_MAX_LENGTH )
|
||||
return luaL_error(L, "filename too long");
|
||||
const char *fname = luaL_checklstring( L, 1, &len );
|
||||
luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
|
||||
file_close(L);
|
||||
SPIFFS_remove(&fs, (char *)fname);
|
||||
return 0;
|
||||
|
@ -173,12 +171,10 @@ static int file_rename( lua_State* L )
|
|||
}
|
||||
|
||||
const char *oldname = luaL_checklstring( L, 1, &len );
|
||||
if( len > FS_NAME_MAX_LENGTH )
|
||||
return luaL_error(L, "filename too long");
|
||||
|
||||
const char *newname = luaL_checklstring( L, 2, &len );
|
||||
if( len > FS_NAME_MAX_LENGTH )
|
||||
return luaL_error(L, "filename too long");
|
||||
luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 1, "filename too long");
|
||||
|
||||
const char *newname = luaL_checklstring( L, 2, &len );
|
||||
luaL_argcheck(L, len <= FS_NAME_MAX_LENGTH, 2, "filename too long");
|
||||
|
||||
if(SPIFFS_OK==myspiffs_rename( oldname, newname )){
|
||||
lua_pushboolean(L, 1);
|
||||
|
@ -325,7 +321,6 @@ static const LUA_REG_TYPE file_map[] = {
|
|||
{ LSTRKEY( "remove" ), LFUNCVAL( file_remove ) },
|
||||
{ LSTRKEY( "seek" ), LFUNCVAL( file_seek ) },
|
||||
{ LSTRKEY( "flush" ), LFUNCVAL( file_flush ) },
|
||||
//{ LSTRKEY( "check" ), LFUNCVAL( file_check ) },
|
||||
{ LSTRKEY( "rename" ), LFUNCVAL( file_rename ) },
|
||||
{ LSTRKEY( "fsinfo" ), LFUNCVAL( file_fsinfo ) },
|
||||
{ LSTRKEY( "exists" ), LFUNCVAL( file_exists ) },
|
||||
|
|
Loading…
Reference in New Issue