util: report write errors in sysfs_write

This commit is contained in:
Marcel Alexandru Nitan
2023-01-31 21:22:18 +02:00
parent 28c95af44b
commit 5833dd5dd9

View File

@@ -59,11 +59,19 @@ void sysfs_write(char *path, char *content)
{
std::cout << "Write: " << content << " -> " << path << std::endl;
int fd;
fd = open(path, O_WRONLY);
write(fd, content, strlen(content));
if (fd = open(path, O_WRONLY) == -1)
{
perror("Failed to open sysfs file");
return;
}
if (write(fd, content, strlen(content) == -1))
{
perror("Failed to write sysfs file");
}
close(fd);
}
char *getprop(char *key)
{
std::array<char, 128> buffer;