Add some extra streamfile helpers

This commit is contained in:
bnnm 2018-08-04 20:42:00 +02:00
parent 6384b91f8f
commit 0fc5b466c8
2 changed files with 22 additions and 0 deletions

View File

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

View File

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