Skip to content

Commit

Permalink
add errno handling
Browse files Browse the repository at this point in the history
  • Loading branch information
darvark committed Aug 3, 2023
1 parent 4c45c92 commit 5f33659
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/addmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ int init_and_load_multipliers(void) {
}

while ((read = getline(&s_inputbuffer, &s_inputbuffer_len, cfp)) != -1) {
if (read != -1) {
if (s_inputbuffer_len > 0) {
/* strip leading and trailing whitespace */
g_strstrip(s_inputbuffer);
Expand All @@ -372,12 +371,10 @@ int init_and_load_multipliers(void) {

add_mult_line(s_inputbuffer);
}
}
else {
printf("RuntimeError: %ld", read);
exit(1);
}

else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

fclose(cfp);
Expand Down
8 changes: 8 additions & 0 deletions src/bandmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,16 @@ void bmdata_read_file() {
free_spot(entry);
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}

if (line != NULL)
free(line);
Expand Down
4 changes: 4 additions & 0 deletions src/cabrillo_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ static int process_cabrillo_template_file(const char *file_name) {
break;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (logline != NULL)
Expand Down
12 changes: 12 additions & 0 deletions src/checklogfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ int repair_log(char *filename) {
fputs(buffer, outfp);
fputs("\n", outfp);
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (buffer != NULL)
Expand Down Expand Up @@ -200,6 +204,10 @@ int checklogfile_new(char *filename) {
tooshort = 1;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (buffer != NULL)
Expand Down Expand Up @@ -275,6 +283,10 @@ void checklogfile(void) {
}
fputs(inputbuffer, outfile);
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (inputbuffer != NULL)
Expand Down
4 changes: 4 additions & 0 deletions src/dxcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ int load_ctydata(char *filename) {
}
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (buf != NULL)
Expand Down
6 changes: 5 additions & 1 deletion src/initial_exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ struct ie_list *make_ie_list(char *file) {
/* prepend new entry to existing list */
new->next = ie_listhead;
ie_listhead = new;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (inputbuffer != NULL)
Expand Down
14 changes: 13 additions & 1 deletion src/parse_logcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ int parse_configfile(FILE *fp) {
if (status != PARSE_OK) {
break;
}
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (buffer != NULL)
free(buffer);
Expand Down Expand Up @@ -696,6 +700,10 @@ static int cfg_countrylist(const cfg_arg_t arg) {
break;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

g_free(prefix);
Expand Down Expand Up @@ -788,6 +796,10 @@ static int cfg_continentlist(const cfg_arg_t arg) {
break;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

g_free(prefix);
Expand Down
4 changes: 4 additions & 0 deletions src/readcabrillo.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ int readcabrillo(int mode) {
while((read = getline(&logline, &read_len, fp1)) != 1) {
if (read_len > 0)
cab_qso_to_tlf(logline, cabdesc);
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

strcpy(qsonrstr, t_qsonrstr);
Expand Down
4 changes: 4 additions & 0 deletions src/readcalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ int readcalls(const char *logfile, bool interactive) {

g_ptr_array_add(qso_array, qso);
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

fclose(fp);
Expand Down
16 changes: 16 additions & 0 deletions src/readqtccalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ int readqtccalls() {
last_qtc = tempi;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (inputbuffer != NULL)
Expand Down Expand Up @@ -125,6 +129,10 @@ int readqtccalls() {

total++; /* add one point per QTC */
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (inputbuffer != NULL)
Expand All @@ -145,6 +153,10 @@ int readqtccalls() {
/* remember callsign, mark it as QTC capable, based on eg. last years */
if (inputbuffer_len > 0)
qtc_inc(g_strstrip(inputbuffer), QTC_CAP);
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (inputbuffer != NULL)
Expand All @@ -161,6 +173,10 @@ int readqtccalls() {
/* remember callsign, set marked QTC states */
if (inputbuffer_len > 0)
parse_qtc_flagline(inputbuffer);
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

if (inputbuffer != NULL)
Expand Down
4 changes: 4 additions & 0 deletions src/searchlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ int load_callmaster(void) {
g_hash_table_add(callset, call);
g_ptr_array_add(callmaster, call);
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}

g_hash_table_destroy(callset);
Expand Down
7 changes: 6 additions & 1 deletion src/writecabrillo.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ struct linedata_t *get_next_record(FILE *fp) {
int read;

while ((read = getline(&buffer, &buffer_len, fp)) != -1) {
if (buffer_len > 0)
if (buffer_len > 0) {
if (!log_is_comment(buffer)) {
ptr = parse_logline(buffer);
return ptr;
}
}
else {
perror("RuntimeError: ");
exit(EXIT_FAILURE);
}
}
if (buffer != NULL)
free(buffer);
Expand Down

0 comments on commit 5f33659

Please sign in to comment.