1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-15 17:43:51 +01:00

sys/vfs_util: add vfs_file_exists()

This commit is contained in:
Benjamin Valentin 2024-05-06 15:43:50 +02:00
parent 469c919969
commit 9c4ca01e24
2 changed files with 23 additions and 0 deletions

View File

@ -20,6 +20,9 @@
#ifndef VFS_UTIL_H
#define VFS_UTIL_H
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -115,6 +118,15 @@ int vfs_file_sha256(const char* file, void *digest,
*/
int vfs_is_dir(const char *path);
/**
@brief Checks if @p path is a file and can be read.
*
* @param[in] path Path to check
*
* @return true if the file exists, false otherwise
*/
bool vfs_file_exists(const char *path);
/**
* @brief Behaves like `rm -r @p root`.
*

View File

@ -171,6 +171,17 @@ int vfs_is_dir(const char *path)
return ((stat.st_mode & S_IFMT) == S_IFDIR);
}
bool vfs_file_exists(const char *path)
{
int res = vfs_open(path, O_RDONLY, 0);
if (res < 0) {
return false;
}
vfs_close(res);
return true;
}
/**
* @brief Removes additional "/" slashes from @p path
*