mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
spa: vulkan: simplify kernel version parsing
Use a single `sscanf()` instead of multiple `strtok()`, `atoi()` calls. After this change all three components are required to be present.
This commit is contained in:
parent
2771c435fd
commit
01d1e29402
1 changed files with 4 additions and 23 deletions
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <linux/dma-buf.h>
|
||||
#include <linux/version.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <xf86drm.h>
|
||||
|
|
@ -51,29 +52,9 @@ bool dmabuf_check_sync_file_import_export(struct spa_log *log) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Trim release suffix if any, e.g. "-arch1-1"
|
||||
for (size_t i = 0; utsname.release[i] != '\0'; i++) {
|
||||
char ch = utsname.release[i];
|
||||
if ((ch < '0' || ch > '9') && ch != '.') {
|
||||
utsname.release[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *rel = strtok(utsname.release, ".");
|
||||
int major = atoi(rel);
|
||||
|
||||
int minor = 0;
|
||||
rel = strtok(NULL, ".");
|
||||
if (rel != NULL) {
|
||||
minor = atoi(rel);
|
||||
}
|
||||
|
||||
int patch = 0;
|
||||
rel = strtok(NULL, ".");
|
||||
if (rel != NULL) {
|
||||
patch = atoi(rel);
|
||||
}
|
||||
unsigned int major, minor, patch;
|
||||
if (sscanf(utsname.release, "%u.%u.%u", &major, &minor, &patch) != 3)
|
||||
return false;
|
||||
|
||||
return KERNEL_VERSION(major, minor, patch) >= KERNEL_VERSION(5, 20, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue