mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 18:13:49 +01:00
sys/vfs_util: add vfs_file_exists()
This commit is contained in:
parent
469c919969
commit
9c4ca01e24
@ -20,6 +20,9 @@
|
|||||||
#ifndef VFS_UTIL_H
|
#ifndef VFS_UTIL_H
|
||||||
#define VFS_UTIL_H
|
#define VFS_UTIL_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -115,6 +118,15 @@ int vfs_file_sha256(const char* file, void *digest,
|
|||||||
*/
|
*/
|
||||||
int vfs_is_dir(const char *path);
|
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`.
|
* @brief Behaves like `rm -r @p root`.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -171,6 +171,17 @@ int vfs_is_dir(const char *path)
|
|||||||
return ((stat.st_mode & S_IFMT) == S_IFDIR);
|
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
|
* @brief Removes additional "/" slashes from @p path
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user