diff options
author | Tom Rondeau <trondeau@vt.edu> | 2010-11-08 01:44:16 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2010-11-08 22:42:37 -0500 |
commit | 9eeb6dbaa1398946229db780f2eb1ca4e9eae04b (patch) | |
tree | 923c2785e202bae2b088137f8be91ccc12556b16 /gnuradio-core/src/lib | |
parent | ee02e4e66a291685ce6399d7871b98ffccbdca54 (diff) |
Adding a bit more checking on file operations.
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/general/gr_circular_file.cc | 7 | ||||
-rw-r--r-- | gnuradio-core/src/lib/runtime/gr_preferences.cc | 24 |
2 files changed, 25 insertions, 6 deletions
diff --git a/gnuradio-core/src/lib/general/gr_circular_file.cc b/gnuradio-core/src/lib/general/gr_circular_file.cc index 468b49a108..c9222597a8 100644 --- a/gnuradio-core/src/lib/general/gr_circular_file.cc +++ b/gnuradio-core/src/lib/general/gr_circular_file.cc @@ -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 { diff --git a/gnuradio-core/src/lib/runtime/gr_preferences.cc b/gnuradio-core/src/lib/runtime/gr_preferences.cc index e0be2db627..5f74122483 100644 --- a/gnuradio-core/src/lib/runtime/gr_preferences.cc +++ b/gnuradio-core/src/lib/runtime/gr_preferences.cc @@ -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); }; |