fd = open(buf, O_RDONLY);
if (fd != -1) {
if (read(fd, readbuf, 2 * sizeof(char)) != 2) {
+ close(fd);
break;
}
chan_num = ((int) strtol(readbuf, NULL, 10));
int curr_bytes = 0;
char shortbuf, signchar;
memset(buf, 0, MAX_SIZE);
+ memset(readbuf, 0, 32);
snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS, dev->num);
dir = opendir(buf);
if (dir != NULL) {
int event_fd;
int fd;
- sprintf(bu, IIO_SLASH_DEV "%d", dev->num);
+ snprintf(bu, MAX_SIZE, IIO_SLASH_DEV "%d", dev->num);
fd = open(bu, 0);
- ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
- close(fd);
+ if (fd != -1) {
+ ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
+ close(fd);
+ } else {
+ return MRAA_ERROR_UNSPECIFIED;
+ }
if (ret == -1 || event_fd == -1)
return MRAA_ERROR_UNSPECIFIED;
struct stat configfs_status;
struct stat trigger_status;
char buf[MAX_SIZE];
+ int ret;
if (stat(IIO_CONFIGFS_TRIGGER, &configfs_status) == 0) {
memset(buf, 0, MAX_SIZE);
snprintf(buf, MAX_SIZE, IIO_CONFIGFS_TRIGGER "%s", trigger);
- if (stat(buf, &trigger_status) != 0) {
- if (mkdir(buf, configfs_status.st_mode) == 0)
- return MRAA_SUCCESS;
- } else {
- // trigger folder already created
- return MRAA_SUCCESS;
- }
+ // we actually don't care if this doesn't succeed, as it just means
+ // it's already been initialised
+ mkdir(buf, configfs_status.st_mode);
}
return MRAA_ERROR_UNSPECIFIED;
if (read(fd, readbuf, 2 * sizeof(char)) != 2) {
syslog(LOG_ERR, "iio: Failed to read a sensible value from sysfs");
free(str);
+ close(fd);
+ closedir(dir);
return -1;
}
chan->enabled = (int) strtol(readbuf, NULL, 10);
}
}
}
+ closedir(dir);
+ return MRAA_SUCCESS;
}
- return MRAA_SUCCESS;
+
+ return MRAA_ERROR_INVALID_HANDLE;
}
mraa_result_t