aboutsummaryrefslogtreecommitdiff
path: root/src/tag_id3.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-04-23 22:51:45 +0200
committerMax Kellermann <max@duempel.org>2012-04-23 22:51:45 +0200
commit404fa8993714f59f8708a3ce937248bab9bdc3f2 (patch)
tree652bb06648373b59a26fb55dae3b1663f75bec8c /src/tag_id3.c
parent89377556cdd20bdc8cdb5861f271164b1cba6ecf (diff)
tag_id3: export tag_id3_load()
Diffstat (limited to 'src/tag_id3.c')
-rw-r--r--src/tag_id3.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/tag_id3.c b/src/tag_id3.c
index c98179f0..0971829f 100644
--- a/src/tag_id3.c
+++ b/src/tag_id3.c
@@ -541,30 +541,42 @@ tag_id3_riff_aiff_load(FILE *file)
return tag;
}
-bool
-tag_id3_scan(const char *path_fs,
- const struct tag_handler *handler, void *handler_ctx)
+struct id3_tag *
+tag_id3_load(const char *path_fs, GError **error_r)
{
- struct id3_tag *tag;
- FILE *stream;
+ FILE *file = fopen(path_fs, "rb");
+ if (file == NULL) {
+ g_set_error(error_r, g_file_error_quark(), errno,
+ "Failed to open file %s: %s",
+ path_fs, g_strerror(errno));
+ return NULL;
+ }
- stream = fopen(path_fs, "rb");
- if (!stream) {
- g_debug("tag_id3_load: Failed to open file: '%s', %s",
- path_fs, g_strerror(errno));
- return false;
+ struct id3_tag *tag = tag_id3_find_from_beginning(file);
+ if (tag == NULL) {
+ tag = tag_id3_riff_aiff_load(file);
+ if (tag == NULL)
+ tag = tag_id3_find_from_end(file);
}
- tag = tag_id3_find_from_beginning(stream);
- if (tag == NULL)
- tag = tag_id3_riff_aiff_load(stream);
- if (!tag)
- tag = tag_id3_find_from_end(stream);
+ fclose(file);
+ return tag;
+}
- fclose(stream);
+bool
+tag_id3_scan(const char *path_fs,
+ const struct tag_handler *handler, void *handler_ctx)
+{
+ GError *error = NULL;
+ struct id3_tag *tag = tag_id3_load(path_fs, &error);
+ if (tag == NULL) {
+ if (error != NULL) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ }
- if (!tag)
return false;
+ }
scan_id3_tag(tag, handler, handler_ctx);
id3_tag_delete(tag);