Use std::strerror to report system call errors

Refs #357
This commit is contained in:
Derek Bankieris 2016-11-30 13:25:52 -06:00
parent 4d7ea87a43
commit 9fa76d8e78
4 changed files with 23 additions and 11 deletions

View File

@ -1,4 +1,6 @@
#include <cerrno>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
@ -16,7 +18,7 @@ Csv::Csv(char * file_name , char * param_name ) {
len = strlen(param_name) ;
if ((fp_ = fopen(file_name , "r")) == 0 ) {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
exit(-1) ;
}
@ -173,7 +175,7 @@ int CsvLocateParam( char * file_name , char * param_name ) {
}
else {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
}
return(0) ;

View File

@ -1,3 +1,7 @@
#include <cerrno>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#if __sgi | __sun
@ -70,7 +74,7 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) {
fileName_ = file_name;
if ((fp_ = fopen(file_name, "r")) == 0) {
printf("ERROR: Couldn't open \"%s\"\n", file_name) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
return;
}
@ -656,7 +660,7 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) {
int field_index, field_num;
if ((fp = fopen(file_name, "r")) == 0) {
printf("ERROR: Couldn't open \"%s\"\n", file_name) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
return (0);
}

View File

@ -1,3 +1,6 @@
#include <cerrno>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <string.h>
@ -30,7 +33,7 @@ MatLab4::MatLab4(char * file_name , char * param_name , char * time_name ) {
TRICK_GET_BYTE_ORDER(my_byte_order) ;
if ((fp_ = fopen(file_name , "r")) == 0 ) {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
exit(-1) ;
}
@ -280,7 +283,7 @@ int MatLab4LocateParam( char *file_name , char *param_name , char *time_name ) {
TRICK_GET_BYTE_ORDER(my_byte_order) ;
if ((fp = fopen(file_name , "r")) == 0 ) {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
exit(-1) ;
}

View File

@ -1,3 +1,6 @@
#include <cerrno>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <string.h>
@ -176,7 +179,7 @@ TrickBinary::TrickBinary(char * file_name , char * param_name ) {
record_ = new char[record_size_] ;
}
else {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
}
}
@ -408,7 +411,7 @@ int TrickBinaryGetNumVariables(const char* file_name) {
fread(&num_params , 4 , 1 , fp ) ;
if ( swap ) { num_params = trick_byteswap_int(num_params) ; }
} else {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
return(0) ;
}
@ -474,7 +477,7 @@ char** TrickBinaryGetVariableNames(const char* file_name) {
}
}
else {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
return(0) ;
}
@ -541,7 +544,7 @@ char** TrickBinaryGetVariableUnits(const char* file_name) {
}
}
else {
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
std::cout << "ERROR: Couldn't open \"" << file_name << "\": " << std::strerror(errno) << std::endl;
return(0) ;
}