diff src/flacng/tools.c @ 1272:47559538ce3d

- stop read_metadata from stomping on the wrong file descriptors
author Ralf Ertzinger <ralf@skytale.net>
date Sun, 15 Jul 2007 15:00:10 +0200
parents 37598c8f4425
children 263d72004333
line wrap: on
line diff
--- a/src/flacng/tools.c	Fri Jul 13 21:31:17 2007 +0200
+++ b/src/flacng/tools.c	Sun Jul 15 15:00:10 2007 +0200
@@ -64,7 +64,7 @@
     info->replaygain.track_peak = NULL;
     info->replaygain.album_gain = NULL;
     info->replaygain.album_peak = NULL;
-    reset_info(info);
+    reset_info(info, FALSE);
 
     _DEBUG("Playback buffer allocated for %d samples, %d bytes", BUFFER_SIZE_SAMP, BUFFER_SIZE_BYTE);
 
@@ -73,16 +73,17 @@
 
 /* --- */
 
-void reset_info(callback_info* info) {
+void reset_info(callback_info* info, gboolean close_fd) {
 
     _ENTER;
 
     _DEBUG("Using callback_info %s", info->name);
 
-    if (NULL != info->input_stream) {
+    if (close_fd && (NULL != info->input_stream)) {
+        _DEBUG("Closing fd");
         vfs_fclose(info->input_stream);
-        info->input_stream = NULL;
     }
+    info->input_stream = NULL;
 
     // memset(info->output_buffer, 0, BUFFER_SIZE * sizeof(int16_t));
     info->stream.samplerate = 0;
@@ -180,6 +181,10 @@
 
     _DEBUG("Using callback_info %s", info->name);
 
+    reset_info(info, FALSE);
+
+    info->input_stream = fd;
+
     /*
      * Reset the decoder
      */
@@ -188,10 +193,6 @@
         _LEAVE FALSE;
     }
 
-    reset_info(info);
-
-    info->input_stream = fd;
-
     /*
      * Just scan the first 8k for the start of metadata
      */
@@ -212,8 +213,7 @@
         _DEBUG("Could not read the metadata: %s(%d)!",
                 FLAC__StreamDecoderStateString[ret], ret);
         /* Do not close the filehandle, it was passed to us */
-        info->input_stream = NULL;
-        reset_info(info);
+        reset_info(info, FALSE);
         _LEAVE FALSE;
     }