shithub: sox

Download patch

ref: 8dc39989974b02ac069cce9d07ab6be51a5add3f
parent: b2986b68a40a0e99bd2d691689bbd2afe7359ddc
author: Chris Bagwell <chris@cnpbagwell.com>
date: Thu Mar 3 14:29:03 EST 2011

Convert filelength to off_t instead of size_t

Allows to work with > 4G files.  Patch from Thor Andreassen.

--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,10 @@
   o Improvements to man pages for tempo effect.  Really made in 14.3.2.
     (Jim Harkins).
 
+Other new features:
+
+  o Filelength display now uses 64-bit value to work with larger files.
+
 sox-14.3.2	2011-02-27
 ----------
 
--- a/src/formats_i.c
+++ b/src/formats_i.c
@@ -138,12 +138,12 @@
   return ret;
 }
 
-size_t lsx_filelength(sox_format_t * ft)
+off_t lsx_filelength(sox_format_t * ft)
 {
   struct stat st;
   int ret = fstat(fileno(ft->fp), &st);
 
-  return (!ret && (st.st_mode & S_IFREG))? (size_t)st.st_size : 0;
+  return (!ret && (st.st_mode & S_IFREG))? st.st_size : 0;
 }
 
 int lsx_flush(sox_format_t * ft)
--- a/src/skelform.c
+++ b/src/skelform.c
@@ -39,7 +39,7 @@
 static int startread(sox_format_t * ft)
 {
   priv_t * sk = (priv_t *)ft->priv;
-  size_t samples_in_file;
+  off_t samples_in_file;
 
   /* If you need to seek around the input file. */
   if (!ft->seekable) {
--- a/src/sox.c
+++ b/src/sox.c
@@ -190,9 +190,9 @@
 static sox_encodinginfo_t combiner_encoding, ofile_encoding_options;
 static size_t mixing_clips = 0;
 static size_t current_input = 0;
-static unsigned long input_wide_samples = 0;
-static unsigned long read_wide_samples = 0;
-static unsigned long output_samples = 0;
+static off_t input_wide_samples = 0;
+static off_t read_wide_samples = 0;
+static off_t output_samples = 0;
 static sox_bool input_eof = sox_false;
 static sox_bool output_eof = sox_false;
 static sox_bool user_abort = sox_false;
@@ -281,7 +281,7 @@
   FILE * const output = sox_mode == sox_soxi? stdout : stderr;
   char const * text, * text2 = NULL;
   char buffer[30];
-  size_t ws = ft->signal.length / ft->signal.channels;
+  off_t ws = ft->signal.length / ft->signal.channels;
   (void)full;
 
   fprintf(output, "\n");
@@ -376,13 +376,13 @@
     ft->signal.precision);
 
   if (ft->signal.length && ft->signal.channels && ft->signal.rate) {
-    size_t ws = ft->signal.length / ft->signal.channels;
+    off_t ws = ft->signal.length / ft->signal.channels;
     char const * text, * text2 = NULL;
     fprintf(output,
         "Duration       : %s = %lu samples %c %g CDDA sectors\n",
-        str_time((double)ws / ft->signal.rate),
-        (unsigned long)ws, "~="[ft->signal.rate == 44100],
-        (double)ws / ft->signal.rate * 44100 / 588);
+        str_time((double) ws / ft->signal.rate),
+        (off_t) ws, "~="[ft->signal.rate == 44100],
+        (double) ws / ft->signal.rate * 44100 / 588);
     if (ft->mode == 'r' && (text = size_and_bitrate(ft, &text2))) {
       fprintf(output, "File Size      : %s\n", text);
       if (text2)
@@ -487,7 +487,8 @@
 static int combiner_start(sox_effect_t *effp)
 {
   input_combiner_t * z = (input_combiner_t *) effp->priv;
-  size_t ws, i;
+  off_t ws;
+  size_t i;
 
   if (is_serial(combine_method))
     progress_to_next_input_file(files[current_input], effp);
--- a/src/sox.h
+++ b/src/sox.h
@@ -201,7 +201,7 @@
   sox_rate_t       rate;         /* sampling rate */
   unsigned         channels;     /* number of sound channels */
   unsigned         precision;    /* in bits */
-  size_t           length;       /* samples * chans in file */
+  off_t            length;       /* samples * chans in file */
   double           * mult;       /* Effects headroom multiplier; may be null */
 } sox_signalinfo_t;
 
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -198,7 +198,7 @@
 int lsx_flush(sox_format_t * ft);
 int lsx_seeki(sox_format_t * ft, off_t offset, int whence);
 int lsx_unreadb(sox_format_t * ft, unsigned ub);
-size_t lsx_filelength(sox_format_t * ft);
+off_t lsx_filelength(sox_format_t * ft);
 off_t lsx_tell(sox_format_t * ft);
 void lsx_clearerr(sox_format_t * ft);
 void lsx_rewind(sox_format_t * ft);
--- a/src/util.c
+++ b/src/util.c
@@ -119,17 +119,17 @@
   static char const symbols[] = "\0kMGTPEZY";
   static char string[16][10];   /* FIXME: not thread-safe */
   static unsigned n;            /* ditto */
-  unsigned a, b, c;
+  off_t a, b, c;
   sprintf(string[n = (n+1) & 15], "%#.3g", number);
-  switch (sscanf(string[n], "%u.%ue%u", &a, &b, &c)) {
+  switch (sscanf(string[n], "%lu.%lue%lu", &a, &b, &c)) {
     case 2: if (b) return string[n]; /* Can fall through */
     case 1: c = 2; break;
     case 3: a = 100*a + b; break;
   }
   if (c < array_length(symbols) * 3 - 3) switch (c%3) {
-    case 0: sprintf(string[n], "%u.%02u%c", a/100,a%100, symbols[c/3]); break;
-    case 1: sprintf(string[n], "%u.%u%c"  , a/10 ,a%10 , symbols[c/3]); break;
-    case 2: sprintf(string[n], "%u%c"     , a          , symbols[c/3]); break;
+    case 0: sprintf(string[n], "%lu.%02lu%c", a/100,a%100, symbols[c/3]); break;
+    case 1: sprintf(string[n], "%lu.%lu%c"  , a/10 ,a%10 , symbols[c/3]); break;
+    case 2: sprintf(string[n], "%lu%c"     , a          , symbols[c/3]); break;
   }
   return string[n];
 }