summaryrefslogtreecommitdiffabout
path: root/libid3tag
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-15 21:10:01 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-03-15 21:10:01 (GMT)
commit3a27428194f866050472b0f7c7b9e55b19cec230 (patch) (side-by-side diff)
tree0207e9f21036bcb1b2a7fe3edf11b9ad761e2768 /libid3tag
parentf6c2e714cc84ad327cf661967cdb024f835dd1c1 (diff)
downloadidest-3a27428194f866050472b0f7c7b9e55b19cec230.tar.gz
idest-3a27428194f866050472b0f7c7b9e55b19cec230.tar.bz2
Remove old v1 code. Add an option for converting tags to v1.
* libid3tag/file.c (SIZE_T_MAX): Rename to MALLOC_MAX. Use (size_t_max-1), due to a bug in glibc's malloc. (make_temp_file): Fix size calculation (memory overrun). (v2_write): data and/or length can be 0. (id3_file_update): Drop v2 header, if ID3_TAG_OPTION_NO_ID3V2 is set. * libid3tag/id3tag.h (ID3_TAG_OPTION_NO_ID3V2): New constant. * src/id3v1.c, src/id3v1.h: Remove. * src/id3v2.c: Rename to... * src/idop.c: ... this. (set_tags): Handle convert_version and version_option. * src/Makefile.am: Reflect the above. * src/cmdline.opt (--convert, -C): New option. * src/idest.h: Kick off id3v1.h. (convert_version, version_option): new externs. (set_id3v1, query_id3v1, del_id3v1) (set_id3v2, query_id3v2, del_id3v2): Remove. (set_tags, query_tags, del_tags): New prototypes. * src/main.c (convert_version): New variable. (query_id3): use all_frames to determine ed_list. (set_id3): Remove old v1 code. (main): Remove old v1 code.
Diffstat (limited to 'libid3tag') (more/less context) (ignore whitespace changes)
-rw-r--r--libid3tag/file.c47
-rw-r--r--libid3tag/id3tag.h3
2 files changed, 29 insertions, 21 deletions
diff --git a/libid3tag/file.c b/libid3tag/file.c
index 1ba2931..5ad025b 100644
--- a/libid3tag/file.c
+++ b/libid3tag/file.c
@@ -583,7 +583,7 @@ alloc_buf(size_t *pbufsize)
return buf;
}
-#define SIZE_T_MAX ((size_t)~0)
+#define MALLOC_MAX (((size_t)~0) - 1)
#define TNAME "ID3.XXXXXX"
@@ -601,7 +601,7 @@ make_temp_file(struct id3_file *file, char **pname)
p = strrchr(file->path, '/');
if (p) {
size_t len = p - file->path + 1;
- template = malloc(len + sizeof(TNAME) - 1);
+ template = malloc(len + sizeof(TNAME));
if (!template)
return NULL;
memcpy(template, file->path, len);
@@ -645,8 +645,8 @@ copy_block(FILE *inf, FILE *outf, off_t start, off_t size)
if (size == 0)
return 0;
- if (size < 0 || size > SIZE_T_MAX)
- bufsize = SIZE_T_MAX;
+ if (size < 0 || size > MALLOC_MAX)
+ bufsize = MALLOC_MAX;
else
bufsize = size;
@@ -679,8 +679,6 @@ int v2_write(struct id3_file *file,
{
int rc;
- assert(!data || length > 0);
-
if (data &&
((file->ntags == 1 && !(file->flags & ID3_FILE_FLAG_ID3V1)) ||
(file->ntags == 2 && (file->flags & ID3_FILE_FLAG_ID3V1))) &&
@@ -708,7 +706,11 @@ int v2_write(struct id3_file *file,
rc = copy_block(file->iofile, tmp, 0, file->tags[0].location);
if (rc == 0) {
- rc = fwrite(data, length, 1, tmp) != 1;
+ if (data && length)
+ rc = fwrite(data, length, 1, tmp) != 1;
+ else
+ rc = 0;
+
if (rc == 0)
rc = copy_block(file->iofile, tmp,
file->tags[0].location + file->tags[0].length, -1);
@@ -766,20 +768,25 @@ int id3_file_update(struct id3_file *file)
/* render ID3v2 */
- id3_tag_options(file->primary, ID3_TAG_OPTION_ID3V1, 0);
-
- v2size = id3_tag_render(file->primary, 0);
- if (v2size) {
- id3v2 = malloc(v2size);
- if (id3v2 == 0)
- goto fail;
-
- v2size = id3_tag_render(file->primary, id3v2);
- if (v2size == 0) {
- free(id3v2);
- id3v2 = 0;
+ if (options & ID3_TAG_OPTION_NO_ID3V2)
+ id3v2 = NULL;
+ else
+ {
+ id3_tag_options(file->primary, ID3_TAG_OPTION_ID3V1, 0);
+
+ v2size = id3_tag_render(file->primary, 0);
+ if (v2size) {
+ id3v2 = malloc(v2size);
+ if (id3v2 == 0)
+ goto fail;
+
+ v2size = id3_tag_render(file->primary, id3v2);
+ if (v2size == 0) {
+ free(id3v2);
+ id3v2 = 0;
+ }
+ }
}
- }
/* write tags */
diff --git a/libid3tag/id3tag.h b/libid3tag/id3tag.h
index 4f4c681..57c7190 100644
--- a/libid3tag/id3tag.h
+++ b/libid3tag/id3tag.h
@@ -139,7 +139,8 @@ enum {
ID3_TAG_OPTION_APPENDEDTAG = 0x0010, /* tag will be appended */
ID3_TAG_OPTION_FILEALTERED = 0x0020, /* audio data was altered */
- ID3_TAG_OPTION_ID3V1 = 0x0100 /* render ID3v1/ID3v1.1 tag */
+ ID3_TAG_OPTION_ID3V1 = 0x0100, /* render ID3v1/ID3v1.1 tag */
+ ID3_TAG_OPTION_NO_ID3V2 = 0x0200, /* do not render ID3v2 tag */
};
struct id3_frame {

Return to:

Send suggestions and report system problems to the System administrator.