diff options
author | 2016-07-24 22:55:00 -0400 | |
---|---|---|
committer | 2016-07-24 22:55:00 -0400 | |
commit | ab73291e479be171d6f89798ed706b5ea58aa09f (patch) | |
tree | 456ca9bc290187a50909bdf33b610f09e55be70e /src/osd/modules/file | |
parent | 59dafc2261ff1bbe553d64b4aca7b9806b663490 (diff) |
Changed strconv.[cpp|h] functions to return their results as std::string and std::wstring
Diffstat (limited to 'src/osd/modules/file')
-rw-r--r-- | src/osd/modules/file/windir.cpp | 30 | ||||
-rw-r--r-- | src/osd/modules/file/winfile.cpp | 64 | ||||
-rw-r--r-- | src/osd/modules/file/winptty.cpp | 7 |
3 files changed, 28 insertions, 73 deletions
diff --git a/src/osd/modules/file/windir.cpp b/src/osd/modules/file/windir.cpp index 3ecd2412910..9b67e163652 100644 --- a/src/osd/modules/file/windir.cpp +++ b/src/osd/modules/file/windir.cpp @@ -14,6 +14,7 @@ // MAME headers #include "osdcore.h" +#include "strformat.h" // MAMEOS headers #include "strconv.h" @@ -47,6 +48,7 @@ private: bool m_is_first; // true if this is the first entry entry m_entry; // current entry's data WIN32_FIND_DATA m_data; // current raw data + std::string m_name; // converted name of directory }; //============================================================ @@ -69,8 +71,6 @@ win_directory::win_directory() win_directory::~win_directory() { // free any data associated - if (m_entry.name != nullptr) - osd_free((void *)m_entry.name); if (m_find != INVALID_HANDLE_VALUE) FindClose(m_find); } @@ -82,13 +82,6 @@ win_directory::~win_directory() const directory::entry *win_directory::read() { - // if we've previously allocated a name, free it now - if (m_entry.name != nullptr) - { - osd_free((void *)m_entry.name); - m_entry.name = nullptr; - } - // if this isn't the first file, do a find next if (!m_is_first) { @@ -98,7 +91,8 @@ const directory::entry *win_directory::read() m_is_first = false; // extract the data - m_entry.name = utf8_from_tstring(m_data.cFileName); + utf8_from_tstring(m_name, m_data.cFileName); + m_entry.name = m_name.c_str(); m_entry.type = win_attributes_to_entry_type(m_data.dwFileAttributes); m_entry.size = m_data.nFileSizeLow | (std::uint64_t(m_data.nFileSizeHigh) << 32); m_entry.last_modified = win_time_point_from_filetime(&m_data.ftLastWriteTime); @@ -114,20 +108,14 @@ bool win_directory::open_impl(std::string const &dirname) { assert(m_find == INVALID_HANDLE_VALUE); - // convert the path to TCHARs - std::unique_ptr<TCHAR, void (*)(void *)> const t_dirname(tstring_from_utf8(dirname.c_str()), &osd_free); - if (!t_dirname) - return false; - // append \*.* to the directory name - auto const dirfilter_size = _tcslen(t_dirname.get()) + 5; - std::unique_ptr<TCHAR []> dirfilter; - try { dirfilter.reset(new TCHAR[dirfilter_size]); } - catch (...) { return false; } - _sntprintf(dirfilter.get(), dirfilter_size, TEXT("%s\\*.*"), t_dirname.get()); + std::string dirfilter = string_format("%s\\*.*", dirname); + + // convert the path to TCHARs + auto t_dirfilter = tstring_from_utf8(dirfilter.c_str()); // attempt to find the first file - m_find = FindFirstFileEx(dirfilter.get(), FindExInfoStandard, &m_data, FindExSearchNameMatch, nullptr, 0); + m_find = FindFirstFileEx(t_dirfilter.c_str(), FindExInfoStandard, &m_data, FindExSearchNameMatch, nullptr, 0); return m_find != INVALID_HANDLE_VALUE; } diff --git a/src/osd/modules/file/winfile.cpp b/src/osd/modules/file/winfile.cpp index 1885925f9ee..1484caeb818 100644 --- a/src/osd/modules/file/winfile.cpp +++ b/src/osd/modules/file/winfile.cpp @@ -184,14 +184,7 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p return win_open_ptty(path, openflags, file, filesize); // convert path to TCHAR - TCHAR *t_path = tstring_from_utf8(path.c_str()); - osd_disposer<TCHAR> t_path_disposer(t_path); - if (!t_path) - return error::OUT_OF_MEMORY; - - // convert the path into something Windows compatible - for (TCHAR *src = t_path; *src != 0; src++) - *src = /* ('/' == *src) ? '\\' : */ *src; + auto t_path = tstring_from_utf8(path.c_str()); // select the file open modes DWORD disposition, access, sharemode; @@ -213,25 +206,25 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p } // attempt to open the file - HANDLE h = CreateFile(t_path, access, sharemode, nullptr, disposition, 0, nullptr); + HANDLE h = CreateFile(t_path.c_str(), access, sharemode, nullptr, disposition, 0, nullptr); if (INVALID_HANDLE_VALUE == h) { DWORD err = GetLastError(); // create the path if necessary if ((ERROR_PATH_NOT_FOUND == err) && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS)) { - TCHAR *pathsep = _tcsrchr(t_path, '\\'); + TCHAR *pathsep = _tcsrchr(&t_path[0], '\\'); if (pathsep != nullptr) { // create the path up to the file *pathsep = 0; - err = create_path_recursive(t_path); + err = create_path_recursive(&t_path[0]); *pathsep = '\\'; // attempt to reopen the file if (err == NO_ERROR) { - h = CreateFile(t_path, access, sharemode, nullptr, disposition, 0, nullptr); + h = CreateFile(t_path.c_str(), access, sharemode, nullptr, disposition, 0, nullptr); err = GetLastError(); } } @@ -287,15 +280,12 @@ osd_file::error osd_file::openpty(ptr &file, std::string &name) osd_file::error osd_file::remove(std::string const &filename) { - TCHAR *tempstr = tstring_from_utf8(filename.c_str()); - if (!tempstr) - return error::OUT_OF_MEMORY; + auto tempstr = tstring_from_utf8(filename.c_str()); error filerr = error::NONE; - if (!DeleteFile(tempstr)) + if (!DeleteFile(tempstr.c_str())) filerr = win_error_to_file_error(GetLastError()); - osd_free(tempstr); return filerr; } @@ -309,7 +299,6 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN { DISK_GEOMETRY dg; DWORD bytesRead; - TCHAR *t_filename; HANDLE file; int result; @@ -318,11 +307,8 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN return FALSE; // do a create file on the drive - t_filename = tstring_from_utf8(filename); - if (t_filename == nullptr) - return FALSE; - file = CreateFile(t_filename, GENERIC_READ, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, nullptr); - osd_free(t_filename); + auto t_filename = tstring_from_utf8(filename); + file = CreateFile(t_filename.c_str(), GENERIC_READ, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, nullptr); if (file == INVALID_HANDLE_VALUE) return FALSE; @@ -358,9 +344,7 @@ int osd_get_physical_drive_geometry(const char *filename, UINT32 *cylinders, UIN std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path) { // convert the path to TCHARs - std::unique_ptr<TCHAR, void (*)(void *)> const t_path(tstring_from_utf8(path.c_str()), &osd_free); - if (!t_path) - return nullptr; + auto t_path = tstring_from_utf8(path.c_str()); // is this path a root directory (e.g. - C:)? WIN32_FIND_DATA find_data; @@ -368,13 +352,13 @@ std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path) if (isalpha(path[0]) && (path[1] == ':') && (path[2] == '\0')) { // need to do special logic for root directories - if (!GetFileAttributesEx(t_path.get(), GetFileExInfoStandard, &find_data.dwFileAttributes)) + if (!GetFileAttributesEx(t_path.c_str(), GetFileExInfoStandard, &find_data.dwFileAttributes)) find_data.dwFileAttributes = INVALID_FILE_ATTRIBUTES; } else { // attempt to find the first file - HANDLE find = FindFirstFileEx(t_path.get(), FindExInfoStandard, &find_data, FindExSearchNameMatch, nullptr, 0); + HANDLE find = FindFirstFileEx(t_path.c_str(), FindExInfoStandard, &find_data, FindExSearchNameMatch, nullptr, 0); if (find == INVALID_HANDLE_VALUE) return nullptr; FindClose(find); @@ -404,23 +388,15 @@ std::unique_ptr<osd::directory::entry> osd_stat(const std::string &path) osd_file::error osd_get_full_path(std::string &dst, std::string const &path) { // convert the path to TCHARs - TCHAR *t_path = tstring_from_utf8(path.c_str()); - osd_disposer<TCHAR> t_path_disposer(t_path); - if (!t_path) - return osd_file::error::OUT_OF_MEMORY; + auto t_path = tstring_from_utf8(path.c_str()); // cannonicalize the path TCHAR buffer[MAX_PATH]; - if (!GetFullPathName(t_path, ARRAY_LENGTH(buffer), buffer, nullptr)) + if (!GetFullPathName(t_path.c_str(), ARRAY_LENGTH(buffer), buffer, nullptr)) return win_error_to_file_error(GetLastError()); // convert the result back to UTF-8 - char *result = utf8_from_tstring(buffer); - osd_disposer<char> result_disposer(result); - if (!result) - return osd_file::error::OUT_OF_MEMORY; - - dst = result; + utf8_from_tstring(dst, buffer); return osd_file::error::NONE; } @@ -432,14 +408,8 @@ osd_file::error osd_get_full_path(std::string &dst, std::string const &path) bool osd_is_absolute_path(std::string const &path) { - bool result = false; - TCHAR *t_path = tstring_from_utf8(path.c_str()); - if (t_path != nullptr) - { - result = !PathIsRelative(t_path); - osd_free(t_path); - } - return result; + auto t_path = tstring_from_utf8(path.c_str()); + return !PathIsRelative(t_path.c_str()); } diff --git a/src/osd/modules/file/winptty.cpp b/src/osd/modules/file/winptty.cpp index 88920d69099..54aba00c253 100644 --- a/src/osd/modules/file/winptty.cpp +++ b/src/osd/modules/file/winptty.cpp @@ -87,12 +87,9 @@ bool win_check_ptty_path(std::string const &path) osd_file::error win_open_ptty(std::string const &path, std::uint32_t openflags, osd_file::ptr &file, std::uint64_t &filesize) { - TCHAR *t_name = tstring_from_utf8(path.c_str()); - if (!t_name) - return osd_file::error::OUT_OF_MEMORY; + auto t_name = tstring_from_utf8(path.c_str()); - HANDLE pipe = CreateNamedPipe(t_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 32, 32, 0, nullptr); - osd_free(t_name); + HANDLE pipe = CreateNamedPipe(t_name.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 32, 32, 0, nullptr); if (INVALID_HANDLE_VALUE == pipe) return osd_file::error::ACCESS_DENIED; |