mraa.c: we now remove trailing CR/LF from IIO dev names
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>
This commit is contained in:
committed by
Brendan Le Foll
parent
325ac461d6
commit
e5f28ab04c
@@ -173,9 +173,12 @@ mraa_init()
|
|||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
len = read(fd, &name, 64);
|
len = read(fd, &name, 64);
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
|
// remove any trailing CR/LF symbols
|
||||||
|
name[strcspn(name, "\r\n")] = '\0';
|
||||||
|
len = strlen(name);
|
||||||
// use strndup
|
// use strndup
|
||||||
device->name = malloc((sizeof(char) * len) + sizeof(char));
|
device->name = malloc((sizeof(char) * len) + sizeof(char));
|
||||||
strncpy(device->name, name, len);
|
strncpy(device->name, name, len+1);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user