diff options
| author | Gertjan van den Burg <burg@ese.eur.nl> | 2016-09-20 16:43:55 +0200 |
|---|---|---|
| committer | Gertjan van den Burg <burg@ese.eur.nl> | 2016-09-20 16:43:55 +0200 |
| commit | bd23e7751320f25dc8147bd71bd531201d353d60 (patch) | |
| tree | 5b50ebd261749a010738e7450679e1c6e2a6c47a /src | |
| parent | Remove inline rand function (diff) | |
| download | gensvm-bd23e7751320f25dc8147bd71bd531201d353d60.tar.gz gensvm-bd23e7751320f25dc8147bd71bd531201d353d60.zip | |
Use exit_failure and err() in gensvm_io
Diffstat (limited to 'src')
| -rw-r--r-- | src/gensvm_io.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/gensvm_io.c b/src/gensvm_io.c index c3eebaf..2a9abaa 100644 --- a/src/gensvm_io.c +++ b/src/gensvm_io.c @@ -166,9 +166,11 @@ void gensvm_read_model(struct GenModel *model, char *model_filename) fid = fopen(model_filename, "r"); if (fid == NULL) { - fprintf(stderr, "Error opening model file %s\n", + // LCOV_EXCL_START + err("[GenSVM Error]: Couldn't open model file %s\n", model_filename); - exit(1); + exit(EXIT_FAILURE); + // LCOV_EXCL_STOP } // skip the first four lines for (i=0; i<4; i++) @@ -188,9 +190,11 @@ void gensvm_read_model(struct GenModel *model, char *model_filename) // read filename of data file if (fgets(buffer, MAX_LINE_LENGTH, fid) == NULL) { - fprintf(stderr, "Error reading model file %s\n", + // LCOV_EXCL_START + err("[GenSVM Error]: Error reading from model file %s\n", model_filename); - exit(1); + exit(EXIT_FAILURE); + // LCOV_EXCL_STOP } sscanf(buffer, "filename = %s\n", data_filename); model->data_file = data_filename; @@ -213,10 +217,12 @@ void gensvm_read_model(struct GenModel *model, char *model_filename) } } if (nr != (model->m+1)*(model->K-1)) { - fprintf(stderr, "Error reading model file %s. " + // LCOV_EXCL_START + err("[GenSVM Error] Error reading from model file %s. " "Not enough elements of V found.\n", model_filename); - exit(1); + exit(EXIT_FAILURE); + // LCOV_EXCL_STOP } } @@ -242,9 +248,11 @@ void gensvm_write_model(struct GenModel *model, char *output_filename) // open output file fid = fopen(output_filename, "w"); if (fid == NULL) { - fprintf(stderr, "Error opening output file %s", + // LCOV_EXCL_START + err("[GenSVM Error]: Error opening output file %s\n", output_filename); - exit(1); + exit(EXIT_FAILURE); + // LCOV_EXCL_STOP } gensvm_time_string(timestr); @@ -300,9 +308,11 @@ void gensvm_write_predictions(struct GenData *data, long *predy, fid = fopen(output_filename, "w"); if (fid == NULL) { - fprintf(stderr, "Error opening output file %s", + // LCOV_EXCL_START + err("[GenSVM Error]: Error opening output file %s\n", output_filename); - exit(1); + exit(EXIT_FAILURE); + // LCOV_EXCL_STOP } fprintf(fid, "%li\n", data->n); @@ -341,15 +351,17 @@ void gensvm_time_string(char *buffer) // get current time (in epoch) current_time = time(NULL); if (current_time == ((time_t)-1)) { - fprintf(stderr, "Failed to compute the current time.\n"); + // LCOV_EXCL_START + err("[GenSVM Error]: Failed to compute the current time.\n"); return; + // LCOV_EXCL_STOP } // convert time to local time and create a string lclt = localtime(¤t_time); strftime(timestr, MAX_LINE_LENGTH, "%c", lclt); if (timestr == NULL) { - fprintf(stderr, "Failed to convert time to string.\n"); + err("[GenSVM Error]: Failed to convert time to string.\n"); return; } |
