diff options
author | Max Kellermann <max@duempel.org> | 2016-02-21 07:14:04 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2016-02-21 07:14:04 +0100 |
commit | 054e9ecaaebe6a8536c894c5093bdce99577e51f (patch) | |
tree | 562ced8f19b36e63e84ff8260cbb314d2e0bad1c | |
parent | 84fe3bfa8799847d496094476fefcc0d7298bf6d (diff) |
tag/Id3Load: split tag_id3_read()
-rw-r--r-- | src/tag/Id3Load.cxx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/tag/Id3Load.cxx b/src/tag/Id3Load.cxx index d723b50a5..b39ce3d11 100644 --- a/src/tag/Id3Load.cxx +++ b/src/tag/Id3Load.cxx @@ -60,13 +60,12 @@ get_id3v2_footer_size(FILE *stream, long offset, int whence) } static UniqueId3Tag -tag_id3_read(FILE *stream, long offset, int whence) +ReadId3Tag(FILE *file) { - /* It's ok if we get less than we asked for */ id3_byte_t query_buffer[ID3_TAG_QUERYSIZE]; - size_t query_buffer_size = fill_buffer(query_buffer, ID3_TAG_QUERYSIZE, - stream, offset, whence); - if (query_buffer_size <= 0) + size_t query_buffer_size = fread(query_buffer, 1, sizeof(query_buffer), + file); + if (query_buffer_size == 0) return nullptr; /* Look for a tag header */ @@ -87,7 +86,7 @@ tag_id3_read(FILE *stream, long offset, int whence) /* now read the remaining bytes */ const size_t remaining = tag_size - query_buffer_size; - const size_t nbytes = fread(end, 1, remaining, stream); + const size_t nbytes = fread(end, 1, remaining, file); if (nbytes != remaining) return nullptr; @@ -95,6 +94,15 @@ tag_id3_read(FILE *stream, long offset, int whence) } static UniqueId3Tag +tag_id3_read(FILE *file, long offset, int whence) +{ + if (fseek(file, offset, whence) != 0) + return 0; + + return ReadId3Tag(file); +} + +static UniqueId3Tag tag_id3_find_from_beginning(FILE *stream) { auto tag = tag_id3_read(stream, 0, SEEK_SET); |