/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */ #include #include #include #include #include #include #include #include gs_error_t gs_sysfs_write_file(const char *path, const char *value) { log_trace("sysfs: write %s to %s", value, path); int fd = open(path, O_WRONLY); if (fd < 0) { return GS_ERROR_HANDLE; } size_t len = strlen(value); ssize_t bytes = write(fd, value, len); close(fd); if (bytes < 0) { return GS_ERROR_NO_DATA; } return (len == (size_t)bytes) ? GS_OK : GS_ERROR_NO_DATA; } gs_error_t gs_sysfs_read_file(const char *path, char *value, size_t len) { log_trace("sysfs: read %s", path); int fd = open(path, O_RDONLY); if (fd < 0) { return GS_ERROR_HANDLE; } ssize_t bytes = read(fd, value, len); close(fd); if (bytes < 0) { return GS_ERROR_DATA; } return GS_OK; }