Browse Source

AP_Filesystem: tweak fgets()

This avoids that it returns False when encountering new lines or
\n\r
gps-1.3.1
Willian Galvani 3 years ago committed by Peter Barker
parent
commit
802974a337
  1. 7
      libraries/AP_Filesystem/AP_Filesystem.cpp

7
libraries/AP_Filesystem/AP_Filesystem.cpp

@ -260,7 +260,10 @@ bool AP_Filesystem::fgets(char *buf, uint8_t buflen, int fd) @@ -260,7 +260,10 @@ bool AP_Filesystem::fgets(char *buf, uint8_t buflen, int fd)
uint8_t i = 0;
for (; i<buflen-1; i++) {
if (backend.fs.read(fd, &buf[i], 1) != 1) {
if (backend.fs.read(fd, &buf[i], 1) <= 0) {
if (i==0) {
return false;
}
break;
}
if (buf[i] == '\r' || buf[i] == '\n') {
@ -268,7 +271,7 @@ bool AP_Filesystem::fgets(char *buf, uint8_t buflen, int fd) @@ -268,7 +271,7 @@ bool AP_Filesystem::fgets(char *buf, uint8_t buflen, int fd)
}
}
buf[i] = '\0';
return i != 0;
return true;
}
// format filesystem

Loading…
Cancel
Save