mp3: Add support for id3 version 2 tags.
[paraslash.git] / afh.c
diff --git a/afh.c b/afh.c
index 86f34ac..454517f 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -60,22 +60,30 @@ static int cat_file(void *audio_file_data, struct afh_info *afhi)
        int ret;
        struct timeval stream_start;
        long unsigned i, first_chunk, last_chunk;
        int ret;
        struct timeval stream_start;
        long unsigned i, first_chunk, last_chunk;
-       char *buf;
+       const char *buf;
        size_t size;
 
 
        size_t size;
 
 
-       if (conf.begin_chunk_arg < 0)
-               return -ERRNO_TO_PARA_ERROR(EINVAL);
-       first_chunk = conf.begin_chunk_arg;
-
-       if (conf.end_chunk_given) {
-               if (conf.end_chunk_arg < 0)
-                       return -ERRNO_TO_PARA_ERROR(EINVAL);
-               if (conf.end_chunk_arg >= afhi->chunks_total)
+       if (conf.begin_chunk_arg < 0) {
+               if (-conf.begin_chunk_arg > afhi->chunks_total)
                        return -ERRNO_TO_PARA_ERROR(EINVAL);
                        return -ERRNO_TO_PARA_ERROR(EINVAL);
-               last_chunk = conf.end_chunk_arg;
+               first_chunk = afhi->chunks_total + conf.begin_chunk_arg;
+       } else
+               first_chunk = conf.begin_chunk_arg;
+       if (conf.end_chunk_given) {
+               if (conf.end_chunk_arg < 0) {
+                       if (-conf.end_chunk_arg > afhi->chunks_total)
+                               return -ERRNO_TO_PARA_ERROR(EINVAL);
+                       last_chunk = afhi->chunks_total + conf.end_chunk_arg;
+               } else {
+                       if (conf.end_chunk_arg >= afhi->chunks_total)
+                               return -ERRNO_TO_PARA_ERROR(EINVAL);
+                       last_chunk = conf.end_chunk_arg;
+               }
        } else
                last_chunk = afhi->chunks_total - 1;
        } else
                last_chunk = afhi->chunks_total - 1;
+       if (first_chunk >= last_chunk)
+               return -ERRNO_TO_PARA_ERROR(EINVAL);
        if (!afhi->chunks_total)
                return 1;
        afh_get_header(afhi, audio_file_data, &buf, &size);
        if (!afhi->chunks_total)
                return 1;
        afh_get_header(afhi, audio_file_data, &buf, &size);
@@ -114,7 +122,7 @@ static int cat_file(void *audio_file_data, struct afh_info *afhi)
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
-       int ret, audio_format_num;
+       int ret, audio_format_num, fd;
        void *audio_file_data;
        size_t audio_file_size;
        struct afh_info afhi;
        void *audio_file_data;
        size_t audio_file_size;
        struct afh_info afhi;
@@ -126,10 +134,11 @@ int main(int argc, char **argv)
                goto out;
        afh_init();
        ret = mmap_full_file(conf.inputs[0], O_RDONLY, &audio_file_data,
                goto out;
        afh_init();
        ret = mmap_full_file(conf.inputs[0], O_RDONLY, &audio_file_data,
-               &audio_file_size, NULL);
+               &audio_file_size, &fd);
        if (ret < 0)
                goto out;
        if (ret < 0)
                goto out;
-       ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size, &afhi);
+       ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size,
+               fd, &afhi);
        if (ret < 0)
                goto out;
        audio_format_num = ret;
        if (ret < 0)
                goto out;
        audio_format_num = ret;