mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-31 22:42:52 +08:00
Cleanup SDL_UDEV_GetProductSerial()
This commit is contained in:
+14
-15
@@ -247,22 +247,19 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, in
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(device_path, &statbuf) == -1) {
|
if (stat(device_path, &statbuf) < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISBLK(statbuf.st_mode)) {
|
if (S_ISBLK(statbuf.st_mode)) {
|
||||||
type = 'b';
|
type = 'b';
|
||||||
}
|
} else if (S_ISCHR(statbuf.st_mode)) {
|
||||||
else if (S_ISCHR(statbuf.st_mode)) {
|
|
||||||
type = 'c';
|
type = 'c';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
|
dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
|
||||||
|
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -302,19 +299,20 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, in
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
|
char *SDL_UDEV_GetProductSerial(const char *device_path)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
char type;
|
char type;
|
||||||
struct udev_device *dev;
|
struct udev_device *dev;
|
||||||
const char *val;
|
const char *val;
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
if (!_this) {
|
if (!_this) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(device_path, &statbuf) < 0) {
|
if (stat(device_path, &statbuf) < 0) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISBLK(statbuf.st_mode)) {
|
if (S_ISBLK(statbuf.st_mode)) {
|
||||||
@@ -322,21 +320,22 @@ bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
|
|||||||
} else if (S_ISCHR(statbuf.st_mode)) {
|
} else if (S_ISCHR(statbuf.st_mode)) {
|
||||||
type = 'c';
|
type = 'c';
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
|
dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
|
val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
|
||||||
if (val) {
|
if (val && *val) {
|
||||||
*serial = val;
|
result = SDL_strdup(val);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
_this->syms.udev_device_unref(dev);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDL_UDEV_UnloadLibrary(void)
|
void SDL_UDEV_UnloadLibrary(void)
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ extern bool SDL_UDEV_LoadLibrary(void);
|
|||||||
extern void SDL_UDEV_Poll(void);
|
extern void SDL_UDEV_Poll(void);
|
||||||
extern bool SDL_UDEV_Scan(void);
|
extern bool SDL_UDEV_Scan(void);
|
||||||
extern bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, int *class, char **driver);
|
extern bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, int *class, char **driver);
|
||||||
extern bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial);
|
extern char *SDL_UDEV_GetProductSerial(const char *device_path);
|
||||||
extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
|
extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
|
||||||
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
|
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
|
||||||
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
|
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
|
||||||
|
|||||||
@@ -1609,10 +1609,7 @@ static bool LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SDL_USE_LIBUDEV
|
#ifdef SDL_USE_LIBUDEV
|
||||||
const char *serial = NULL;
|
joystick->serial = SDL_UDEV_GetProductSerial(item->path);
|
||||||
if (SDL_UDEV_GetProductSerial(item->path, &serial)) {
|
|
||||||
joystick->serial = SDL_strdup(serial);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// mark joystick as fresh and ready
|
// mark joystick as fresh and ready
|
||||||
|
|||||||
Reference in New Issue
Block a user