aboutsummaryrefslogblamecommitdiffstats
path: root/libgamepad_close_device.c
blob: 896d22e382f122144f1d9da76519d9b77508fc9d (plain) (tree)
1
2
3
4
5
6
7
8
9



                                                         
   

                                                         
                               
                     
                                        
                                                                           
                                                        


                                                                       

                                                         
                                                       


                                                 


                                            


                                                


                                             


                                                 



                                               
         
                 
 
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libgamepad_close_device(struct libgamepad_device *device)
{
	int deferred_error = 0;
	if (device) {
		if (device->internals) {
			deferred_error = device->internals->deferred_error;
			if (device->internals->close_fd)
				if (close(device->fd))
					if (!deferred_error)
						deferred_error = errno;
			free(device->internals->absinfo);
			free(device->internals->buttons);
			free(device->internals->evbuf);
			free(device->internals);
			device->internals = NULL;
		}
		free(device->buttons);
		free(device->absolute_axes);
		free(device->relative_axes);
		free(device->name);
		free(device->unique_id);
		free(device->physical_location);
		device->buttons = NULL;
		device->absolute_axes = NULL;
		device->relative_axes = NULL;
		device->name = NULL;
		device->unique_id = NULL;
		device->physical_location = NULL;
		if (deferred_error) {
			errno = deferred_error;
			return -1;
		}
	}
	return 0;
}