From 15ca1850528b0c67a5877652155650866ebb75e8 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 25 Feb 2018 16:27:48 +0100 Subject: [PATCH] Add util to get base filename without path --- src/streamfile.c | 23 +++++++++++++++++++++++ src/streamfile.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/streamfile.c b/src/streamfile.c index f62b7842..c664a28d 100644 --- a/src/streamfile.c +++ b/src/streamfile.c @@ -993,6 +993,29 @@ int get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size) { streamFile->get_name(streamFile,buffer,size); return 1; } +int get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size) { + char foldername[PATH_LIMIT]; + const char *path; + + streamFile->get_name(streamFile,foldername,sizeof(foldername)); + + //todo Windows CMD accepts both \\ and /, better way to handle this? + path = strrchr(foldername,'\\'); + if (!path) + path = strrchr(foldername,'/'); + if (path != NULL) + path = path+1; + + //todo validate sizes and copy sensible max + if (path) { + VGM_LOG("path\n"); + strcpy(buffer, path); + } else { + VGM_LOG("no path\n"); + strcpy(buffer, foldername); + } + return 1; +} int get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size) { const char *path; diff --git a/src/streamfile.h b/src/streamfile.h index 49818e9c..6841b939 100644 --- a/src/streamfile.h +++ b/src/streamfile.h @@ -179,6 +179,7 @@ int find_chunk_le(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, int find_chunk(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, int full_chunk_size, off_t *out_chunk_offset, size_t *out_chunk_size, int size_big_endian, int zero_size_end); int get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size); +int get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size); int get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size); int get_streamfile_ext(STREAMFILE *streamFile, char * filename, size_t size); #endif