libwindows: implement strncpy_s from Wine.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
124de54aa9
commit
3d247e6ee9
6 changed files with 39 additions and 8 deletions
|
@ -915,7 +915,7 @@ namespace sa2
|
|||
{
|
||||
ImGui::PushID(nAddress);
|
||||
DisasmLine_t line;
|
||||
const char* pSymbol = FindSymbolFromAddress(nAddress);
|
||||
std::string const* pSymbol = FindSymbolFromAddress(nAddress);
|
||||
const int bDisasmFormatFlags = GetDisassemblyLine(nAddress, line);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
@ -979,7 +979,7 @@ namespace sa2
|
|||
ImGui::TableNextColumn();
|
||||
if (pSymbol)
|
||||
{
|
||||
debuggerTextColored(FG_DISASM_SYMBOL, pSymbol);
|
||||
debuggerTextColored(FG_DISASM_SYMBOL, pSymbol->c_str());
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
|
|
@ -58,8 +58,7 @@ void JoyLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
|
|||
{
|
||||
for (UINT n = 0; n < 4; n++)
|
||||
{
|
||||
char str[sizeof(SS_YAML_KEY_PDL_INACTIVE_CYCLE) + 1];
|
||||
sprintf_s(str, sizeof(str), SS_YAML_KEY_PDL_INACTIVE_CYCLE, n);
|
||||
const std::string str = StrFormat(SS_YAML_KEY_PDL_INACTIVE_CYCLE, n);
|
||||
yamlLoadHelper.LoadUint64(str);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#define IDYES 6
|
||||
#define IDNO 7
|
||||
|
||||
#define EINVAL 22
|
||||
|
||||
BOOL WINAPI PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
int MessageBox(HWND, const char *, const char *, UINT);
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
#include <ctime>
|
||||
|
||||
typedef int errno_t;
|
||||
|
||||
#define _tzset tzset
|
||||
errno_t ctime_s(char * buf, size_t size, const time_t *time);
|
||||
|
||||
|
|
|
@ -206,6 +206,8 @@ typedef void * HWND;
|
|||
typedef LONG_PTR LPARAM;
|
||||
typedef UINT_PTR WPARAM;
|
||||
|
||||
typedef int errno_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "wincompat.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <ctype.h>
|
||||
|
@ -18,8 +19,6 @@ int vsnprintf_s(
|
|||
|
||||
#define _TRUNCATE ((size_t)-1)
|
||||
|
||||
#define sprintf_s snprintf
|
||||
|
||||
#define _strdup strdup
|
||||
#define _strtoui64 strtoull
|
||||
#define _vsntprintf vsnprintf
|
||||
|
@ -51,3 +50,34 @@ inline bool IsCharUpper(char ch) {
|
|||
DWORD CharLowerBuff(LPTSTR lpsz, DWORD cchLength);
|
||||
|
||||
LPSTR _strupr( LPSTR str );
|
||||
|
||||
// copied from
|
||||
// https://github.com/wine-mirror/wine/blob/1d178982ae5a73b18f367026c8689b56789c39fd/dlls/msvcrt/heap.c#L833
|
||||
template <size_t size>
|
||||
errno_t strncpy_s(char (&dest)[size], const char *src, size_t count)
|
||||
{
|
||||
size_t end;
|
||||
if (count != _TRUNCATE && count < size)
|
||||
{
|
||||
end = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
end = size - 1;
|
||||
}
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < end && src[i]; i++)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
}
|
||||
|
||||
if (!src[i] || end == count || count == _TRUNCATE)
|
||||
{
|
||||
dest[i] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
dest[0] = '\0';
|
||||
return EINVAL;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue