From 7e6fa6b8cf905fb9b0695e154f2d1fdf10bb9b31 Mon Sep 17 00:00:00 2001 From: Marcel Alexandru Nitan Date: Tue, 31 Jan 2023 22:24:35 +0200 Subject: [PATCH] util: fix sysfs_write not writting to file --- src/util.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index f2f7efe..b0b778f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -58,17 +58,15 @@ bool isdir(char *path) void sysfs_write(char *path, char *content) { std::cout << "Write: " << content << " -> " << path << std::endl; - int fd; - if (fd = open(path, O_WRONLY) == -1) - { - perror("Failed to open sysfs file"); - return; + std::ofstream sysfsFile; + sysfsFile.open(path); + if (!sysfsFile.is_open()) { + perror("Failed to open sysfs path"); } - if (write(fd, content, strlen(content) == -1)) - { - perror("Failed to write sysfs file"); - } - close(fd); + sysfsFile << content; + perror("Status"); + sysfsFile.close(); + std::cout << std::endl; } @@ -84,6 +82,3 @@ char *getprop(char *key) return value; } - - -