mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-04 17:06:25 +00:00
SDL_GUIDToString() follows the SDL_GetStringRule
Also removed the distinction between SDL_GUID and SDL_JoystickGUID
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user