fbuf: New data structure for buffered file I/O.
[pspp] / utilities / pspp-convert.c
index b123e5f69e4465b87ed2e4666a38c11576e1c683..ad91ef9da2c937570d3538a4b7eff78baa6ef3e1 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2013, 2014, 2015 Free Software Foundation, Inc.
+   Copyright (C) 2013, 2014, 2015, 2016 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 #include "data/casereader.h"
 #include "data/casewriter.h"
 #include "data/csv-file-writer.h"
+#include "data/dictionary.h"
 #include "data/encrypted-file.h"
 #include "data/file-name.h"
 #include "data/por-file-writer.h"
@@ -58,14 +59,14 @@ main (int argc, char *argv[])
   const char *output_filename;
 
   long long int max_cases = LLONG_MAX;
-  struct dictionary *dict;
+  struct dictionary *dict = NULL;
   struct casereader *reader;
-  struct file_handle *input_fh;
+  struct file_handle *input_fh = NULL;
   const char *encoding = NULL;
   struct encrypted_file *enc;
 
   const char *output_format = NULL;
-  struct file_handle *output_fh;
+  struct file_handle *output_fh = NULL;
   struct casewriter *writer;
   const char *password = NULL;
 
@@ -165,7 +166,7 @@ main (int argc, char *argv[])
 
       if (! decrypt_file (enc, input_fh, output_fh, password))
        goto error;
-         
+
       goto exit;
     }
 
@@ -202,6 +203,8 @@ main (int argc, char *argv[])
              output_filename);
       NOT_REACHED ();
     }
+  if (!writer)
+    error (1, 0, _("%s: error opening output file"), output_filename);
 
   for (i = 0; i < max_cases; i++)
     {
@@ -220,6 +223,7 @@ main (int argc, char *argv[])
     error (1, 0, _("%s: error writing output file"), output_filename);
 
 exit:
+  dict_destroy (dict);
   fh_unref (output_fh);
   fh_unref (input_fh);
   fh_done ();
@@ -228,6 +232,7 @@ exit:
   return 0;
 
 error:
+  dict_destroy (dict);
   fh_unref (output_fh);
   fh_unref (input_fh);
   fh_done ();
@@ -257,7 +262,7 @@ decrypt_file (struct encrypted_file *enc,
   if (!encrypted_file_unlock (enc, password))
     error (1, 0, _("sorry, wrong password"));
 
-  out = fn_open (ofh, "wb");
+  out = fn_fopen (ofh, "wb");
   if (out == NULL)
     error (1, errno, ("%s: error opening output file"), output_filename);