mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
cpu: clean up
Change read_file to spa_cpu_read_file and remove static because it might not be used for some cpus. Use spa_cpu_read_file in arm cpu detection.
This commit is contained in:
parent
bba452695e
commit
da26563a83
2 changed files with 4 additions and 27 deletions
|
|
@ -49,37 +49,14 @@ static char *get_cpuinfo_line(char *cpuinfo, const char *tag)
|
||||||
return strndup(colon, end - colon);
|
return strndup(colon, end - colon);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_cpuinfo(void)
|
|
||||||
{
|
|
||||||
char *cpuinfo;
|
|
||||||
int n, fd;
|
|
||||||
|
|
||||||
cpuinfo = malloc(MAX_BUFFER);
|
|
||||||
|
|
||||||
if ((fd = open("/proc/cpuinfo", O_RDONLY | O_CLOEXEC, 0)) < 0) {
|
|
||||||
free(cpuinfo);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((n = read(fd, cpuinfo, MAX_BUFFER-1)) < 0) {
|
|
||||||
free(cpuinfo);
|
|
||||||
close(fd);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
cpuinfo[n] = 0;
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return cpuinfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
arm_init(struct impl *impl)
|
arm_init(struct impl *impl)
|
||||||
{
|
{
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
char *cpuinfo, *line;
|
char *cpuinfo, *line, buffer[MAX_BUFFER];
|
||||||
int arch;
|
int arch;
|
||||||
|
|
||||||
if (!(cpuinfo = get_cpuinfo())) {
|
if (!(cpuinfo = spa_cpu_read_file("/proc/cpuinfo", buffer, sizeof(buffer)))) {
|
||||||
spa_log_warn(impl->log, "%p: Can't read cpuinfo", impl);
|
spa_log_warn(impl->log, "%p: Can't read cpuinfo", impl);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ struct impl {
|
||||||
uint32_t vm_type;
|
uint32_t vm_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *read_file(const char *name, char *buffer, size_t len)
|
char *spa_cpu_read_file(const char *name, char *buffer, size_t len)
|
||||||
{
|
{
|
||||||
int n, fd;
|
int n, fd;
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ impl_cpu_get_vm_type(void *object)
|
||||||
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendors, dv) {
|
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendors, dv) {
|
||||||
char buffer[256], *s;
|
char buffer[256], *s;
|
||||||
|
|
||||||
if ((s = read_file(*dv, buffer, sizeof(buffer))) == NULL)
|
if ((s = spa_cpu_read_file(*dv, buffer, sizeof(buffer))) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendor_table, t) {
|
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendor_table, t) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue