Skip to content

Commit 8245c33

Browse files
committedJan 22, 2024
feat: returing error in gps_open_files
1 parent eb34933 commit 8245c33

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎gps.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ void gps_construct_filename(char *dest, const char *path, char *helper_buff, gps
629629
strcat(dest, ".csv");
630630
}
631631

632-
void gps_open_files(gps_files_t *files, const char *path) {
632+
int gps_open_files(gps_files_t *files, const char *path) {
633633
const int message_size = 20;
634634
const int filepath_size = 100;
635635
char message[message_size];
@@ -640,13 +640,22 @@ void gps_open_files(gps_files_t *files, const char *path) {
640640
match.message = i;
641641
gps_construct_filename(filepath, path, message, &match);
642642
files->nmea[i] = fopen(filepath, "w");
643+
if(files->nmea[i] == NULL) {
644+
printf("GPS: could not open file %s\n", filepath);
645+
return -1;
646+
}
643647
}
644648
match.protocol = GPS_PROTOCOL_TYPE_UBX;
645649
for (int i = 0; i < GPS_UBX_TYPE_SIZE; i++) {
646650
match.message = i;
647651
gps_construct_filename(filepath, path, message, &match);
648652
files->ubx[i] = fopen(filepath, "w");
653+
if(files->ubx[i] == NULL) {
654+
printf("GPS: could not open file %s\n", filepath);
655+
return -1;
656+
}
649657
}
658+
return 0;
650659
}
651660

652661
void gps_close_files(gps_files_t *files) {

‎gps.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ typedef struct gps_files_t {
273273
} gps_files_t;
274274

275275
void gps_get_message_name(gps_protocol_and_message *match, char *buff);
276-
void gps_open_files(gps_files_t *files, const char *path);
276+
int gps_open_files(gps_files_t *files, const char *path);
277277
void gps_close_files(gps_files_t *files);
278278

279279
void gps_to_file(gps_files_t *files, gps_parsed_data_t *data, gps_protocol_and_message *match);

0 commit comments

Comments
 (0)
Please sign in to comment.