Author: dcreager
Date: Thu Sep 13 21:28:19 2012
New Revision: 1384549

URL: http://svn.apache.org/viewvc?rev=1384549&view=rev
Log:
AVRO-1160. C: Better error reporting in avrocat

Contributed by Lucas Martin-King.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c/src/avrocat.c

Modified: avro/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1384549&r1=1384548&r2=1384549&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Sep 13 21:28:19 2012
@@ -67,6 +67,9 @@ Avro 1.7.2 (unreleased)
     AVRO-1159. C: Check union discriminants in avro_value_read.
     (Lucas Martin-King via dcreager)
 
+    AVRO-1160. C: Better error reporting in avrocat.  (Lucas Martin-King
+    via dcreager)
+
 Avro 1.7.1 (16 July 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/c/src/avrocat.c
URL: 
http://svn.apache.org/viewvc/avro/trunk/lang/c/src/avrocat.c?rev=1384549&r1=1384548&r2=1384549&view=diff
==============================================================================
--- avro/trunk/lang/c/src/avrocat.c (original)
+++ avro/trunk/lang/c/src/avrocat.c Thu Sep 13 21:28:19 2012
@@ -30,21 +30,33 @@ static void
 process_file(const char *filename)
 {
        avro_file_reader_t  reader;
+       FILE *fp;
+       int  should_close;
 
        if (filename == NULL) {
-               if (avro_file_reader_fp(stdin, "<stdin>", 0, &reader)) {
-                       fprintf(stderr, "Error opening <stdin>:\n  %s\n",
-                               avro_strerror());
-                       exit(1);
-               }
+               fp = stdin;
+               filename = "<stdin>";
+               should_close = 0;
        } else {
-               if (avro_file_reader(filename, &reader)) {
+               fp = fopen(filename, "rb");
+               should_close = 1;
+
+               if (fp == NULL) {
                        fprintf(stderr, "Error opening %s:\n  %s\n",
-                               filename, avro_strerror());
+                               filename, strerror(errno));
                        exit(1);
                }
        }
 
+       if (avro_file_reader_fp(fp, filename, 0, &reader)) {
+               fprintf(stderr, "Error opening %s:\n  %s\n",
+                       filename, avro_strerror());
+               if (should_close) {
+                       fclose(fp);
+               }
+               exit(1);
+       }
+
        avro_schema_t  wschema;
        avro_value_iface_t  *iface;
        avro_value_t  value;
@@ -67,9 +79,17 @@ process_file(const char *filename)
                avro_value_reset(&value);
        }
 
+       if (!feof(fp)) {
+               fprintf(stderr, "Error: %s\n", avro_strerror());
+       }
+
        avro_file_reader_close(reader);
        avro_value_decref(&value);
        avro_value_iface_decref(iface);
+
+       if (should_close) {
+               fclose(fp);
+       }
 }
 
 


Reply via email to