diff --git a/src/streamfile.c b/src/streamfile.c index bde4973a..3019b35f 100644 --- a/src/streamfile.c +++ b/src/streamfile.c @@ -772,6 +772,10 @@ fail: /* **************************************************** */ +STREAMFILE * open_streamfile(STREAMFILE *streamFile, const char * pathname) { + return streamFile->open(streamFile,pathname,STREAMFILE_DEFAULT_BUFFER_SIZE); +} + STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext) { char filename_ext[PATH_LIMIT]; @@ -1035,6 +1039,7 @@ int find_chunk(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, in return 0; } +/* copies name as-is (may include full path included) */ void get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size) { streamFile->get_name(streamFile,buffer,size); } @@ -1060,6 +1065,18 @@ void get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size) strcpy(buffer, foldername); } } +/* copies the filename without path or extension */ +void get_streamfile_basename(STREAMFILE *streamFile, char * buffer, size_t size) { + char *ext; + + get_streamfile_filename(streamFile,buffer,size); + + ext = strrchr(buffer,'.'); + if (ext) { + ext[0] = '\0'; /* remove .ext from buffer */ + } +} +/* copies path removing name (NULL when if filename has no path) */ void get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size) { const char *path; diff --git a/src/streamfile.h b/src/streamfile.h index f7a3949f..9a674662 100644 --- a/src/streamfile.h +++ b/src/streamfile.h @@ -98,6 +98,10 @@ STREAMFILE *open_fakename_streamfile(STREAMFILE *streamfile, const char * fakena * The first streamfile is used to get names, stream index and so on. */ STREAMFILE *open_multifile_streamfile(STREAMFILE **streamfiles, size_t streamfiles_size); +/* Opens a STREAMFILE from a (path)+filename. + * Just a wrapper, to avoid having to access the STREAMFILE's callbacks directly. */ +STREAMFILE * open_streamfile(STREAMFILE *streamFile, const char * pathname); + /* Opens a STREAMFILE from a base pathname + new extension * Can be used to get companion headers. */ STREAMFILE * open_streamfile_by_ext(STREAMFILE *streamFile, const char * ext); @@ -197,6 +201,7 @@ int find_chunk(STREAMFILE *streamFile, uint32_t chunk_id, off_t start_offset, in void get_streamfile_name(STREAMFILE *streamFile, char * buffer, size_t size); void get_streamfile_filename(STREAMFILE *streamFile, char * buffer, size_t size); +void get_streamfile_basename(STREAMFILE *streamFile, char * buffer, size_t size); void get_streamfile_path(STREAMFILE *streamFile, char * buffer, size_t size); void get_streamfile_ext(STREAMFILE *streamFile, char * filename, size_t size); #endif