$NetBSD: patch-am,v 1.1.1.1 1999/12/04 12:56:30 scw Exp $

--- libaudiofile/wav.c.orig	Fri Nov 12 17:55:50 1999
+++ libaudiofile/wav.c	Tue Nov 30 21:55:29 1999
@@ -32,7 +32,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFreadWAV
 ---------------------------------------------------------------------------*/
-AFfilehandle AFreadWAV (int file)
+AFfilehandle AFreadWAV (fhandle file)
 {
   int i;
   int j;
@@ -89,7 +89,11 @@
   if (strncmp (id,"WAVE",4))
     fail ("WAV header does not contain a valid form type\n")
 
+#ifndef USE_STDIO
   while (!done && !error) // && !feof (file))
+#else
+  while (!done && !error && !feof (file))
+#endif
   {
     if (!idRead (file,id))
     {
@@ -144,11 +148,19 @@
       }
 
       // Skip past data for now
+#ifndef USE_STDIO
       handle->ssndStart = lseek (file,0L,SEEK_CUR);
+#else
+      handle->ssndStart = ftell (file);
+#endif
       if (handle->ssndStart == -1) aiffError
       seeksize = chunksize;
       if (seeksize % 2) seeksize++;
+#ifndef USE_STDIO
       if (lseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#else
+      if (fseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#endif
       data = TRUE;
     }
     else if (!strncmp (id,"cue ",4))
@@ -210,7 +222,11 @@
         {
           seeksize = chunksize - 4; // Already read in list type
           if (seeksize % 2) seeksize++;
+#ifndef USE_STDIO
           if (lseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#else
+          if (fseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#endif
         }
         else
         {
@@ -226,7 +242,11 @@
         else if (!strncmp (listType,"INFO",4)) info = TRUE;
         
         while (!done && !error &&
+#ifndef USE_STDIO
           amountRead < listChunksize) // && !feof (file))
+#else
+          amountRead < listChunksize && !feof (file))
+#endif
         {
           if (!idRead (file,id))
           {
@@ -253,7 +273,11 @@
               stringsize = chunksize - 4; // Allow for mark id
               markname = (char *) calloc (stringsize,sizeof (char));
               if (!markname) aiffError
+#ifndef USE_STDIO
               if (read (file,markname,stringsize) != stringsize)
+#else
+              if (fread (markname,1,stringsize,file) != stringsize)
+#endif
                 aiffError
               markname [stringsize - 1] = 0; // Just in case
               if (stringsize % 2) ucread (uctemp)
@@ -292,7 +316,11 @@
             if (chunksize % 2) amountRead++; // Space for padding byte
             string = (char *) calloc (chunksize,sizeof (char));
             if (!string) aiffError
+#ifndef USE_STDIO
             if (read (file,string,chunksize) != chunksize)
+#else
+            if (fread (string,1,chunksize,file) != chunksize)
+#endif
               aiffError
             string [chunksize - 1] = 0; // Just in case
             if (chunksize % 2) ucread (uctemp)
@@ -363,7 +391,11 @@
             // Skip past data
             seeksize = chunksize;
             if (seeksize % 2) seeksize++;
+#ifndef USE_STDIO
             if (lseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#else
+            if (fseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#endif
           }
         }
       }
@@ -407,7 +439,11 @@
       // Skip past data
       seeksize = chunksize;
       if (seeksize % 2) seeksize++;
+#ifndef USE_STDIO
       if (lseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#else
+      if (fseek (file,seeksize,SEEK_CUR) == -1) aiffError
+#endif
     }
   }
 
@@ -421,7 +457,11 @@
     fail ("no data chunk\n")
 
   // Read to start of sound data
+#ifndef USE_STDIO
   if (lseek (file,handle->ssndStart,SEEK_SET) == -1)
+#else
+  if (fseek (file,handle->ssndStart,SEEK_SET) == -1)
+#endif
     fail ("error seeking to start of sound data\n")
 
   handle = (AFfilehandle) calloc (1,sizeof (aiffHandle));
@@ -432,7 +472,7 @@
 /*---------------------------------------------------------------------------
 | FUNCTION AFwriteWAV
 ---------------------------------------------------------------------------*/
-AFfilehandle AFwriteWAV (int file,AFfilesetup setup)
+AFfilehandle AFwriteWAV (fhandle file,AFfilesetup setup)
 {
   int i;
   int j;
@@ -543,7 +583,11 @@
       uiwrite (handle->aiff.mark [i].id)
     
       if (stringsize)
+#ifndef USE_STDIO
         if (write (file,handle->aiff.mark [i].name,stringsize) != stringsize)
+#else
+        if (fwrite (handle->aiff.mark [i].name,1,stringsize,file) != stringsize)
+#endif
           return AF_NULL_FILEHANDLE;
       handle->actualBytes += stringsize;
       
@@ -660,7 +704,11 @@
       {
         chunksize = handle->aiff.misc [i].size + 1;
         uiwrite (chunksize)
+#ifndef USE_STDIO
         if (write (file,handle->aiff.misc [i].data,handle->aiff.misc [i].size)
+#else
+        if (fwrite(handle->aiff.misc [i].data,1,handle->aiff.misc [i].size,file)
+#endif
           != handle->aiff.misc [i].size)
           return AF_NULL_FILEHANDLE;
         handle->actualBytes += handle->aiff.misc [i].size;
@@ -685,7 +733,9 @@
   // Don't know length yet
   uiwrite (0)
 
-  // fflush (file); no flushing needed
+#ifdef USE_STDIO
+  fflush (file);
+#endif
 
   handle = (AFfilehandle) calloc (1,sizeof (aiffHandle));
   *handle = handleAct;
@@ -707,7 +757,7 @@
   unsigned short ustemp;
   unsigned char uctemp;
   char idtemp [4];
-  int file;
+  fhandle file;
   int bitWidth;
   int byteWidth;
   unsigned int byteRate;
@@ -723,7 +773,11 @@
   
   if (handle->mode == READONLY)
   {
+#ifndef USE_STDIO
     if (close (handle->file) == -1) return -1;
+#else
+    if (fclose (handle->file) == -1) return -1;
+#endif
     free (handle);
     return 0;
   }
@@ -738,7 +792,11 @@
       ucwrite (0)
     
     // Reset file descriptor
+#ifndef USE_STDIO
     if (lseek (file,0L,SEEK_SET) == -1)
+#else
+    if (fseek (file,0L,SEEK_SET) == -1)
+#endif
     {
       fprintf (stderr,"unable to seek on file\n");
       return -1;
@@ -821,7 +879,11 @@
         uiupdate (handle->aiff.mark [i].id)
 
         if (stringsize)
+#ifndef USE_STDIO
           if (write (file,handle->aiff.mark [i].name,stringsize) != stringsize)
+#else
+          if (fwrite(handle->aiff.mark [i].name,1,stringsize,file)!= stringsize)
+#endif
             return AF_NULL_FILEHANDLE;
         handle->actualBytes += stringsize;
 
@@ -938,7 +1000,11 @@
         {
           chunksize = handle->aiff.misc [i].size + 1;
           uiupdate (chunksize)
+#ifndef USE_STDIO
           if (write (file,handle->aiff.misc [i].data,handle->aiff.misc [i].size)
+#else
+          if (fwrite(handle->aiff.misc [i].data,1,handle->aiff.misc [i].size,file)
+#endif
             != handle->aiff.misc [i].size)
             return AF_NULL_FILEHANDLE;
           handle->actualBytes += handle->aiff.misc [i].size;
@@ -967,7 +1033,11 @@
     chunksize *= byteWidth;
     uiupdate (chunksize)
     
+#ifndef USE_STDIO
     if (close (handle->file) == -1) return -1;
+#else
+    if (fclose (handle->file) == -1) return -1;
+#endif
     free (handle);
     return 0;
   }
@@ -982,7 +1052,7 @@
   int i;
   int j;
   int frameCount;
-  int file;
+  fhandle file;
   unsigned char uctemp;
   short stemp;
   int itemp;
@@ -996,7 +1066,11 @@
   i = 0;
   frameCount = 0;
   while (handle->actualFrames < handle->aiff.framecount &&
+#ifndef USE_STDIO
     frameCount < count) // && !(feof (file)))
+#else
+    frameCount < count && !(feof (file)))
+#endif
   {
     for (j=0; j<handle->aiff.channels; j++)
     {
@@ -1034,7 +1108,7 @@
   int i;
   int j;
   int frameCount;
-  int file;
+  fhandle file;
   unsigned char uctemp;
   short stemp;
   int itemp;
@@ -1047,7 +1121,11 @@
 
   i = 0;
   frameCount = 0;
+#ifndef USE_STDIO
   while (frameCount < count) // && !(feof (file)))
+#else
+  while (frameCount < count && !(feof (file)))
+#endif
   {
     for (j=0; j<handle->aiff.channels; j++)
     {
