|
36 | 36 | #include "SDL_evdev_capabilities.h" |
37 | 37 | #include "../unix/SDL_poll.h" |
38 | 38 |
|
39 | | -#define SDL_UDEV_FALLBACK_LIBS "libudev.so.1", "libudev.so.0" |
| 39 | +#define SDL_UDEV_FALLBACK_LIBS "libudev.so.1", "libudev.so.0" |
40 | 40 |
|
41 | 41 | static const char *SDL_UDEV_LIBS[] = { SDL_UDEV_FALLBACK_LIBS }; |
42 | 42 |
|
@@ -247,22 +247,19 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, in |
247 | 247 | return false; |
248 | 248 | } |
249 | 249 |
|
250 | | - if (stat(device_path, &statbuf) == -1) { |
| 250 | + if (stat(device_path, &statbuf) < 0) { |
251 | 251 | return false; |
252 | 252 | } |
253 | 253 |
|
254 | 254 | if (S_ISBLK(statbuf.st_mode)) { |
255 | 255 | type = 'b'; |
256 | | - } |
257 | | - else if (S_ISCHR(statbuf.st_mode)) { |
| 256 | + } else if (S_ISCHR(statbuf.st_mode)) { |
258 | 257 | type = 'c'; |
259 | | - } |
260 | | - else { |
| 258 | + } else { |
261 | 259 | return false; |
262 | 260 | } |
263 | 261 |
|
264 | 262 | dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev); |
265 | | - |
266 | 263 | if (!dev) { |
267 | 264 | return false; |
268 | 265 | } |
@@ -302,41 +299,43 @@ bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, in |
302 | 299 | return true; |
303 | 300 | } |
304 | 301 |
|
305 | | -bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial) |
| 302 | +char *SDL_UDEV_GetProductSerial(const char *device_path) |
306 | 303 | { |
307 | 304 | struct stat statbuf; |
308 | 305 | char type; |
309 | 306 | struct udev_device *dev; |
310 | 307 | const char *val; |
| 308 | + char *result = NULL; |
311 | 309 |
|
312 | 310 | if (!_this) { |
313 | | - return false; |
| 311 | + return NULL; |
314 | 312 | } |
315 | 313 |
|
316 | 314 | if (stat(device_path, &statbuf) < 0) { |
317 | | - return false; |
| 315 | + return NULL; |
318 | 316 | } |
319 | 317 |
|
320 | 318 | if (S_ISBLK(statbuf.st_mode)) { |
321 | 319 | type = 'b'; |
322 | 320 | } else if (S_ISCHR(statbuf.st_mode)) { |
323 | 321 | type = 'c'; |
324 | 322 | } else { |
325 | | - return false; |
| 323 | + return NULL; |
326 | 324 | } |
327 | 325 |
|
328 | 326 | dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev); |
329 | 327 | if (!dev) { |
330 | | - return false; |
| 328 | + return NULL; |
331 | 329 | } |
332 | 330 |
|
333 | 331 | val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT"); |
334 | | - if (val) { |
335 | | - *serial = val; |
336 | | - return true; |
| 332 | + if (val && *val) { |
| 333 | + result = SDL_strdup(val); |
337 | 334 | } |
338 | 335 |
|
339 | | - return false; |
| 336 | + _this->syms.udev_device_unref(dev); |
| 337 | + |
| 338 | + return result; |
340 | 339 | } |
341 | 340 |
|
342 | 341 | void SDL_UDEV_UnloadLibrary(void) |
|
0 commit comments