Bulk update copyright dates
[flac.git] / src / share / grabbag / seektable.c
index 3ee6374..01118d5 100644 (file)
@@ -1,5 +1,6 @@
 /* grabbag - Convenience lib for various routines common to several tools
- * Copyright (C) 2002,2003,2004,2005,2006  Josh Coalson
+ * Copyright (C) 2002-2009  Josh Coalson
+ * Copyright (C) 2011-2016  Xiph.Org Foundation
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
 #include "share/grabbag.h"
+#include "share/compat.h"
 #include "FLAC/assert.h"
 #include <stdlib.h> /* for atoi() */
 #include <string.h>
 
-#ifdef _MSC_VER
-/* There's no strtoll() in MSVC6 so we just write a specialized one */
-static FLAC__int64 local__strtoll(const char *src, char **endptr)
-{
-       FLAC__bool neg = false;
-       FLAC__int64 ret = 0;
-       int c;
-       FLAC__ASSERT(0 != src);
-       if(*src == '-') {
-               neg = true;
-               src++;
-       }
-       while(0 != (c = *src)) {
-               c -= '0';
-               if(c >= 0 && c <= 9)
-                       ret = (ret * 10) + c;
-               else
-                       break;
-               src++;
-       }
-       if(endptr)
-               *endptr = (char*)src;
-       return neg? -ret : ret;
-}
-#endif
-
 FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec, FLAC__bool only_explicit_placeholders, FLAC__uint64 total_samples_to_encode, unsigned sample_rate, FLAC__StreamMetadata *seektable_template, FLAC__bool *spec_has_real_points)
 {
        unsigned i;
@@ -58,7 +34,7 @@ FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec
 
        FLAC__ASSERT(0 != spec);
        FLAC__ASSERT(0 != seektable_template);
-       FLAC__ASSERT(seektable_template->type = FLAC__METADATA_TYPE_SEEKTABLE);
+       FLAC__ASSERT(seektable_template->type == FLAC__METADATA_TYPE_SEEKTABLE);
 
        if(0 != spec_has_real_points)
                *spec_has_real_points = false;
@@ -93,6 +69,8 @@ FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec
                                                const double sec = atof(pt);
                                                if(sec > 0.0) {
                                                        unsigned samples = (unsigned)(sec * (double)sample_rate);
+                                                       /* Restrict seekpoints to two per second of audio. */
+                                                       samples = samples < sample_rate / 2 ? sample_rate / 2 : samples;
                                                        if(samples > 0) {
                                                                /* +1 for the initial point at sample 0 */
                                                                if(!FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(seektable_template, samples, total_samples_to_encode))
@@ -107,11 +85,7 @@ FLAC__bool grabbag__seektable_convert_specification_to_template(const char *spec
                                        *spec_has_real_points = true;
                                if(!only_explicit_placeholders) {
                                        char *endptr;
-#ifdef _MSC_VER
-                                       const FLAC__int64 n = local__strtoll(pt, &endptr);
-#else
                                        const FLAC__int64 n = (FLAC__int64)strtoll(pt, &endptr, 10);
-#endif
                                        if(
                                                (n > 0 || (endptr > pt && *endptr == ';')) && /* is a valid number (extra check needed for "0") */
                                                (total_samples_to_encode == 0 || (FLAC__uint64)n < total_samples_to_encode) /* number is not >= the known total_samples_to_encode */