mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-04-07 08:21:11 -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/dma-buf.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
|
|
@ -51,29 +52,9 @@ bool dmabuf_check_sync_file_import_export(struct spa_log *log) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim release suffix if any, e.g. "-arch1-1"
|
unsigned int major, minor, patch;
|
||||||
for (size_t i = 0; utsname.release[i] != '\0'; i++) {
|
if (sscanf(utsname.release, "%u.%u.%u", &major, &minor, &patch) != 3)
|
||||||
char ch = utsname.release[i];
|
return false;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return KERNEL_VERSION(major, minor, patch) >= KERNEL_VERSION(5, 20, 0);
|
return KERNEL_VERSION(major, minor, patch) >= KERNEL_VERSION(5, 20, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue