rendered paste bodyIndex: src/flac/vorbiscomment.c
===================================================================
RCS file: /cvsroot/flac/flac/src/flac/vorbiscomment.c,v
retrieving revision 1.7
diff -u -r1.7 vorbiscomment.c
--- src/flac/vorbiscomment.c 25 Jan 2005 04:18:29 -0000 1.7
+++ src/flac/vorbiscomment.c 30 Oct 2005 02:25:28 -0000
@@ -59,6 +59,45 @@
return ret;
}
+ static char *read_comment_from_file(char *filename, const char **violation)
+ {
+ FILE *file;
+ long file_length;
+ char *file_buffer;
+ int i;
+
+ FLAC__ASSERT(0 != filename);
+
+ file = fopen(filename, "rb");
+ if (0 == file) {
+ *violation = "could not open tag data file for reading";
+ return 0;
+ }
+ fseek(file, 0L, SEEK_END);
+ file_length = ftell(file);
+ rewind(file);
+
+ if (0 == file_length) {
+ *violation = "tag data file contains no data";
+ fclose(file);
+ return 0;
+ }
+
+ file_buffer = malloc(file_length);
+ if (0 == file_buffer) {
+ die("out of memory during read_comment_from_file()");
+ }
+
+ for (i = 0; i < file_length-1; i++) {
+ file_buffer[i] = getc(file);
+ }
+ file_buffer[i] = '\0';
+
+ fclose(file);
+
+ return(file_buffer);
+ }
+
static FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, unsigned *length, const char **violation)
{
static const char * const violations[] = {
@@ -88,9 +127,26 @@
}
}
+ if (*p == '@') {
+ *name = local_strdup(s);
+ *value = read_comment_from_file(++p, violation);
+ if (*value == 0) {
+ free(s);
+ return false;
+ }
+ *length = strlen(*value);
+
+ // reconstruct field from file data
+ free(*field);
+ *field = malloc(strlen(*name) + 1 + strlen(*value));
+ strcpy(*field, *name);
+ strcat(*field, "=");
+ strcat(*field, *value);
+ } else {
*name = local_strdup(s);
*value = local_strdup(p);
*length = strlen(p);
+ }
free(s);
return true;
Index: src/metaflac/utils.c
===================================================================
RCS file: /cvsroot/flac/flac/src/metaflac/utils.c,v
retrieving revision 1.10
diff -u -r1.10 utils.c
--- src/metaflac/utils.c 24 Aug 2005 07:39:25 -0000 1.10
+++ src/metaflac/utils.c 30 Oct 2005 02:25:29 -0000
@@ -175,6 +175,45 @@
}
}
+ static char *read_comment_from_file(char *filename, const char **violation)
+ {
+ FILE *file;
+ long file_length;
+ char *file_buffer;
+ int i;
+
+ FLAC__ASSERT(0 != filename);
+
+ file = fopen(filename, "rb");
+ if (0 == file) {
+ *violation = "could not open tag data file for reading";
+ return 0;
+ }
+ fseek(file, 0L, SEEK_END);
+ file_length = ftell(file);
+ rewind(file);
+
+ if (0 == file_length) {
+ *violation = "tag data file contains no data";
+ fclose(file);
+ return 0;
+ }
+
+ file_buffer = malloc(file_length);
+ if (0 == file_buffer) {
+ die("out of memory during read_comment_from_file()");
+ }
+
+ for (i = 0; i < file_length-1; i++) {
+ file_buffer[i] = getc(file);
+ }
+ file_buffer[i] = '\0';
+
+ fclose(file);
+
+ return(file_buffer);
+ }
+
FLAC__bool parse_vorbis_comment_field(const char *field_ref, char **field, char **name, char **value, unsigned *length, const char **violation)
{
static const char * const violations[] = {
@@ -204,9 +243,26 @@
}
}
+ if (*p == '@') {
+ *name = local_strdup(s);
+ *value = read_comment_from_file(++p, violation);
+ if (*value == 0) {
+ free(s);
+ return false;
+ }
+ *length = strlen(*value);
+
+ // reconstruct field from file data
+ free(*field);
+ *field = malloc(strlen(*name) + 1 + strlen(*value));
+ strcpy(*field, *name);
+ strcat(*field, "=");
+ strcat(*field, *value);
+ } else {
*name = local_strdup(s);
*value = local_strdup(p);
*length = strlen(p);
+ }
free(s);
return true;