summaryrefslogtreecommitdiff
path: root/gr-trellis/src/lib/fsm.cc
diff options
context:
space:
mode:
authorTom Rondeau2010-11-09 22:45:02 -0500
committerTom Rondeau2010-11-09 22:45:02 -0500
commita72819e861caaabdea0ac41f5f5e387cb61d3513 (patch)
tree89121c244d1260fd1f6dab42ad88efb85c0867c1 /gr-trellis/src/lib/fsm.cc
parent5d1baa5a96e3dac0756571da9fc115dba14bbbff (diff)
downloadgnuradio-a72819e861caaabdea0ac41f5f5e387cb61d3513.tar.gz
gnuradio-a72819e861caaabdea0ac41f5f5e387cb61d3513.tar.bz2
gnuradio-a72819e861caaabdea0ac41f5f5e387cb61d3513.zip
Adding file operations result checking.
Diffstat (limited to 'gr-trellis/src/lib/fsm.cc')
-rw-r--r--gr-trellis/src/lib/fsm.cc20
1 files changed, 17 insertions, 3 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();