ucm: Use LFS calls (stat, scandir)

Continue the work in commit ba86ac55 ("conf: Use LFS calls when reading
config files") and fix the UCM code, too.

Fixes: https://github.com/alsa-project/alsa-lib/pull/223
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2022-05-19 17:37:46 +02:00
parent 45b65fa4c1
commit edec439a0c
4 changed files with 19 additions and 19 deletions

View file

@ -166,7 +166,7 @@ static int read_tlv_file(unsigned int **res,
{ {
int err = 0; int err = 0;
int fd; int fd;
struct stat st; struct stat64 st;
size_t sz; size_t sz;
ssize_t sz_read; ssize_t sz_read;
struct snd_ctl_tlv *tlv; struct snd_ctl_tlv *tlv;
@ -176,7 +176,7 @@ static int read_tlv_file(unsigned int **res,
err = -errno; err = -errno;
return err; return err;
} }
if (fstat(fd, &st) == -1) { if (fstat64(fd, &st) == -1) {
err = -errno; err = -errno;
goto __fail; goto __fail;
} }
@ -218,7 +218,7 @@ static int binary_file_parse(snd_ctl_elem_value_t *dst,
{ {
int err = 0; int err = 0;
int fd; int fd;
struct stat st; struct stat64 st;
size_t sz; size_t sz;
ssize_t sz_read; ssize_t sz_read;
char *res; char *res;
@ -236,7 +236,7 @@ static int binary_file_parse(snd_ctl_elem_value_t *dst,
err = -errno; err = -errno;
return err; return err;
} }
if (stat(filepath, &st) == -1) { if (stat64(filepath, &st) == -1) {
err = -errno; err = -errno;
goto __fail; goto __fail;
} }

View file

@ -36,7 +36,7 @@
#include <dirent.h> #include <dirent.h>
#include <limits.h> #include <limits.h>
static int filename_filter(const struct dirent *dirent); static int filename_filter(const struct dirent64 *dirent);
static int parse_sequence(snd_use_case_mgr_t *uc_mgr, static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
struct list_head *base, struct list_head *base,
@ -2549,7 +2549,7 @@ static int parse_toplevel_path(snd_use_case_mgr_t *uc_mgr,
snd_config_t *n, *n2; snd_config_t *n, *n2;
const char *id; const char *id;
char *dir = NULL, *file = NULL, fn[PATH_MAX]; char *dir = NULL, *file = NULL, fn[PATH_MAX];
struct stat st; struct stat64 st;
long version; long version;
int err; int err;
@ -2624,7 +2624,7 @@ static int parse_toplevel_path(snd_use_case_mgr_t *uc_mgr,
} }
ucm_filename(fn, sizeof(fn), version, dir, file); ucm_filename(fn, sizeof(fn), version, dir, file);
if (access(fn, R_OK) == 0 && lstat(fn, &st) == 0) { if (access(fn, R_OK) == 0 && lstat64(fn, &st) == 0) {
if (st.st_mode & S_IFLNK) { if (st.st_mode & S_IFLNK) {
ssize_t r; ssize_t r;
char *link, *dir2, *p; char *link, *dir2, *p;
@ -2838,7 +2838,7 @@ __error:
return err; return err;
} }
static int filename_filter(const struct dirent *dirent) static int filename_filter(const struct dirent64 *dirent)
{ {
if (dirent == NULL) if (dirent == NULL)
return 0; return 0;
@ -2872,7 +2872,7 @@ int uc_mgr_scan_master_configs(const char **_list[])
int i, j, cnt, err; int i, j, cnt, err;
long l; long l;
ssize_t ss; ssize_t ss;
struct dirent **namelist; struct dirent64 **namelist;
if (env) if (env)
snprintf(filename, sizeof(filename), "%s/conf.virt.d", env); snprintf(filename, sizeof(filename), "%s/conf.virt.d", env);
@ -2881,11 +2881,11 @@ int uc_mgr_scan_master_configs(const char **_list[])
snd_config_topdir()); snd_config_topdir());
#if defined(_GNU_SOURCE) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__sun) && !defined(ANDROID) #if defined(_GNU_SOURCE) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__sun) && !defined(ANDROID)
#define SORTFUNC versionsort #define SORTFUNC versionsort64
#else #else
#define SORTFUNC alphasort #define SORTFUNC alphasort64
#endif #endif
err = scandir(filename, &namelist, filename_filter, SORTFUNC); err = scandir64(filename, &namelist, filename_filter, SORTFUNC);
if (err < 0) { if (err < 0) {
err = -errno; err = -errno;
uc_error("error: could not scan directory %s: %s", uc_error("error: could not scan directory %s: %s",

View file

@ -44,10 +44,10 @@ static int find_exec(const char *name, char *out, size_t len)
char bin[PATH_MAX]; char bin[PATH_MAX];
char *path, *tmp, *tmp2 = NULL; char *path, *tmp, *tmp2 = NULL;
DIR *dir; DIR *dir;
struct dirent *de; struct dirent64 *de;
struct stat st; struct stat64 st;
if (name[0] == '/') { if (name[0] == '/') {
if (lstat(name, &st)) if (lstat64(name, &st))
return 0; return 0;
if (!S_ISREG(st.st_mode) || !(st.st_mode & S_IEXEC)) if (!S_ISREG(st.st_mode) || !(st.st_mode & S_IEXEC))
return 0; return 0;
@ -63,12 +63,12 @@ static int find_exec(const char *name, char *out, size_t len)
tmp = strtok_r(path, ":", &tmp2); tmp = strtok_r(path, ":", &tmp2);
while (tmp && !ret) { while (tmp && !ret) {
if ((dir = opendir(tmp))) { if ((dir = opendir(tmp))) {
while ((de = readdir(dir))) { while ((de = readdir64(dir))) {
if (strstr(de->d_name, name) != de->d_name) if (strstr(de->d_name, name) != de->d_name)
continue; continue;
snprintf(bin, sizeof(bin), "%s/%s", tmp, snprintf(bin, sizeof(bin), "%s/%s", tmp,
de->d_name); de->d_name);
if (lstat(bin, &st)) if (lstat64(bin, &st))
continue; continue;
if (!S_ISREG(st.st_mode) if (!S_ISREG(st.st_mode)
|| !(st.st_mode & S_IEXEC)) || !(st.st_mode & S_IEXEC))

View file

@ -499,7 +499,7 @@ static char *rval_env(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char *i
static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char *id) static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char *id)
{ {
char path[PATH_MAX], link[PATH_MAX + 1]; char path[PATH_MAX], link[PATH_MAX + 1];
struct stat sb; struct stat64 sb;
ssize_t len; ssize_t len;
const char *e; const char *e;
int fd; int fd;
@ -510,7 +510,7 @@ static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char
if (id[0] == '/') if (id[0] == '/')
id++; id++;
snprintf(path, sizeof(path), "%s/%s", e, id); snprintf(path, sizeof(path), "%s/%s", e, id);
if (lstat(path, &sb) != 0) if (lstat64(path, &sb) != 0)
return NULL; return NULL;
if (S_ISLNK(sb.st_mode)) { if (S_ISLNK(sb.st_mode)) {
len = readlink(path, link, sizeof(link) - 1); len = readlink(path, link, sizeof(link) - 1);