SDL_GUIDToString() follows the SDL_GetStringRule

Also removed the distinction between SDL_GUID and SDL_JoystickGUID
This commit is contained in:
Sam Lantinga
2024-07-19 09:08:17 -07:00
parent 892df4bf4b
commit 61a7a0e579
44 changed files with 182 additions and 260 deletions

View File

@@ -21,28 +21,21 @@
#include "SDL_internal.h"
/* convert the guid to a printable string */
int SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
const char *SDL_GUIDToString(SDL_GUID guid)
{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
char string[sizeof(guid) * 2 + 1];
if (!pszGUID) {
return SDL_InvalidParamError("pszGUID");
}
if (cbGUID <= 0) {
return SDL_InvalidParamError("cbGUID");
}
for (i = 0; i < sizeof(guid.data) && i < (cbGUID - 1) / 2; i++) {
/* each input byte writes 2 ascii chars, and might write a null byte. */
/* If we don't have room for next input byte, stop */
for (i = 0; i < sizeof(guid.data); ++i) {
unsigned char c = guid.data[i];
*pszGUID++ = k_rgchHexToASCII[c >> 4];
*pszGUID++ = k_rgchHexToASCII[c & 0x0F];
string[i * 2 + 0] = k_rgchHexToASCII[c >> 4];
string[i * 2 + 1] = k_rgchHexToASCII[c & 0x0F];
}
*pszGUID = '\0';
return 0;
string[sizeof(string) -1] = '\0';
return SDL_CreateTemporaryString(string);
}
/*-----------------------------------------------------------------------------