serial_readline() now terminates on and strips CR and/or LF

This commit is contained in:
Bert Vermeulen 2012-11-07 01:24:23 +01:00
parent b87f8504dc
commit 318dd53c70
1 changed files with 5 additions and 3 deletions

View File

@ -621,8 +621,9 @@ SR_PRIV int serial_readline(int fd, char **buf, int *buflen,
if (len > 0) { if (len > 0) {
*buflen += len; *buflen += len;
*(*buf + *buflen) = '\0'; *(*buf + *buflen) = '\0';
if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') { if (*buflen > 0 && (*(*buf + *buflen - 1) == '\r'
/* Strip LF and terminate. */ || *(*buf + *buflen - 1) == '\n')) {
/* Strip CR/LF and terminate. */
*(*buf + --*buflen) = '\0'; *(*buf + --*buflen) = '\0';
break; break;
} }
@ -632,6 +633,7 @@ SR_PRIV int serial_readline(int fd, char **buf, int *buflen,
break; break;
g_usleep(2000); g_usleep(2000);
} }
if (*buflen)
sr_dbg("Received %d: '%s'.", *buflen, *buf); sr_dbg("Received %d: '%s'.", *buflen, *buf);
return SR_OK; return SR_OK;