hermes

HTTP GET/HEAD-only web server for static content.
git clone git://git.francescosaccone.com/hermes
Log | Files | Refs | README | LICENSE

commit 7751002f4f97766dd613e97068f9f53ac2acb90c
parent ee1b8836e6c86b2b962c15f364a8277194bea92f
Author: Francesco Saccone <francesco@francescosaccone.com>
Date:   Tue,  1 Apr 2025 10:53:50 +0200

feat: add get_file_extension function

Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>

Diffstat:
Mfile.c | 12++++++++++++
Mfile.h | 3+++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/file.c b/file.c @@ -62,6 +62,18 @@ get_file_name(char *path) { return character_after_last_slash; } +char * +get_file_extension(char *path) { + char *file_name = get_file_name(path), + *last_dot = strrchr(file_name, '.'); + + if (last_dot == NULL) { + return ""; + } + + return last_dot + sizeof(char); +} + struct file_content get_file_content(char *path) { struct file_content result = { NULL, 0 }; diff --git a/file.h b/file.h @@ -42,6 +42,9 @@ get_normalised_path(char *path); char * get_file_name(char *path); +char * +get_file_extension(char *path); + /* * It returns the file_content instances of the file at given path. *