From 00568ce0f6bfe0a1920257212da44e97e2eb7896 Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Sun, 12 Jun 2022 22:32:57 +0500 Subject: [PATCH] Fix --- src/utils.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/utils.c b/src/utils.c index 39135bd..79c9fb8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -144,16 +145,17 @@ int mkpath(char* file_path, mode_t mode) const char *get_ext(const char *path) { - const char *base; + const char *dot = NULL, *s = path + strlen(path) - 1; - if ((base = strrchr(path, '/'))) - base++; - else - base = path; + for (; ; s--) { + if (*s == '.') { + dot = s + 1; + continue; + } - const char *dot = strchr(base, '.'); - if (!dot || dot == base) - return NULL; + if (!isalnum(*s) || s == path) + break; + } - return &dot[1]; + return dot; }