mirror of
https://github.com/holub/mame
synced 2025-04-24 17:30:55 +03:00
Fixed off by one issue and other cleanups requested by Vas
This commit is contained in:
parent
ab73291e47
commit
4a9e9742fd
@ -116,17 +116,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class osd_disposer
|
||||
{
|
||||
public:
|
||||
osd_disposer(T *&ptr) : m_ptr(ptr) { }
|
||||
~osd_disposer() { if (m_ptr) osd_free(m_ptr); }
|
||||
private:
|
||||
T *&m_ptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//============================================================
|
||||
// INLINE FUNCTIONS
|
||||
@ -186,6 +175,11 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
|
||||
// convert path to TCHAR
|
||||
auto t_path = tstring_from_utf8(path.c_str());
|
||||
|
||||
// convert the path into something Windows compatible (the actual interesting part appears
|
||||
// to have been commented out???)
|
||||
for (auto iter = t_path.begin(); iter != t_path.end(); iter++)
|
||||
*iter = /* ('/' == *iter) ? '\\' : */ *iter;
|
||||
|
||||
// select the file open modes
|
||||
DWORD disposition, access, sharemode;
|
||||
if (openflags & OPEN_FLAG_WRITE)
|
||||
@ -213,13 +207,16 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
|
||||
// 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[0], '\\');
|
||||
if (pathsep != nullptr)
|
||||
// the code below assumes these are the same
|
||||
assert(std::string::npos == std::wstring::npos);
|
||||
|
||||
auto pathsep = t_path.rfind('\\');
|
||||
if (pathsep != std::string::npos)
|
||||
{
|
||||
// create the path up to the file
|
||||
*pathsep = 0;
|
||||
t_path[pathsep] = 0;
|
||||
err = create_path_recursive(&t_path[0]);
|
||||
*pathsep = '\\';
|
||||
t_path[pathsep] = '\\';
|
||||
|
||||
// attempt to reopen the file
|
||||
if (err == NO_ERROR)
|
||||
|
@ -86,7 +86,7 @@ bool osd_font_windows::open(std::string const &font_path, std::string const &_na
|
||||
|
||||
// copy in the face name
|
||||
std::basic_string<TCHAR> face = tstring_from_utf8(name.c_str());
|
||||
_tcsncpy(logfont.lfFaceName, face.c_str(), sizeof(logfont.lfFaceName) / sizeof(TCHAR));
|
||||
_tcsncpy(logfont.lfFaceName, face.c_str(), ARRAY_LENGTH(logfont.lfFaceName));
|
||||
logfont.lfFaceName[sizeof(logfont.lfFaceName) / sizeof(TCHAR)-1] = 0;
|
||||
|
||||
// create the font
|
||||
|
@ -277,7 +277,7 @@ static char *get_clipboard_text_by_format(UINT format, std::string (*convert)(LP
|
||||
// copy the string
|
||||
result = (char *) osd_malloc(s.size() + 1);
|
||||
if (result != nullptr)
|
||||
memcpy(result, s.data(), s.size() * sizeof(*result));
|
||||
memcpy(result, s.data(), (s.size() + 1) * sizeof(*result));
|
||||
|
||||
// unlock the data
|
||||
GlobalUnlock(data_handle);
|
||||
|
@ -25,9 +25,9 @@ std::string &astring_from_utf8(std::string &dst, const char *s)
|
||||
std::basic_string<WCHAR> wstring = wstring_from_utf8(s);
|
||||
|
||||
// convert UTF-16 to "ANSI code page" string
|
||||
int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size() + 1, nullptr, 0, nullptr, nullptr);
|
||||
dst.resize(char_count - 1);
|
||||
WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), -1, &dst[0], char_count - 1, nullptr, nullptr);
|
||||
WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size() + 1, &dst[0], char_count - 1, nullptr, nullptr);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user