diff options
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_sink.cc | 27 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_sink_base.cc | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gr_file_source.cc | 5 |
3 files changed, 21 insertions, 13 deletions
diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc b/gnuradio-core/src/lib/io/gr_file_sink.cc index 5d147fcfe..10c8360cb 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink.cc @@ -42,8 +42,6 @@ gr_file_sink::gr_file_sink(size_t itemsize, const char *filename) gr_file_sink_base(filename, true), d_itemsize(itemsize) { - if (!open(filename)) - throw std::runtime_error ("can't open file"); } gr_file_sink::~gr_file_sink () @@ -55,23 +53,32 @@ gr_file_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - char *inbuf = (char *) input_items[0]; + char *inbuf = (char*)input_items[0]; int nwritten = 0; do_update(); // update d_fp is reqd - if (!d_fp) + if(!d_fp) return noutput_items; // drop output on the floor - while (nwritten < noutput_items){ - int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten, d_fp); - if (count == 0) // FIXME add error handling - break; + while(nwritten < noutput_items) { + int count = fwrite(inbuf, d_itemsize, noutput_items - nwritten, d_fp); + if(count == 0) { + if(ferror(d_fp)) { + std::stringstream s; + s << "file_sink write failed with error " << fileno(d_fp) << std::endl; + throw std::runtime_error(s.str()); + } + else { // is EOF + break; + } + } nwritten += count; inbuf += count * d_itemsize; } - if (d_unbuffered) - fflush (d_fp); + + if(d_unbuffered) + fflush (d_fp); return nwritten; } diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index b2dcc1be5..2dd896ae7 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -122,5 +122,5 @@ gr_file_sink_base::do_update() void gr_file_sink_base::set_unbuffered(bool unbuffered) { - d_unbuffered = unbuffered; + d_unbuffered = unbuffered; } diff --git a/gnuradio-core/src/lib/io/gr_file_source.cc b/gnuradio-core/src/lib/io/gr_file_source.cc index 3f06a8244..96333fa24 100644 --- a/gnuradio-core/src/lib/io/gr_file_source.cc +++ b/gnuradio-core/src/lib/io/gr_file_source.cc @@ -111,8 +111,9 @@ gr_file_source::work (int noutput_items, break; if (fseek ((FILE *) d_fp, 0, SEEK_SET) == -1) { - fprintf(stderr, "[%s] fseek failed\n", __FILE__); - exit(-1); + std::stringstream s; + s << "[" << __FILE__ << "]" << " fseek failed" << std::endl; + throw std::runtime_error(s.str()); } } |