mraa.c: we now remove trailing CR/LF from IIO dev names
authorAlex Tereschenko <alext.mkrs@gmail.com>
Sat, 10 Oct 2015 16:35:22 +0000 (18:35 +0200)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 15 Dec 2015 10:42:06 +0000 (10:42 +0000)
E.g. on Edison they have LFs and that may cause problems
with downstream consumers of this data.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/mraa.c

index 720a7cc..d115030 100644 (file)
@@ -173,9 +173,12 @@ mraa_init()
         if (fd > 0) {
             len = read(fd, &name, 64);
             if (len > 1) {
+                // remove any trailing CR/LF symbols
+                name[strcspn(name, "\r\n")] = '\0';
+                len = strlen(name);
                 // use strndup
                 device->name = malloc((sizeof(char) * len) + sizeof(char));
-                strncpy(device->name, name, len);
+                strncpy(device->name, name, len+1);
             }
             close(fd);
         }