Skip to content

Commit 391bb80

Browse files
ccawley2011slouken
authored andcommitted
Replace duplicate functions and lstrlen/lstrcat with SDL string functions
1 parent 67e8522 commit 391bb80

File tree

6 files changed

+16
-50
lines changed

6 files changed

+16
-50
lines changed

src/SDL_log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,15 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
376376
#if !defined(HAVE_STDIO_H) && !defined(__WINRT__)
377377
/* Screen output to stderr, if console was attached. */
378378
if (consoleAttached == 1) {
379-
if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
379+
if (!WriteConsole(stderrHandle, tstr, SDL_tcslen(tstr), &charsWritten, NULL)) {
380380
OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
381381
if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) {
382382
OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
383383
}
384384
}
385385

386386
} else if (consoleAttached == 2) {
387-
if (!WriteFile(stderrHandle, output, lstrlenA(output), &charsWritten, NULL)) {
387+
if (!WriteFile(stderrHandle, output, SDL_strlen(output), &charsWritten, NULL)) {
388388
OutputDebugString(TEXT("Error calling WriteFile\r\n"));
389389
}
390390
}

src/audio/wasapi/SDL_wasapi.c

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,6 @@ static const IID SDL_IID_IAudioCaptureClient = { 0xc8adbd64, 0xe71e, 0x48a0,{ 0x
5858
static const GUID SDL_KSDATAFORMAT_SUBTYPE_PCM = { 0x00000001, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
5959
static const GUID SDL_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT = { 0x00000003, 0x0000, 0x0010,{ 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
6060

61-
static SDL_bool
62-
WStrEqual(const WCHAR *a, const WCHAR *b)
63-
{
64-
while (*a) {
65-
if (*a != *b) {
66-
return SDL_FALSE;
67-
}
68-
a++;
69-
b++;
70-
}
71-
return *b == 0;
72-
}
73-
74-
static size_t
75-
WStrLen(const WCHAR *wstr)
76-
{
77-
size_t retval = 0;
78-
if (wstr) {
79-
while (*(wstr++)) {
80-
retval++;
81-
}
82-
}
83-
return retval;
84-
}
85-
86-
static WCHAR *
87-
WStrDupe(const WCHAR *wstr)
88-
{
89-
const size_t len = (WStrLen(wstr) + 1) * sizeof (WCHAR);
90-
WCHAR *retval = (WCHAR *) SDL_malloc(len);
91-
if (retval) {
92-
SDL_memcpy(retval, wstr, len);
93-
}
94-
return retval;
95-
}
96-
9761

9862
void
9963
WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
@@ -103,7 +67,7 @@ WASAPI_RemoveDevice(const SDL_bool iscapture, LPCWSTR devid)
10367
DevIdList *prev = NULL;
10468
for (i = deviceid_list; i; i = next) {
10569
next = i->next;
106-
if (WStrEqual(i->str, devid)) {
70+
if (SDL_wcscmp(i->str, devid) == 0) {
10771
if (prev) {
10872
prev->next = next;
10973
} else {
@@ -153,7 +117,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS
153117

154118
/* see if we already have this one. */
155119
for (devidlist = deviceid_list; devidlist; devidlist = devidlist->next) {
156-
if (WStrEqual(devidlist->str, devid)) {
120+
if (SDL_wcscmp(devidlist->str, devid) == 0) {
157121
return; /* we already have this. */
158122
}
159123
}
@@ -163,7 +127,7 @@ WASAPI_AddDevice(const SDL_bool iscapture, const char *devname, WAVEFORMATEXTENS
163127
return; /* oh well. */
164128
}
165129

166-
devid = WStrDupe(devid);
130+
devid = SDL_wcsdup(devid);
167131
if (!devid) {
168132
SDL_free(devidlist);
169133
return; /* oh well. */
@@ -690,7 +654,7 @@ WASAPI_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
690654
if (!devid) { /* is default device? */
691655
this->hidden->default_device_generation = SDL_AtomicGet(iscapture ? &WASAPI_DefaultCaptureGeneration : &WASAPI_DefaultPlaybackGeneration);
692656
} else {
693-
this->hidden->devid = WStrDupe(devid);
657+
this->hidden->devid = SDL_wcsdup(devid);
694658
if (!this->hidden->devid) {
695659
return SDL_OutOfMemory();
696660
}

src/core/windows/SDL_windows.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
#if UNICODE
4747
#define WIN_StringToUTF8 WIN_StringToUTF8W
4848
#define WIN_UTF8ToString WIN_UTF8ToStringW
49+
#define SDL_tcslen SDL_wcslen
4950
#define SDL_tcsstr SDL_wcsstr
5051
#else
5152
#define WIN_StringToUTF8 WIN_StringToUTF8A
5253
#define WIN_UTF8ToString WIN_UTF8ToStringA
54+
#define SDL_tcslen SDL_strlen
5355
#define SDL_tcsstr SDL_strstr
5456
#endif
5557

src/filesystem/windows/SDL_sysfilesystem.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ SDL_GetPrefPath(const char *org, const char *app)
143143
return NULL;
144144
}
145145

146-
new_wpath_len = lstrlenW(worg) + lstrlenW(wapp) + lstrlenW(path) + 3;
146+
new_wpath_len = SDL_wcslen(worg) + SDL_wcslen(wapp) + SDL_wcslen(path) + 3;
147147

148148
if ((new_wpath_len + 1) > MAX_PATH) {
149149
SDL_free(worg);
@@ -153,8 +153,8 @@ SDL_GetPrefPath(const char *org, const char *app)
153153
}
154154

155155
if (*worg) {
156-
lstrcatW(path, L"\\");
157-
lstrcatW(path, worg);
156+
SDL_wcslcat(path, L"\\", SDL_arraysize(path));
157+
SDL_wcslcat(path, worg, SDL_arraysize(path));
158158
}
159159
SDL_free(worg);
160160

@@ -167,8 +167,8 @@ SDL_GetPrefPath(const char *org, const char *app)
167167
}
168168
}
169169

170-
lstrcatW(path, L"\\");
171-
lstrcatW(path, wapp);
170+
SDL_wcslcat(path, L"\\", SDL_arraysize(path));
171+
SDL_wcslcat(path, wapp, SDL_arraysize(path));
172172
SDL_free(wapp);
173173

174174
api_result = CreateDirectoryW(path, NULL);
@@ -179,7 +179,7 @@ SDL_GetPrefPath(const char *org, const char *app)
179179
}
180180
}
181181

182-
lstrcatW(path, L"\\");
182+
SDL_wcslcat(path, L"\\", SDL_arraysize(path));
183183

184184
retval = WIN_StringToUTF8W(path);
185185

src/video/winrt/SDL_winrtgamebar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ WINRT_GetGameBar()
8989
IGameBarStatics_ *pGameBar = NULL;
9090
HRESULT hr;
9191

92-
hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName);
92+
hr = ::WindowsCreateString(wClassName, (UINT32)SDL_wcslen(wClassName), &hClassName);
9393
if (FAILED(hr)) {
9494
goto done;
9595
}

src/video/winrt/SDL_winrtvideo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ WINRT_CreateDisplayRequest(_THIS)
782782
ABI::Windows::System::Display::IDisplayRequest * pDisplayRequest = nullptr;
783783
HRESULT hr;
784784

785-
hr = ::WindowsCreateString(wClassName, (UINT32)wcslen(wClassName), &hClassName);
785+
hr = ::WindowsCreateString(wClassName, (UINT32)SDL_wcslen(wClassName), &hClassName);
786786
if (FAILED(hr)) {
787787
goto done;
788788
}

0 commit comments

Comments
 (0)