eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit 3ab0d8270a52a4a80ecda4a04147e31d72cb94d0
parent b33d100f7b85be8f8e51eaf8584c98666ec02653
Author: Matt Oberle <matt.r.oberle@gmail.com>
Date:   Mon,  9 Aug 2021 01:27:24 -0400

storage: provide storage_is_file

Add a function 'storage_is_file' which will use stat to verify a
file's existence given a path relative to the storage directory.

Not all filesystems provide a file type via readdir's d_type.
XFS is a notable system with optional d_type support.
When d_type is not supported stat must be used as a fallback.
If a stat fallback is not provided iwd will fail to load state files.

Diffstat:
Msrc/storage.c | 18++++++++++++++++++
Msrc/storage.h | 1+
2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/storage.c b/src/storage.c @@ -29,11 +29,13 @@ #include <errno.h> #include <ctype.h> #include <fcntl.h> +#include <stdbool.h> #include <string.h> #include <stdarg.h> #include <stdlib.h> #include <unistd.h> #include <time.h> +#include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> @@ -445,3 +447,19 @@ void storage_known_frequencies_sync(struct l_settings *known_freqs) l_free(known_freq_file_path); } + +bool storage_is_file(const char *filename) +{ + char *path; + struct stat st; + int err; + + path = storage_get_path("%s", filename); + err = stat(path, &st); + l_free(path); + + if (!err && S_ISREG(st.st_mode) != 0) + return true; + + return false; +} diff --git a/src/storage.h b/src/storage.h @@ -32,6 +32,7 @@ ssize_t write_file(const void *buffer, size_t len, bool preserve_times, const char *path_fmt, ...) __attribute__((format(printf, 4, 5))); +bool storage_is_file(const char *filename); bool storage_create_dirs(void); void storage_cleanup_dirs(void); char *storage_get_path(const char *format, ...);