From 7ebf15543b3cf0ec41b7a342184de0168faa24bb Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 4 May 2013 19:33:14 +0200 Subject: [PATCH] Use strrchr in file_get_extension Signed-off-by: Sebastian Ramacher --- utils.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/utils.c b/utils.c index 26a07cd..7c462b3 100644 --- a/utils.c +++ b/utils.c @@ -29,24 +29,16 @@ const char* file_get_extension(const char* path) { - if (!path) { + if (path == NULL) { return NULL; } - unsigned int i = strlen(path); - for (; i > 0; i--) { - if (*(path + i) != '.') { - continue; - } else { - break; - } - } - - if (!i) { + const char* res = strrchr(path, '.'); + if (res == NULL) { return NULL; } - return path + i + 1; + return res + 1; } bool