Changes from Alfred:
authorSam Lantinga <slouken@libsdl.org>
Tue, 11 Dec 2012 11:54:32 -0800
changeset 6738 b408d5a406a3
parent 6737 63ba9e5b1272
child 6739 d365b03b9207
Changes from Alfred: - rename JoystickGUID -> SDL_JoystickGUID - change SDL_JoystickGetGUIDString to take the string as an arg, rather than doing a malloc
include/SDL_joystick.h
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_dxjoystick_c.h
src/joystick/windows/SDL_mmjoystick.c
--- a/include/SDL_joystick.h	Tue Dec 11 10:50:45 2012 -0800
+++ b/include/SDL_joystick.h	Tue Dec 11 11:54:32 2012 -0800
@@ -65,7 +65,7 @@
 /* A structure that encodes the stable unique id for a joystick device */
 typedef struct {
 	Uint8 data[16];
-} JoystickGUID;
+} SDL_JoystickGUID;
 
 typedef int SDL_JoystickID;
 
@@ -102,22 +102,22 @@
 /**
  *  Return the GUID for the joystick at this index
  */
-extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
 
 /**
  *  Return the GUID for this opened joystick
  */
-extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
 
 /**
  *  Return a string representation for this guid. You are responsible for freeing memory from this call
  */
-extern DECLSPEC char *SDLCALL SDL_JoystickGetGUIDString(JoystickGUID guid);
+extern DECLSPEC void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
 
 /**
  *  convert a string into a joystick formatted guid
  */
-extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
+extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
 
 /**
  *  Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
--- a/src/joystick/SDL_gamecontroller.c	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/SDL_gamecontroller.c	Tue Dec 11 11:54:32 2012 -0800
@@ -48,7 +48,7 @@
 /* our in memory mapping db between joystick objects and controller mappings*/
 struct _SDL_ControllerMapping
 {
-	JoystickGUID guid;
+	SDL_JoystickGUID guid;
 	const char *name;
 
 	// mapping of axis/button id to controller version
@@ -71,7 +71,7 @@
 /* our hard coded list of mapping support */
 typedef struct _ControllerMapping_t
 {
-	JoystickGUID guid;
+	SDL_JoystickGUID guid;
 	char *name;
 	const char *mapping;
 	struct _ControllerMapping_t *next;
@@ -458,7 +458,7 @@
 /*
  * Make a new button mapping struct
  */
-void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, JoystickGUID guid, const char *pchName, const char *pchMapping )
+void SDL_PrivateLoadButtonMapping( struct _SDL_ControllerMapping *pMapping, SDL_JoystickGUID guid, const char *pchName, const char *pchMapping )
 {
 	int j;
 
@@ -673,7 +673,7 @@
 	}
 	else
 	{
-		JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
+		SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
 		pSupportedController = s_pSupportedControllers;
 		while ( pSupportedController )
 		{
@@ -700,10 +700,11 @@
 	}
 	else
 	{
-		JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
+		SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
 		pSupportedController = s_pSupportedControllers;
 		// debug code to help get the guid string for a new joystick
-		/*const char *pchGUID = SDL_JoystickGetGUIDString( jGUID );
+		/* char szGUID[33];
+		SDL_JoystickGetGUIDString( jGUID, szGUID, sizeof(szGUID) );
 		printf( "%s\n", pchGUID );
 		SDL_free( pchGUID );*/
 		while ( pSupportedController )
@@ -759,7 +760,7 @@
 	pSupportedController =  SDL_PrivateGetControllerMapping(device_index);
 	if ( !pSupportedController )
 	{
-		JoystickGUID jGUID;
+		SDL_JoystickGUID jGUID;
 
 		jGUID = SDL_JoystickGetDeviceGUID( device_index );
 		pSupportedController = s_pSupportedControllers;
--- a/src/joystick/SDL_joystick.c	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/SDL_joystick.c	Tue Dec 11 11:54:32 2012 -0800
@@ -683,34 +683,28 @@
 
 
 /* return the guid for this index */
-JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
+SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
 {
 	return SDL_SYS_JoystickGetDeviceGUID( device_index );
 }
 
 /* return the guid for this opened device */
-JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
+SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
 {
 	return SDL_SYS_JoystickGetGUID( joystick );
 }
 
 /* convert the guid to a printable string */
-char *SDL_JoystickGetGUIDString(JoystickGUID guid)
+void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID )
 {
 	static const char k_rgchHexToASCII[] = "0123456789abcdef";
 	char *pchOut = NULL;
 	char *pchString = NULL;
 	int i;
-	pchString = SDL_malloc(33); // 16 bytes
-	if ( !pchString )
-	{
-		SDL_OutOfMemory();
-		return NULL;
-	}
 	
-	pchOut = pchString;
+	pchOut = pszGUID;
 
-	for ( i = 0; i < sizeof(guid); i++ )
+	for ( i = 0; i < sizeof(guid) && i < (cbGUID-1); 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
@@ -720,7 +714,6 @@
 		*pchOut++ = k_rgchHexToASCII[ c & 0x0F ];
 	}
 	*pchOut = '\0';
-	return pchString;
 }
 
 
@@ -756,9 +749,9 @@
 
 
 /* convert the string version of a joystick guid to the struct */
-JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
+SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
 {
-	JoystickGUID guid;
+	SDL_JoystickGUID guid;
 	int maxoutputbytes= sizeof(guid);
 	int len = SDL_strlen( pchGUID );
 	Uint8 *p;
--- a/src/joystick/SDL_sysjoystick.h	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/SDL_sysjoystick.h	Tue Dec 11 11:54:32 2012 -0800
@@ -104,10 +104,10 @@
 extern void SDL_SYS_JoystickQuit(void);
 
 /* Function to return the stable GUID for a plugged in device */
-extern JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
+extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
 
 /* Function to return the stable GUID for a opened joystick */
-extern JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
+extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
 
 #ifdef SDL_JOYSTICK_DINPUT
 /* Function to get the current instance id of the joystick located at device_index */
--- a/src/joystick/darwin/SDL_sysjoystick.c	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Tue Dec 11 11:54:32 2012 -0800
@@ -1083,7 +1083,7 @@
 }
 
 
-JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
 {
     recDevice *device = gpDeviceList;
     int index;
@@ -1094,7 +1094,7 @@
 	return device->guid;	
 }
 
-JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
 {
 	return joystick->hwdata->guid;
 }
--- a/src/joystick/linux/SDL_sysjoystick.c	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Dec 11 11:54:32 2012 -0800
@@ -953,13 +953,15 @@
 #endif
 }
 
-JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
 {
+    JoystickGUID guid;
     return JoystickByDevIndex(device_index)->guid;
 }
 
-JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
 {
+    JoystickGUID guid;
     return joystick->hwdata->guid;
 }
 
--- a/src/joystick/windows/SDL_dxjoystick.c	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/windows/SDL_dxjoystick.c	Tue Dec 11 11:54:32 2012 -0800
@@ -79,7 +79,7 @@
                                        LPUNKNOWN punkOuter);
 struct JoyStick_DeviceData_
 {
-	JoystickGUID guid;
+	SDL_JoystickGUID guid;
 	DIDEVICEINSTANCE dxdevice;
 	char *joystickname;
 	Uint8 send_add_event;
@@ -1676,7 +1676,7 @@
 
 
 /* return the stable device guid for this device index */
-JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
 {
 	JoyStick_DeviceData *device = SYS_Joystick;
 	int index;
@@ -1687,7 +1687,7 @@
 	return device->guid;
 }
 
-JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
 {
 	return joystick->hwdata->guid;
 }
--- a/src/joystick/windows/SDL_dxjoystick_c.h	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/windows/SDL_dxjoystick_c.h	Tue Dec 11 11:54:32 2012 -0800
@@ -87,7 +87,7 @@
     LPDIRECTINPUTDEVICE8 InputDevice;
     DIDEVCAPS Capabilities;
     int buffered;
-	JoystickGUID guid;
+	SDL_JoystickGUID guid;
 
     input_t Inputs[MAX_INPUTS];
     int NumInputs;
--- a/src/joystick/windows/SDL_mmjoystick.c	Tue Dec 11 10:50:45 2012 -0800
+++ b/src/joystick/windows/SDL_mmjoystick.c	Tue Dec 11 11:54:32 2012 -0800
@@ -405,9 +405,9 @@
     }
 }
 
-JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
+SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
 {
-    JoystickGUID guid;
+    SDL_JoystickGUID guid;
     // the GUID is just the first 16 chars of the name for now
     const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
     SDL_zero( guid );
@@ -415,9 +415,9 @@
     return guid;
 }
 
-JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
+SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
 {
-    JoystickGUID guid;
+    SDL_JoystickGUID guid;
     // the GUID is just the first 16 chars of the name for now
     const char *name = joystick->name;
     SDL_zero( guid );