summaryrefslogtreecommitdiffstats
path: root/core/uemis-downloader.c
diff options
context:
space:
mode:
authorGravatar Oliver Schwaneberg <oliver.schwaneberg@gmail.com>2018-01-27 23:33:05 +0100
committerGravatar Jan Mulder <jlmulder@xs4all.nl>2018-01-31 14:47:47 +0100
commit728e007c5c3eff08cd3dc213ebc3034a9513d4c9 (patch)
treed8f656a9206d445e7562f5c3ffa0467c3efa6ffd /core/uemis-downloader.c
parent8f81a22e7f26729cc2f4902ba7db8f696314539f (diff)
downloadsubsurface-728e007c5c3eff08cd3dc213ebc3034a9513d4c9.tar.gz
uemis: code refactoring
- Variable max_deleted_seen had no effect and is removed. - Results of read/write operations are evaluated to assert success and to prevent compiler warnings. Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
Diffstat (limited to 'core/uemis-downloader.c')
-rw-r--r--core/uemis-downloader.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index ff0027f7b..6ad2fcc1d 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -75,8 +75,6 @@ static int next_table_index = 0;
static int dive_to_read = 0;
static uint32_t mindiveid;
-static int max_deleted_seen = -1;
-
/* Linked list to remember already executed divespot download requests */
struct divespot_mapping {
int divespot_id;
@@ -317,7 +315,8 @@ static bool uemis_init(const char *path)
}
if (bytes_available(reqtxt_file) > 5) {
char tmp[6];
- read(reqtxt_file, tmp, 5);
+ if (read(reqtxt_file, tmp, 5) != 5)
+ return false;
tmp[5] = '\0';
#if UEMIS_DEBUG & 2
fprintf(debugfile, "::r req.txt \"%s\"\n", tmp);
@@ -594,7 +593,8 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
#endif
return false;
}
- read(ans_file, tmp, 100);
+ if (read(ans_file, tmp, 100) < 0)
+ return false;
close(ans_file);
#if UEMIS_DEBUG & 8
tmp[100] = '\0';
@@ -1065,12 +1065,6 @@ static char *uemis_get_divenr(char *deviceidstr, int force)
}
}
}
- if (max_deleted_seen >= 0 && maxdiveid < (uint32_t)max_deleted_seen) {
- maxdiveid = max_deleted_seen;
-#if UEMIS_DEBUG & 4
- fprintf(debugfile, "overriding max seen with max deleted seen %d\n", max_deleted_seen);
-#endif
- }
snprintf(divenr, 10, "%d", maxdiveid);
return strdup(divenr);
}
@@ -1082,6 +1076,7 @@ static bool do_dump_buffer_to_file(char *buf, char *prefix)
char path[100];
char date[40];
char obid[40];
+ bool success;
if (!buf)
return false;
@@ -1106,10 +1101,10 @@ static bool do_dump_buffer_to_file(char *buf, char *prefix)
int dumpFile = subsurface_open(path, O_RDWR | O_CREAT, 0666);
if (dumpFile == -1)
return false;
- write(dumpFile, buf, strlen(buf));
+ success = write(dumpFile, buf, strlen(buf)) == strlen(buf);
close(dumpFile);
bufCnt++;
- return true;
+ return success;
}
#endif
@@ -1269,7 +1264,6 @@ static bool get_matching_dive(int idx, char *newmax, int *uemis_mem_status, devi
fprintf(debugfile, "TRY matching dive log id %d from %s with dive details %d but details are deleted\n", dive->dc.diveid, d_time, dive_to_read);
#endif
deleted_files++;
- max_deleted_seen = dive_to_read;
/* mark this log entry as deleted and cleanup later, otherwise we mess up our array */
dive->downloaded = false;
#if UEMIS_DEBUG & 2