summaryrefslogtreecommitdiff
path: root/src/venus_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/venus_api.c')
-rw-r--r--src/venus_api.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/venus_api.c b/src/venus_api.c
index 04ad78d..40a52ea 100644
--- a/src/venus_api.c
+++ b/src/venus_api.c
@@ -267,19 +267,24 @@ int venus_write_msg_read_ack(int fd, struct venus_msg *msg)
ssize_t venus_read_nmea_sentence(int fd, void *buf, size_t count)
{
- int err;
- char c;
ssize_t total = 0;
char *cp = buf;
-
int start = 0;
+ char c;
+ int err;
- while (1) {
+ if (!count) {
+ return 0;
+ }
+ count--;
+
+ while (count > 0) {
err = safe_read(fd, &c, 1);
if (err <= 0) {
log_error("read from gps failed: %m");
return -1;
}
+
if (!start) {
if (c != '$') {
continue;
@@ -287,16 +292,16 @@ ssize_t venus_read_nmea_sentence(int fd, void *buf, size_t count)
start = 1;
}
- if (total < count) {
- *cp++ = c;
- total++;
- }
+ cp[total++] = c;
+ count--;
if (c == '\n') {
break;
}
}
+ cp[total] = '\0';
+
return total;
}