From 9948eee6c2fe0e07646f570793283c5af26b68db Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 15 Jun 2016 16:18:56 -0700 Subject: [PATCH] libobs/util: Add function to get path extension --- libobs/util/platform.c | 23 +++++++++++++++++++++++ libobs/util/platform.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/libobs/util/platform.c b/libobs/util/platform.c index af031e60b..ffccf8ab2 100644 --- a/libobs/util/platform.c +++ b/libobs/util/platform.c @@ -633,3 +633,26 @@ int os_mkdirs(const char *dir) dstr_free(&dir_str); return ret; } + +const char *os_get_path_extension(const char *path) +{ + struct dstr temp; + size_t pos = 0; + char *period; + char *slash; + + dstr_init_copy(&temp, path); + dstr_replace(&temp, "\\", "/"); + + slash = strrchr(temp.array, '/'); + period = strrchr(temp.array, '.'); + if (period) + pos = (size_t)(period - temp.array); + + dstr_free(&temp); + + if (!period || slash > period) + return NULL; + + return path + pos; +} diff --git a/libobs/util/platform.h b/libobs/util/platform.h index 808171723..78fc40df3 100644 --- a/libobs/util/platform.h +++ b/libobs/util/platform.h @@ -113,6 +113,8 @@ EXPORT bool os_file_exists(const char *path); EXPORT size_t os_get_abs_path(const char *path, char *abspath, size_t size); EXPORT char *os_get_abs_path_ptr(const char *path); +EXPORT const char *os_get_path_extension(const char *path); + struct os_dir; typedef struct os_dir os_dir_t;