From ad0a4609231a69d3c7da666ff7a7a73d68eeb72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Sun, 6 Aug 2023 12:06:43 +0200 Subject: [PATCH] feat: add filesystem_exists --- lib/filesystem.c | 4 ++++ lib/filesystem.h | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/filesystem.c b/lib/filesystem.c index 65d8e91..c714b10 100644 --- a/lib/filesystem.c +++ b/lib/filesystem.c @@ -27,6 +27,10 @@ int filesystem_write(string_t path, byte_t *file_content, off_t file_size) { return 0; } +bool filesystem_exists(string_t path) { + return access(path, F_OK) == 0; +} + string_t filesystem_get_mimetype(string_t path) { if (string_ends_with(path, ".html")) { return "text/html"; diff --git a/lib/filesystem.h b/lib/filesystem.h index 21c9990..94df9ab 100644 --- a/lib/filesystem.h +++ b/lib/filesystem.h @@ -37,6 +37,16 @@ int filesystem_read(string_t path, byte_t **file_content, off_t *file_size); */ int filesystem_write(string_t path, byte_t *file_content, off_t file_size); +/** + * @brief Check if a path exists. + * + * @param path + * @retval true if the path exists. + * @retval false if the path does not exist. + * @since v3.1.0 + */ +bool filesystem_exists(string_t path); + /** * @brief Get the mimetype of a file. *