From: Bert Vermeulen Date: Wed, 7 Nov 2012 00:24:23 +0000 (+0100) Subject: serial_readline() now terminates on and strips CR and/or LF X-Git-Tag: dsupstream~578 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=318dd53c7093aa2ea26e0d246b23ffeb77b46707;p=libsigrok.git serial_readline() now terminates on and strips CR and/or LF --- diff --git a/hardware/common/serial.c b/hardware/common/serial.c index bc837a38..23bd42c3 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -621,8 +621,9 @@ SR_PRIV int serial_readline(int fd, char **buf, int *buflen, if (len > 0) { *buflen += len; *(*buf + *buflen) = '\0'; - if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') { - /* Strip LF and terminate. */ + if (*buflen > 0 && (*(*buf + *buflen - 1) == '\r' + || *(*buf + *buflen - 1) == '\n')) { + /* Strip CR/LF and terminate. */ *(*buf + --*buflen) = '\0'; break; } @@ -632,7 +633,8 @@ SR_PRIV int serial_readline(int fd, char **buf, int *buflen, break; g_usleep(2000); } - sr_dbg("Received %d: '%s'.", *buflen, *buf); + if (*buflen) + sr_dbg("Received %d: '%s'.", *buflen, *buf); return SR_OK; }