[easytag] Use ID3V1_TAG_SIZE define consistently
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Use ID3V1_TAG_SIZE define consistently
- Date: Mon, 14 Nov 2016 23:35:35 +0000 (UTC)
commit 756412dcfee019a46b3f13e34cef362295324397
Author: David King <amigadave amigadave com>
Date: Fri Nov 11 18:36:45 2016 +0000
Use ID3V1_TAG_SIZE define consistently
src/crc32.c | 10 ++++++----
src/tags/id3_tag.h | 1 +
src/tags/id3v24_tag.c | 1 -
src/tags/libapetag/apetaglib.c | 18 ++++++++++--------
src/tags/libapetag/is_tag.c | 9 +++++----
5 files changed, 22 insertions(+), 17 deletions(-)
---
diff --git a/src/crc32.c b/src/crc32.c
index 2fc91a6..85032ae 100644
--- a/src/crc32.c
+++ b/src/crc32.c
@@ -19,6 +19,7 @@
*/
#include "crc32.h"
+#include "id3_tag.h"
#define BUFFERSIZE 16384 /* (16k) buffer size for reading from the file */
@@ -140,7 +141,8 @@ crc32_file_with_ID3_tag (GFile *file,
}
/* Check if there is an ID3v1 tag. */
- if (!g_seekable_seek (G_SEEKABLE (istream), -128, G_SEEK_END, NULL, err))
+ if (!g_seekable_seek (G_SEEKABLE (istream), -ID3V1_TAG_SIZE, G_SEEK_END,
+ NULL, err))
{
goto error;
}
@@ -217,16 +219,16 @@ crc32_file_with_ID3_tag (GFile *file,
while ((nr = g_input_stream_read (G_INPUT_STREAM (istream), buf,
sizeof (buf), NULL, err)) > 0)
{
- if (has_id3v1 && nr <= 128)
+ if (has_id3v1 && nr <= ID3V1_TAG_SIZE)
/* Reading the end of an ID3v1 tag. */
{
break;
}
- if (has_id3v1 && ((size = size - nr) < 128))
+ if (has_id3v1 && ((size = size - nr) < ID3V1_TAG_SIZE))
{
/* ID3v1 tag is in the current buf. */
- nr = nr - 128 + size;
+ nr = nr - ID3V1_TAG_SIZE + size;
}
for (p = buf; nr--; ++p)
diff --git a/src/tags/id3_tag.h b/src/tags/id3_tag.h
index 13ffda4..d7ace40 100644
--- a/src/tags/id3_tag.h
+++ b/src/tags/id3_tag.h
@@ -26,6 +26,7 @@
G_BEGIN_DECLS
#define ID3_INVALID_GENRE 255
+#define ID3V1_TAG_SIZE 128
/*
* Error domain and codes for errors while reading/writing ID3 tags.
diff --git a/src/tags/id3v24_tag.c b/src/tags/id3v24_tag.c
index 43700f6..542181d 100644
--- a/src/tags/id3v24_tag.c
+++ b/src/tags/id3v24_tag.c
@@ -51,7 +51,6 @@
****************/
#define MULTIFIELD_SEPARATOR " - "
#define EASYTAG_STRING_ENCODEDBY "Encoded by"
-#define ID3V1_TAG_SIZE 128
enum {
EASYTAG_ID3_FIELD_LATIN1 = 0x0001,
diff --git a/src/tags/libapetag/apetaglib.c b/src/tags/libapetag/apetaglib.c
index 8b94e48..8001a8b 100644
--- a/src/tags/libapetag/apetaglib.c
+++ b/src/tags/libapetag/apetaglib.c
@@ -31,6 +31,7 @@
#endif
#include <glib/gstdio.h>
#include "apetaglib.h"
+#include "../id3_tag.h"
#include "../genres.h"
#include "../win32/win32dep.h"
@@ -606,7 +607,7 @@ readtag_id3v1_fp (apetag *mem_cnt, FILE * fp)
if (!is_id3v1(fp))
return 0; /* TODO:: 0 or no_id3v1*/
- fseek(fp, -128, SEEK_END);
+ fseek (fp, -ID3V1_TAG_SIZE, SEEK_END);
if (sizeof (struct _id3v1Tag)!=fread(&m, 1, sizeof (struct _id3v1Tag), fp)){
PRINT_ERR( "ERROR->libapetag->readtag_id3v1_fp:fread\n");
return ATL_FREAD;
@@ -714,7 +715,8 @@ apetag_read_fp(apetag *mem_cnt, FILE * fp, const char *filename, int flag)
return ATL_NOINIT;
}
- fseek(fp, id3v1 ? -128 - sizeof (ape_footer) : -sizeof (ape_footer), SEEK_END);
+ fseek (fp, id3v1 ? -ID3V1_TAG_SIZE - sizeof (ape_footer)
+ : -sizeof (ape_footer), SEEK_END);
if (sizeof (ape_footer) != fread(&ape_footer, 1, sizeof (ape_footer), fp)){
PRINT_ERR( "ERROR->libapetag->apetag_read_fp:fread1\n");
fseek(fp, savedFilePosition, SEEK_SET);
@@ -732,15 +734,15 @@ apetag_read_fp(apetag *mem_cnt, FILE * fp, const char *filename, int flag)
is_id3v1 (fp), is_id3v2 (fp), is_ape (fp), is_ape_ver (fp));
apeTag2 = ape2long(ape_footer.version);
- buffLength = is_ape(fp) + 128;
+ buffLength = is_ape(fp) + ID3V1_TAG_SIZE;
buff = (unsigned char *) malloc(buffLength);
if (buff == NULL) {
PRINT_ERR( "ERROR->libapetag->apetag_read_fp:malloc\n");
return ATL_MALOC;
}
- fseek(fp, id3v1 ? -ape2long(ape_footer.length) -
- 128 : -ape2long(ape_footer.length), SEEK_END);
+ fseek (fp, id3v1 ? -ape2long (ape_footer.length) -
+ ID3V1_TAG_SIZE : -ape2long (ape_footer.length), SEEK_END);
memset(buff, 0, buffLength);
if (ape2long(ape_footer.length) != fread(buff, 1, ape2long(ape_footer.length), fp)) {
PRINT_ERR( "ERROR->libapetag->apetag_read_fp:fread2\n");
@@ -915,7 +917,7 @@ apetag_save (const char *filename, apetag *mem_cnt, int flag)
saveApe2 = !(flag & APE_TAG_V1); // (flag & APE_TAG_V2) ? 1 : (flag & APE_TAG_V1);
if (id3v1) {
- fseek (fp, -128, SEEK_END);
+ fseek (fp, -ID3V1_TAG_SIZE, SEEK_END);
if (fread (&id3v1_tag, 1, sizeof (struct _id3v1Tag), fp)
!= sizeof (struct _id3v1Tag))
{
@@ -944,7 +946,7 @@ apetag_save (const char *filename, apetag *mem_cnt, int flag)
}
if (!!(flag & SAVE_CREATE_ID3V1_TAG )) {
make_id3v1_tag(mem_cnt, &id3v1_tag);
- tagSSize += 128;
+ tagSSize += ID3V1_TAG_SIZE;
}
//PRINT_D4 (">apetaglib>SAVE>>: size %li %i %i %i\n", tagSSize,
// mem_cnt->countTag, flag, saveApe2);
@@ -959,7 +961,7 @@ apetag_save (const char *filename, apetag *mem_cnt, int flag)
memcpy (ape_footer.id, "APETAGEX", sizeof (ape_footer.id));
long2ape (ape_footer.flags, 0l);
if (!!(flag & SAVE_CREATE_ID3V1_TAG ))
- long2ape (ape_footer.length, tagSSize-128);
+ long2ape (ape_footer.length, tagSSize - ID3V1_TAG_SIZE);
else
long2ape (ape_footer.length, tagSSize);
//long2ape(ape_footer.tagCount, mem_cnt->countTag);
diff --git a/src/tags/libapetag/is_tag.c b/src/tags/libapetag/is_tag.c
index 452c77c..7a6407a 100644
--- a/src/tags/libapetag/is_tag.c
+++ b/src/tags/libapetag/is_tag.c
@@ -26,6 +26,7 @@
#include <limits.h>
#include <assert.h>
#include "is_tag.h"
+#include "../id3_tag.h"
/*
PL: czy dany plik ma taga odpowiednio id3v1, id3v2 i ape ???
@@ -62,7 +63,7 @@ is_id3v1 (FILE * fp)
do {
n++;
memset (buf, 0, sizeof (buf));
- fseek (fp, ((-128)*n) - 3 , SEEK_END);
+ fseek (fp, ((-ID3V1_TAG_SIZE) * n) - 3, SEEK_END);
if (fread (&buf, 1, sizeof (buf), fp) != sizeof (buf))
{
fseek (fp, savedFilePosition, SEEK_SET);
@@ -73,7 +74,7 @@ is_id3v1 (FILE * fp)
} while (memcmp (buf+3, "TAG", 3) == 0);
fseek (fp, savedFilePosition, SEEK_SET);
- return (n-1)*128;
+ return (n - 1) * ID3V1_TAG_SIZE;
}
/**
@@ -129,7 +130,7 @@ is_ape_ver (FILE * fp)
savedFilePosition = ftell (fp);
memset (buf, 0, sizeof (buf));
- fseek (fp, (is_id3v1 (fp) ? -32 - 128 : -32), SEEK_END);
+ fseek (fp, (is_id3v1 (fp) ? -32 - ID3V1_TAG_SIZE : -32), SEEK_END);
if (fread (&buf, 1, sizeof (buf), fp) != sizeof (buf))
{
fseek (fp, savedFilePosition, SEEK_SET);
@@ -161,7 +162,7 @@ is_ape (FILE * fp)
savedFilePosition = ftell (fp);
memset (buf, 0, sizeof (buf));
- fseek (fp, (is_id3v1 (fp) ? -32 - 128 : -32), SEEK_END);
+ fseek (fp, (is_id3v1 (fp) ? -32 - ID3V1_TAG_SIZE : -32), SEEK_END);
if (fread (&buf, 1, sizeof (buf), fp) != sizeof (buf))
{
fseek (fp, savedFilePosition, SEEK_SET);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]