/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122// convert the guid to a printable string23void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)24{25static const char k_rgchHexToASCII[] = "0123456789abcdef";26int i;2728if ((!pszGUID) || (cbGUID <= 0)) {29return;30}3132for (i = 0; i < sizeof(guid.data) && i < (cbGUID - 1) / 2; i++) {33// each input byte writes 2 ascii chars, and might write a null byte.34// If we don't have room for next input byte, stop35unsigned char c = guid.data[i];3637*pszGUID++ = k_rgchHexToASCII[c >> 4];38*pszGUID++ = k_rgchHexToASCII[c & 0x0F];39}40*pszGUID = '\0';41}4243/*-----------------------------------------------------------------------------44* Purpose: Returns the 4 bit nibble for a hex character45* Input : c -46* Output : unsigned char47*-----------------------------------------------------------------------------*/48static unsigned char nibble(unsigned char c)49{50if ((c >= '0') && (c <= '9')) {51return c - '0';52}5354if ((c >= 'A') && (c <= 'F')) {55return c - 'A' + 0x0a;56}5758if ((c >= 'a') && (c <= 'f')) {59return c - 'a' + 0x0a;60}6162// received an invalid character, and no real way to return an error63// AssertMsg1(false, "Q_nibble invalid hex character '%c' ", c);64return 0;65}6667// convert the string version of a guid to the struct68SDL_GUID SDL_StringToGUID(const char *pchGUID)69{70SDL_GUID guid;71int maxoutputbytes = sizeof(guid);72size_t len = SDL_strlen(pchGUID);73Uint8 *p;74size_t i;7576// Make sure it's even77len = (len) & ~0x1;7879SDL_memset(&guid, 0x00, sizeof(guid));8081p = (Uint8 *)&guid;82for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i += 2, p++) {83*p = (nibble((unsigned char)pchGUID[i]) << 4) | nibble((unsigned char)pchGUID[i + 1]);84}8586return guid;87}888990