mirror of
https://github.com/libretro/beetle-gba-libretro.git
synced 2024-11-23 08:19:57 +00:00
Cleanups
This commit is contained in:
parent
0d6df3fa1f
commit
b877588e6d
@ -31,128 +31,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static bool IsAbsolutePath(const char *path)
|
||||
{
|
||||
if (
|
||||
#ifdef _WIN32
|
||||
path[0] == '\\' ||
|
||||
#endif
|
||||
path[0] == '/'
|
||||
)
|
||||
return(TRUE);
|
||||
|
||||
#if defined(WIN32) || defined(DOS)
|
||||
if((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'))
|
||||
{
|
||||
if(path[1] == ':')
|
||||
return(TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
static bool IsAbsolutePath(const std::string &path)
|
||||
{
|
||||
return(IsAbsolutePath(path.c_str()));
|
||||
}
|
||||
|
||||
bool MDFN_IsFIROPSafe(const std::string &path)
|
||||
{
|
||||
// We could make this more OS-specific, but it shouldn't hurt to try to weed out usage of characters that are path
|
||||
// separators in one OS but not in another, and we'd also run more of a risk of missing a special path separator case
|
||||
// in some OS.
|
||||
|
||||
if(!MDFN_GetSettingB("filesys.untrusted_fip_check"))
|
||||
return(true);
|
||||
|
||||
if(path.find('\0') != string::npos)
|
||||
return(false);
|
||||
|
||||
if(path.find(':') != string::npos)
|
||||
return(false);
|
||||
|
||||
if(path.find('\\') != string::npos)
|
||||
return(false);
|
||||
|
||||
if(path.find('/') != string::npos)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void MDFN_GetFilePathComponents(const std::string &file_path,
|
||||
std::string *dir_path_out, std::string *file_base_out,
|
||||
std::string *file_ext_out)
|
||||
{
|
||||
size_t final_ds; // in file_path
|
||||
string file_name;
|
||||
size_t fn_final_dot; // in local var file_name
|
||||
string dir_path, file_base, file_ext; // Temporary output
|
||||
|
||||
#ifdef _WIN32
|
||||
final_ds = file_path.find_last_of('\\');
|
||||
|
||||
size_t alt_final_ds = file_path.find_last_of('/');
|
||||
|
||||
if(final_ds == string::npos || (alt_final_ds != string::npos && alt_final_ds > final_ds))
|
||||
final_ds = alt_final_ds;
|
||||
#else
|
||||
final_ds = file_path.find_last_of('/');
|
||||
#endif
|
||||
|
||||
if(final_ds == string::npos)
|
||||
{
|
||||
dir_path = string(".");
|
||||
file_name = file_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
dir_path = file_path.substr(0, final_ds);
|
||||
file_name = file_path.substr(final_ds + 1);
|
||||
}
|
||||
|
||||
fn_final_dot = file_name.find_last_of('.');
|
||||
|
||||
if(fn_final_dot != string::npos)
|
||||
{
|
||||
file_base = file_name.substr(0, fn_final_dot);
|
||||
file_ext = file_name.substr(fn_final_dot);
|
||||
}
|
||||
else
|
||||
{
|
||||
file_base = file_name;
|
||||
file_ext = string("");
|
||||
}
|
||||
|
||||
if(dir_path_out)
|
||||
*dir_path_out = dir_path;
|
||||
|
||||
if(file_base_out)
|
||||
*file_base_out = file_base;
|
||||
|
||||
if(file_ext_out)
|
||||
*file_ext_out = file_ext;
|
||||
}
|
||||
|
||||
std::string MDFN_EvalFIP(const std::string &dir_path, const std::string &rel_path, bool skip_safety_check)
|
||||
{
|
||||
char slash;
|
||||
#ifdef _WIN32
|
||||
slash = '\\';
|
||||
#else
|
||||
slash = '/';
|
||||
#endif
|
||||
|
||||
if(!skip_safety_check && !MDFN_IsFIROPSafe(rel_path))
|
||||
throw MDFN_Error(0, _("Referenced path \"%s\" is potentially unsafe. See \"filesys.untrusted_fip_check\" setting.\n"), rel_path.c_str());
|
||||
|
||||
if(IsAbsolutePath(rel_path.c_str()))
|
||||
return(rel_path);
|
||||
else
|
||||
return(dir_path + slash + rel_path);
|
||||
}
|
||||
|
||||
const char * GetFNComponent(const char *str)
|
||||
{
|
||||
const char *tp1;
|
||||
@ -223,62 +101,3 @@ void MDFN_trim(char *string)
|
||||
MDFN_rtrim(string);
|
||||
MDFN_ltrim(string);
|
||||
}
|
||||
|
||||
// Remove whitespace from beginning of string
|
||||
void MDFN_ltrim(std::string &string)
|
||||
{
|
||||
size_t len = string.length();
|
||||
size_t di, si;
|
||||
bool InWhitespace = TRUE;
|
||||
|
||||
di = si = 0;
|
||||
|
||||
while(si < len)
|
||||
{
|
||||
if(InWhitespace && (string[si] == ' ' || string[si] == '\r' || string[si] == '\n' || string[si] == '\t' || string[si] == 0x0b))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
InWhitespace = FALSE;
|
||||
string[di] = string[si];
|
||||
di++;
|
||||
}
|
||||
si++;
|
||||
}
|
||||
|
||||
string.resize(di);
|
||||
}
|
||||
|
||||
// Remove whitespace from end of string
|
||||
void MDFN_rtrim(std::string &string)
|
||||
{
|
||||
size_t len = string.length();
|
||||
|
||||
if(len)
|
||||
{
|
||||
size_t x = len;
|
||||
size_t new_len = len;
|
||||
|
||||
do
|
||||
{
|
||||
x--;
|
||||
|
||||
if(!(string[x] == ' ' || string[x] == '\r' || string[x] == '\n' || string[x] == '\t' || string[x] == 0x0b))
|
||||
break;
|
||||
|
||||
new_len--;
|
||||
} while(x);
|
||||
|
||||
string.resize(new_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MDFN_trim(std::string &string)
|
||||
{
|
||||
MDFN_rtrim(string);
|
||||
MDFN_ltrim(string);
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,6 @@ void MDFN_ltrim(char *string);
|
||||
void MDFN_rtrim(char *string);
|
||||
void MDFN_trim(char *string);
|
||||
|
||||
void MDFN_ltrim(std::string &string);
|
||||
void MDFN_rtrim(std::string &string);
|
||||
void MDFN_trim(std::string &string);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MDFNMKF_STATE = 0,
|
||||
@ -38,7 +34,4 @@ typedef enum
|
||||
std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1);
|
||||
|
||||
const char * GetFNComponent(const char *str);
|
||||
|
||||
void MDFN_GetFilePathComponents(const std::string &file_path, std::string *dir_path_out, std::string *file_base_out = NULL, std::string *file_ext_out = NULL);
|
||||
std::string MDFN_EvalFIP(const std::string &dir_path, const std::string &rel_path, bool skip_safety_check = false);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user