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

View file

@ -36,7 +36,7 @@
#include <dirent.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,
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;
const char *id;
char *dir = NULL, *file = NULL, fn[PATH_MAX];
struct stat st;
struct stat64 st;
long version;
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);
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) {
ssize_t r;
char *link, *dir2, *p;
@ -2838,7 +2838,7 @@ __error:
return err;
}
static int filename_filter(const struct dirent *dirent)
static int filename_filter(const struct dirent64 *dirent)
{
if (dirent == NULL)
return 0;
@ -2872,7 +2872,7 @@ int uc_mgr_scan_master_configs(const char **_list[])
int i, j, cnt, err;
long l;
ssize_t ss;
struct dirent **namelist;
struct dirent64 **namelist;
if (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());
#if defined(_GNU_SOURCE) && !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__sun) && !defined(ANDROID)
#define SORTFUNC versionsort
#define SORTFUNC versionsort64
#else
#define SORTFUNC alphasort
#define SORTFUNC alphasort64
#endif
err = scandir(filename, &namelist, filename_filter, SORTFUNC);
err = scandir64(filename, &namelist, filename_filter, SORTFUNC);
if (err < 0) {
err = -errno;
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 *path, *tmp, *tmp2 = NULL;
DIR *dir;
struct dirent *de;
struct stat st;
struct dirent64 *de;
struct stat64 st;
if (name[0] == '/') {
if (lstat(name, &st))
if (lstat64(name, &st))
return 0;
if (!S_ISREG(st.st_mode) || !(st.st_mode & S_IEXEC))
return 0;
@ -63,12 +63,12 @@ static int find_exec(const char *name, char *out, size_t len)
tmp = strtok_r(path, ":", &tmp2);
while (tmp && !ret) {
if ((dir = opendir(tmp))) {
while ((de = readdir(dir))) {
while ((de = readdir64(dir))) {
if (strstr(de->d_name, name) != de->d_name)
continue;
snprintf(bin, sizeof(bin), "%s/%s", tmp,
de->d_name);
if (lstat(bin, &st))
if (lstat64(bin, &st))
continue;
if (!S_ISREG(st.st_mode)
|| !(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)
{
char path[PATH_MAX], link[PATH_MAX + 1];
struct stat sb;
struct stat64 sb;
ssize_t len;
const char *e;
int fd;
@ -510,7 +510,7 @@ static char *rval_sysfs(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, const char
if (id[0] == '/')
id++;
snprintf(path, sizeof(path), "%s/%s", e, id);
if (lstat(path, &sb) != 0)
if (lstat64(path, &sb) != 0)
return NULL;
if (S_ISLNK(sb.st_mode)) {
len = readlink(path, link, sizeof(link) - 1);