diff options
author | 2016-07-07 16:50:39 +1000 | |
---|---|---|
committer | 2016-07-07 16:50:39 +1000 | |
commit | 2c3fdc52214bcb6d1da43e2b8df60cd07b2a4627 (patch) | |
tree | 1002c3f7a5c48aa558924a54c82431ecded007b4 /src/osd/modules/file | |
parent | 630e7a2e9829c98285c8a422bfa1611d3f61676a (diff) |
POSIX implementation for valid filename/path character functions
Diffstat (limited to 'src/osd/modules/file')
-rw-r--r-- | src/osd/modules/file/posixfile.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/osd/modules/file/posixfile.cpp b/src/osd/modules/file/posixfile.cpp index 53b4e1c9893..09ed0ac7984 100644 --- a/src/osd/modules/file/posixfile.cpp +++ b/src/osd/modules/file/posixfile.cpp @@ -39,6 +39,7 @@ // MAME headers #include "posixfile.h" +#include "unicode.h" #include <cassert> #include <cerrno> @@ -66,7 +67,6 @@ constexpr char PATHSEPCH = '\\'; constexpr char INVPATHSEPCH = '/'; #else constexpr char PATHSEPCH = '/'; -constexpr char INVPATHSEPCH = '\\'; #endif @@ -164,7 +164,11 @@ private: bool is_path_separator(char c) { +#if defined(WIN32) return (c == PATHSEPCH) || (c == INVPATHSEPCH); +#else + return c == PATHSEPCH; +#endif } @@ -176,7 +180,7 @@ osd_file::error create_path_recursive(std::string const &path) { // if there's still a separator, and it's not the root, nuke it and recurse auto const sep = path.rfind(PATHSEPCH); - if ((sep != std::string::npos) && (sep > 0) && (path[sep] != ':') && (path[sep - 1] != PATHSEPCH)) + if ((sep != std::string::npos) && (sep > 0) && (path[sep - 1] != PATHSEPCH)) { osd_file::error const err = create_path_recursive(path.substr(0, sep)); if (err != osd_file::error::NONE) @@ -235,8 +239,10 @@ osd_file::error osd_file::open(std::string const &path, std::uint32_t openflags, // convert the path into something compatible dst = path; +#if defined(WIN32) for (auto it = dst.begin(); it != dst.end(); ++it) *it = (INVPATHSEPCH == *it) ? PATHSEPCH : *it; +#endif osd_subst_env(dst, dst); // attempt to open the file @@ -461,7 +467,48 @@ const char *osd_get_volume_name(int idx) return "/"; else return nullptr; - } +} + + +//============================================================ +// osd_is_valid_filename_char +//============================================================ + +bool osd_is_valid_filename_char(unicode_char uchar) +{ + // The only one that's actually invalid is the slash + // The other two are just problematic because they're the escape character and path separator + return osd_is_valid_filepath_char(uchar) +#if defined(WIN32) + && uchar != PATHSEPCH + && uchar != INVPATHSEPCH +#else + && uchar != PATHSEPCH + && uchar != '\\' +#endif + && uchar != ':'; +} + + +//============================================================ +// osd_is_valid_filepath_char +//============================================================ + +bool osd_is_valid_filepath_char(unicode_char uchar) +{ + // One could argue that colon should be in here too because it functions as path separator + return uchar >= 0x20 + && !(uchar >= '\x7F' && uchar <= '\x9F') +#if defined(WIN32) + && uchar != '<' + && uchar != '>' + && uchar != '\"' + && uchar != '|' + && uchar != '?' + && uchar != '*' +#endif + && uchar_isvalid(uchar); +} //============================================================ |