Add util to get base filename without path

This commit is contained in:
bnnm 2018-02-25 16:27:48 +01:00
parent 494dfb8194
commit 15ca185052
2 changed files with 24 additions and 0 deletions

View File

@ -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;

View File

@ -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