1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-11-13 23:43:13 +01:00

feat: add filesystem_exists

This commit is contained in:
Théo LUDWIG 2023-08-06 12:06:43 +02:00
parent be8a63ca8a
commit ad0a460923
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
2 changed files with 14 additions and 0 deletions

View File

@ -27,6 +27,10 @@ int filesystem_write(string_t path, byte_t *file_content, off_t file_size) {
return 0; return 0;
} }
bool filesystem_exists(string_t path) {
return access(path, F_OK) == 0;
}
string_t filesystem_get_mimetype(string_t path) { string_t filesystem_get_mimetype(string_t path) {
if (string_ends_with(path, ".html")) { if (string_ends_with(path, ".html")) {
return "text/html"; return "text/html";

View File

@ -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); 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. * @brief Get the mimetype of a file.
* *