shithub: sox

Download patch

ref: 95609fe504c606a09b660d2d1e27d4de2dd50f0c
parent: 8ae4d299960d9f12f9109f146d7bf9569d19f8c3
author: cbagwell <cbagwell>
date: Fri Sep 24 14:46:57 EDT 2004

partial cleanups

--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -139,7 +139,7 @@
 
 clean:
 	$(RM) *.o libst.a
-	cd gsm && $(RM) *.o
+	cd gsm && $(RM) *.o libgsm.a
 
 distclean:
 	$(RM) *~ *.o *.raw *.sf core sox soxmix libst.a play libst-config
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -207,8 +207,8 @@
                         if (!ft->seekable)
                                 break;
                         /* else, seek to end of sound and hunt for more */
-                        seekto = ftell(ft->fp);
-                        fseek(ft->fp, chunksize, SEEK_CUR); 
+                        seekto = st_tell(ft);
+                        st_seek(ft, chunksize, SEEK_CUR); 
                 }
                 else if (strncmp(buf, "MARK", 4) == 0) {
                         /* MARK chunk */
@@ -329,12 +329,12 @@
                   free(copyright);
                 }
                 else {
-                        if (feof(ft->fp))
+                        if (st_eof(ft))
                                 break;
                         buf[4] = 0;
                         st_report("AIFFstartread: ignoring '%s' chunk\n", buf);
                         st_readdw(ft, &chunksize);
-                        if (feof(ft->fp))
+                        if (st_eof(ft))
                                 break;
                         /* Skip the chunk using st_readb() so we may read
                            from a pipe */
@@ -343,7 +343,7 @@
                                         break;
                         }
                 }
-                if (feof(ft->fp))
+                if (st_eof(ft))
                         break;
         }
 
@@ -354,7 +354,7 @@
         if (ft->seekable)
         {
                 if (seekto > 0)
-                        fseek(ft->fp, seekto, SEEK_SET);
+                        st_seek(ft, seekto, SEEK_SET);
                 else
                 {
                         st_fail_errno(ft,ST_EOF,"AIFF: no sound data on input file");
@@ -477,7 +477,7 @@
             return rc;
 
         ft->length = aiff->nsamples;    /* for seeking */
-        aiff->dataStart = ftell(ft->fp);
+        aiff->dataStart = st_tell(ft);
 
         return(ST_SUCCESS);
 }
@@ -520,7 +520,7 @@
     st_fail_errno(ft,ST_ENOMEM,"AIFF: Couldn't allocate %s header", chunkDescription);
     return(ST_EOF);
   }
-  if (fread(*text, 1, chunksize, ft->fp) != chunksize)
+  if (st_read(ft, *text, 1, chunksize) != chunksize)
   {
     st_fail_errno(ft,ST_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
     return(ST_EOF);
@@ -530,7 +530,7 @@
         {
                 /* Read past pad byte */
                 char c;
-                if (fread(&c, 1, 1, ft->fp) != 1)
+                if (st_read(ft, &c, 1, 1) != 1)
                 {
                 st_fail_errno(ft,ST_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
                         return(ST_EOF);
@@ -573,7 +573,7 @@
         st_fail_errno(ft,ST_ENOMEM,"AIFF: Couldn't allocate %s header", chunkDescription);
         return(ST_EOF);
     }
-    if (fread(*text + totalCommentLength - commentLength, 1, commentLength, ft->fp) != commentLength) {
+    if (st_read(ft, *text + totalCommentLength - commentLength, 1, commentLength) != commentLength) {
         st_fail_errno(ft,ST_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
         return(ST_EOF);
     }
@@ -581,7 +581,7 @@
     if (commentLength % 2) {
         /* Read past pad byte */
         char c;
-        if (fread(&c, 1, 1, ft->fp) != 1) {
+        if (st_read(ft, &c, 1, 1) != 1) {
             st_fail_errno(ft,ST_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
             return(ST_EOF);
         }
@@ -615,13 +615,13 @@
 
         if (!ft->seekable)
         {
-            while (! feof(ft->fp)) 
+            while (! st_eof(ft)) 
             {
-                if (fread(buf, 1, 4, ft->fp) != 4)
+                if (st_read(ft, buf, 1, 4) != 4)
                         break;
 
                 st_readdw(ft, &chunksize);
-                if (feof(ft->fp))
+                if (st_eof(ft))
                         break;
                 buf[4] = '\0';
                 st_warn("Ignoring AIFF tail chunk: '%s', %d bytes long\n", 
@@ -710,7 +710,7 @@
             st_fail_errno(ft,ST_EOF,"Non-seekable file.");
             return(ST_EOF);
         }
-        if (fseek(ft->fp, 0L, SEEK_SET) != 0)
+        if (st_seek(ft, 0L, SEEK_SET) != 0)
         {
                 st_fail_errno(ft,errno,"can't rewind output file to rewrite AIFF header");
                 return(ST_EOF);
@@ -857,7 +857,7 @@
 static double read_ieee_extended(ft_t ft)
 {
         char buf[10];
-        if (fread(buf, 1, 10, ft->fp) != 10)
+        if (st_read(ft, buf, 1, 10) != 10)
         {
                 st_fail_errno(ft,ST_EOF,"EOF while reading IEEE extended number");
                 return(ST_EOF);
@@ -875,7 +875,7 @@
                 buf[0], buf[1], buf[2], buf[3], buf[4],
                 buf[5], buf[6], buf[7], buf[8], buf[9]);
         */
-        (void) fwrite(buf, 1, 10, ft->fp);
+        (void)st_write(ft, buf, 1, 10);
 }
 
 
--- a/src/gsm/Makefile.in
+++ b/src/gsm/Makefile.in
@@ -90,8 +90,8 @@
 	$(RM) $(mandir)/man3/gsm_option.3
 
 clean:
-	$(RM) *.o
+	$(RM) *.o libgsm.a
 
 distclean:
-	$(RM) *~ *.o core
+	$(RM) *~ *.o core libgsm.a
 	$(RM) Makefile
--- a/src/misc.c
+++ b/src/misc.c
@@ -81,6 +81,45 @@
     return fwrite(buf, size, len, ft->fp);
 }
 
+st_size_t st_filelength(ft_t ft)
+{
+  struct stat st;
+
+  fstat(fileno(ft->fp), &st);
+
+  return (st_size_t)st.st_size;
+}
+
+int st_flush(ft_t ft)
+{
+  return fflush(ft->fp);
+}
+
+st_size_t st_tell(ft_t ft)
+{
+  return (st_size_t)ftell(ft->fp);
+}
+
+int st_eof(ft_t ft)
+{
+  return feof(ft->fp);
+}
+
+int st_error(ft_t ft)
+{
+  return ferror(ft->fp);
+}
+ 
+void st_rewind(ft_t ft)
+{
+  rewind(ft->fp);
+}
+
+void st_clearerr(ft_t ft)
+{
+  clearerr(ft->fp);
+}
+
 /* Read and write known datatypes in "machine format".  Swap if indicated.
  * They all return ST_EOF on error and ST_SUCCESS on success.
  */
@@ -95,7 +134,7 @@
     sc = c;
     do
     {
-        if (fread(&in, 1, 1, ft->fp) != 1)
+        if (st_read(ft, &in, 1, 1) != 1)
         {
             *sc = 0;
                 st_fail_errno(ft,errno,readerr);
@@ -116,7 +155,7 @@
 /* Write null-terminated string (without \0). */
 int st_writes(ft_t ft, char *c)
 {
-        if (fwrite(c, 1, strlen(c), ft->fp) != strlen(c))
+        if (st_write(ft, c, 1, strlen(c)) != strlen(c))
         {
                 st_fail_errno(ft,errno,writerr);
                 return(ST_EOF);
@@ -127,7 +166,7 @@
 /* Read byte. */
 int st_readb(ft_t ft, uint8_t *ub)
 {
-        if (fread(ub, 1, 1, ft->fp) != 1)
+        if (st_read(ft, ub, 1, 1) != 1)
         {
                 st_fail_errno(ft,errno,readerr);
             return(ST_EOF);
@@ -138,7 +177,7 @@
 /* Write byte. */
 int st_writeb(ft_t ft, uint8_t ub)
 {
-        if (fwrite(&ub, 1, 1, ft->fp) != 1)
+        if (st_write(ft, &ub, 1, 1) != 1)
         {
                 st_fail_errno(ft,errno,writerr);
                 return(ST_EOF);
@@ -149,7 +188,7 @@
 /* Read word. */
 int st_readw(ft_t ft, uint16_t *uw)
 {
-        if (fread(uw, 2, 1, ft->fp) != 1)
+        if (st_read(ft, uw, 2, 1) != 1)
         {
                 st_fail_errno(ft,errno,readerr);
             return (ST_EOF);
@@ -164,7 +203,7 @@
 {
         if (ft->swap)
                 uw = st_swapw(uw);
-        if (fwrite(&uw, 2, 1, ft->fp) != 1)
+        if (st_write(ft, &uw, 2, 1) != 1)
         {
                 st_fail_errno(ft,errno,writerr);
                 return (ST_EOF);
@@ -175,7 +214,7 @@
 /* Read double word. */
 int st_readdw(ft_t ft, uint32_t *udw)
 {
-        if (fread(udw, 4, 1, ft->fp) != 1)
+        if (st_read(ft, udw, 4, 1) != 1)
         {
                 st_fail_errno(ft,errno,readerr);
             return (ST_EOF);
@@ -190,7 +229,7 @@
 {
         if (ft->swap)
                 udw = st_swapdw(udw);
-        if (fwrite(&udw, 4, 1, ft->fp) != 1)
+        if (st_write(ft, &udw, 4, 1) != 1)
         {
                 st_fail_errno(ft,errno,writerr);
                 return (ST_EOF);
@@ -201,7 +240,7 @@
 /* Read float. */
 int st_readf(ft_t ft, float *f)
 {
-        if (fread(f, sizeof(float), 1, ft->fp) != 1)
+        if (st_read(ft, f, sizeof(float), 1) != 1)
         {
             return(ST_EOF);
         }
@@ -217,7 +256,7 @@
 
         if (ft->swap)
                 t = st_swapf(t);
-        if (fwrite(&t, sizeof(float), 1, ft->fp) != 1)
+        if (st_write(ft, &t, sizeof(float), 1) != 1)
         {
                 st_fail_errno(ft,errno,writerr);
                 return (ST_EOF);
@@ -228,7 +267,7 @@
 /* Read double. */
 int st_readdf(ft_t ft, double *d)
 {
-        if (fread(d, sizeof(double), 1, ft->fp) != 1)
+        if (st_read(ft, d, sizeof(double), 1) != 1)
         {
             return(ST_EOF);
         }
@@ -242,7 +281,7 @@
 {
         if (ft->swap)
                 d = st_swapd(d);
-        if (fwrite(&d, sizeof(double), 1, ft->fp) != 1)
+        if (st_write(ft, &d, sizeof(double), 1) != 1)
         {
                 st_fail_errno(ft,errno,writerr);
                 return (ST_EOF);
@@ -436,12 +475,17 @@
 
 
 #ifndef HAVE_STRERROR
+#ifdef __cplusplus
+extern "C" int sys_nerr;
+extern "C" char *sys_errlist[];
+#else
+extern int sys_nerr;
+extern char *sys_errlist[];
+#endif
 /* strerror function */
 char *strerror(int errcode)
 {
         static char  nomesg[30];
-        extern int sys_nerr;
-        extern char *sys_errlist[];
 
         if (errcode < sys_nerr)
                 return (sys_errlist[errcode]);
@@ -491,14 +535,4 @@
     }
 
     return(ft->st_errno);
-}
-
-st_size_t st_filelength(ft_t ft)
-{
-
-    struct stat st;
-
-    fstat(fileno(ft->fp), &st);
-
-    return (st_size_t)st.st_size;
 }
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -13,8 +13,8 @@
  * the consequences of using this software.
  */
 
-#include "st.h"
 #include "stconfig.h"
+#include "st.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -83,6 +83,12 @@
 int st_writedf(ft_t ft, double d);
 int st_seek(ft_t ft, st_size_t offset, int whence);
 st_size_t st_filelength(ft_t ft);
+int st_flush(ft_t ft);
+st_size_t st_tell(ft_t ft);
+int st_eof(ft_t ft);
+int st_error(ft_t ft);
+void st_rewind(ft_t ft);
+void st_clearerr(ft_t ft);
 
 /* Utilities to byte-swap values, use libc optimized macro's if possible  */
 #ifdef HAVE_BYTESWAP_H