Adding a bit more checking on file operations.
authorTom Rondeau <trondeau@vt.edu>
Mon, 8 Nov 2010 06:44:16 +0000 (01:44 -0500)
committerTom Rondeau <trondeau@vt.edu>
Tue, 9 Nov 2010 03:42:37 +0000 (22:42 -0500)
gnuradio-core/src/lib/general/gr_circular_file.cc
gnuradio-core/src/lib/runtime/gr_preferences.cc

index 468b49a1087246ac2e2a1ddaa77bb3fa8a3ead9d..c9222597a873da93ca5f2081bc7f314d73a9a9d1 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2002 Free Software Foundation, Inc.
+ * Copyright 2002,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -66,7 +66,10 @@ gr_circular_file::gr_circular_file (const char *filename,
       exit (1);
     }
 #ifdef HAVE_MMAP       /* FIXME */
-    ftruncate (d_fd, size + HEADER_SIZE);
+    if(ftruncate (d_fd, size + HEADER_SIZE) != 0) {
+      perror (filename);
+      exit (1);
+    }
 #endif
   }
   else {
index e0be2db62788b1681028121a3e6be2b21012fb7c..5f741224834e16fee6458cd1d5fa2b706565472d 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2003 Free Software Foundation, Inc.
+ * Copyright 2003,2010 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -77,11 +77,20 @@ gr_preferences::get (const char *key)
   static char buf[1024];
 
   FILE         *fp = fopen (pathname (key), "r");
-  if (fp == 0)
+  if (fp == 0) {
+    perror (pathname (key));
     return 0;
+  }
 
   memset (buf, 0, sizeof (buf));
-  fread (buf, 1, sizeof (buf) - 1, fp);
+  size_t ret = fread (buf, 1, sizeof (buf) - 1, fp);
+  if(ret == 0) {
+    if(ferror(fp) != 0) {
+      perror (pathname (key));
+      fclose (fp);
+      return 0;
+    }
+  }
   fclose (fp);
   return buf;
 }
@@ -97,6 +106,13 @@ gr_preferences::set (const char *key, const char *value)
     return;
   }
 
-  fwrite (value, 1, strlen (value), fp);
+  size_t ret = fwrite (value, 1, strlen (value), fp);
+  if(ret == 0) {
+    if(ferror(fp) != 0) {
+      perror (pathname (key));
+      fclose (fp);
+      return;
+    }
+  }
   fclose (fp);
 };