From 49743d4b9ea8f0cd6581cad11836b7e50f897e38 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Mon, 20 Feb 2023 12:18:57 +0100 Subject: [PATCH] Add path_filename() --- src/emu/path.c | 12 ++++++++++++ src/emu/path.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/emu/path.c b/src/emu/path.c index a53362e..04719aa 100644 --- a/src/emu/path.c +++ b/src/emu/path.c @@ -100,3 +100,15 @@ path_remove_trailing(char *path) path[i] = '\0'; } } + +const char * +path_filename(const char *path) +{ + const char *start = strrchr(path, '/'); + if (start == NULL) + start = path; + else + start++; + + return start; +} diff --git a/src/emu/path.h b/src/emu/path.h index 7eb863d..486542e 100644 --- a/src/emu/path.h +++ b/src/emu/path.h @@ -10,5 +10,6 @@ int path_next(const char *path, char sep, const char (**next)); int path_keep(char *path, int n); int path_strip(const char *path, int n, const char (**next)); void path_remove_trailing(char *path); +const char *path_filename(const char *path); #endif /* PATH_H */