summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rondeau2010-11-09 22:45:02 -0500
committerTom Rondeau2010-11-09 22:45:02 -0500
commita72819e861caaabdea0ac41f5f5e387cb61d3513 (patch)
tree89121c244d1260fd1f6dab42ad88efb85c0867c1
parent5d1baa5a96e3dac0756571da9fc115dba14bbbff (diff)
downloadgnuradio-a72819e861caaabdea0ac41f5f5e387cb61d3513.tar.gz
gnuradio-a72819e861caaabdea0ac41f5f5e387cb61d3513.tar.bz2
gnuradio-a72819e861caaabdea0ac41f5f5e387cb61d3513.zip
Adding file operations result checking.
-rw-r--r--gr-trellis/src/lib/fsm.cc20
-rw-r--r--gr-trellis/src/lib/interleaver.cc13
2 files changed, 28 insertions, 5 deletions
diff --git a/gr-trellis/src/lib/fsm.cc b/gr-trellis/src/lib/fsm.cc
index c65b13456..5950b56b9 100644
--- a/gr-trellis/src/lib/fsm.cc
+++ b/gr-trellis/src/lib/fsm.cc
@@ -86,16 +86,30 @@ fsm::fsm(const char *name)
if((fsmfile=fopen(name,"r"))==NULL)
throw std::runtime_error ("fsm::fsm(const char *name): file open error\n");
//printf("file open error in fsm()\n");
+
+ if(fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O) == EOF) {
+ if(ferror(fsmfile) != 0)
+ throw std::runtime_error ("fsm::fsm(const char *name): file read error\n");
+ }
- fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O);
d_NS.resize(d_I*d_S);
d_OS.resize(d_I*d_S);
for(int i=0;i<d_S;i++) {
- for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_NS[i*d_I+j]));
+ for(int j=0;j<d_I;j++) {
+ if(fscanf(fsmfile,"%d",&(d_NS[i*d_I+j])) == EOF) {
+ if(ferror(fsmfile) != 0)
+ throw std::runtime_error ("fsm::fsm(const char *name): file read error\n");
+ }
+ }
}
for(int i=0;i<d_S;i++) {
- for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_OS[i*d_I+j]));
+ for(int j=0;j<d_I;j++) {
+ if(fscanf(fsmfile,"%d",&(d_OS[i*d_I+j])) == EOF) {
+ if(ferror(fsmfile) != 0)
+ throw std::runtime_error ("fsm::fsm(const char *name): file read error\n");
+ }
+ }
}
generate_PS_PI();
diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc
index 077416f80..ff15eeadc 100644
--- a/gr-trellis/src/lib/interleaver.cc
+++ b/gr-trellis/src/lib/interleaver.cc
@@ -75,11 +75,20 @@ interleaver::interleaver(const char *name)
throw std::runtime_error ("file open error in interleaver()");
//printf("file open error in interleaver()\n");
- fscanf(interleaverfile,"%d\n",&d_K);
+ if(fscanf(interleaverfile,"%d\n",&d_K) == EOF) {
+ if(ferror(interleaverfile) != 0)
+ throw std::runtime_error ("interleaver::interleaver(const char *name): file read error\n");
+ }
+
d_INTER.resize(d_K);
d_DEINTER.resize(d_K);
- for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
+ for(int i=0;i<d_K;i++) {
+ if(fscanf(interleaverfile,"%d",&(d_INTER[i])) == EOF) {
+ if(ferror(interleaverfile) != 0)
+ throw std::runtime_error ("interleaver::interleaver(const char *name): file read error\n");
+ }
+ }
// generate DEINTER table
for(int i=0;i<d_K;i++) {