Skip to content

Commit

Permalink
PArtially unified IO error handling for conditional compiled units.
Browse files Browse the repository at this point in the history
  • Loading branch information
val-antonescu committed Nov 27, 2013
1 parent 5cfb28c commit bdc6874
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bt2_idx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const std::string gEbwt_ext("bt2");

#endif // BOWTIE_64BIT_INDEX

string gLastIOErrMsg;

///////////////////////////////////////////////////////////////////////
//
// Functions for searching Ebwts
Expand Down
24 changes: 24 additions & 0 deletions bt2_idx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3047,4 +3047,28 @@ string adjustEbwtBase(const string& cmdline,
const string& ebwtFileBase,
bool verbose);


extern string gLastIOErrMsg;

/* Checks whether a call to read() failed or not. */
inline bool is_read_err(int fdesc, ssize_t ret, size_t count){
if (ret < 0) {
std::stringstream sstm;
sstm << "ERRNO: " << errno << " ERR Msg:" << strerror(errno) << std::endl;
gLastIOErrMsg = sstm.str();
return true;
}
return false;
}

/* Checks whether a call to fread() failed or not. */
inline bool is_fread_err(FILE* file_hd, size_t ret, size_t count){
if (ferror(file_hd)) {
gLastIOErrMsg = "Error Reading File!";
return true;
}
return false;
}


#endif /*EBWT_H_*/
11 changes: 5 additions & 6 deletions bt2_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ void Ebwt::readIntoMemory(

while (bytesLeft>0){
MM_READ_RET r = MM_READ(_in1, (void *)pebwt, bytesLeft);
if(r < 0) {
cerr << "Error reading _ebwt[] array: " << r << ", " << bytesLeft
<< "ERRNO: " << errno << " ERR:" << strerror(errno) << endl;
if(MM_IS_IO_ERR(_in1,r,bytesLeft)) {
cerr << "Error reading _ebwt[] array: " << r << ", "
<< bytesLeft << gLastIOErrMsg << endl;
throw 1;
}
pebwt += r;
Expand Down Expand Up @@ -616,10 +616,9 @@ void Ebwt::readIntoMemory(

while(bytesLeft > 0) {
MM_READ_RET r = MM_READ(_in2, (void*)offs, bytesLeft);
if(r < 0) {
if(MM_IS_IO_ERR(_in2,r,bytesLeft)) {
cerr << "Error reading block of _offs[] array: "
<< r << ", " << bytesLeft << "ERRNO: "
<< errno << " ERR:" << strerror(errno) << endl;
<< r << ", " << bytesLeft << gLastIOErrMsg << endl;
throw 1;
}
offs += r;
Expand Down
2 changes: 2 additions & 0 deletions mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
#define MM_SEEK lseek
#define MM_FILE int
#define MM_FILE_INIT -1
#define MM_IS_IO_ERR(fdesc, ret, count) is_read_err(fdesc, ret, count)
#else
#define MM_FILE_CLOSE(x) if(x != NULL) { fclose(x); }
#define MM_READ_RET size_t
#define MM_READ(file, dest, sz) fread(dest, 1, sz, file)
#define MM_SEEK fseek
#define MM_FILE FILE*
#define MM_FILE_INIT NULL
#define MM_IS_IO_ERR(file_hd, ret, count) is_fread_err(file_hd, ret, count)
#endif

#endif /* MM_H_ */

0 comments on commit bdc6874

Please sign in to comment.