]> sigrok.org Git - libsigrok.git/commitdiff
serial_readline() now terminates on and strips CR and/or LF
authorBert Vermeulen <redacted>
Wed, 7 Nov 2012 00:24:23 +0000 (01:24 +0100)
committerBert Vermeulen <redacted>
Wed, 7 Nov 2012 00:24:23 +0000 (01:24 +0100)
hardware/common/serial.c

index bc837a3841f29e575eefa9ab5490cfe4ecf0475b..23bd42c387590e637a10e9aaef31262e964d835f 100644 (file)
@@ -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;
 }