mraa.c: Fix path of iio device in sysfs
authorBrendan Le Foll <brendan.le.foll@intel.com>
Mon, 28 Sep 2015 15:53:31 +0000 (16:53 +0100)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 15 Dec 2015 10:42:06 +0000 (10:42 +0000)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/mraa.c

index 6e2b6be..36f7dc6 100644 (file)
@@ -171,12 +171,14 @@ mraa_init()
     for (i=0; i < num_iio_devices; i++) {
         device = &plat->iio_devices[i];
         device->num = i;
-        snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d", i);
+        snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
         fd = open(filepath, O_RDONLY);
         if (fd != -1) {
             len = read(fd, &name, 64);
-            device->name = malloc((sizeof(char) * len) + sizeof(char));
-            strncpy(device->name, name, len);
+            if (len > 1) {
+                device->name = malloc((sizeof(char) * len) + sizeof(char));
+                strncpy(device->name, name, len);
+            }
         }
     }