util: fix reading sysfs

This commit is contained in:
Marcel Alexandru Nitan
2023-02-01 13:51:03 +02:00
parent 14e6e09bd4
commit 428659298b
2 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ char *get_gadget_root()
{ {
gadgetRoot = strjin(usbGadgetRoot, entry->d_name); gadgetRoot = strjin(usbGadgetRoot, entry->d_name);
udc = sysfs_read(strjin(gadgetRoot, "/UDC")); udc = sysfs_read(strjin(gadgetRoot, "/UDC"));
if (strcmp(udc, getprop("sys.usb.controller")) == 1) if (strcmp(udc, getprop("sys.usb.controller")) == 0)
break; break;
} }
} }
+10 -4
View File
@@ -65,13 +65,19 @@ void sysfs_write(char *path, char *content)
char *sysfs_read(char *path) char *sysfs_read(char *path)
{ {
char *value = nullptr; std::string value;
std::ifstream sysfsFile(path); std::ifstream sysfsFile(path);
sysfsFile >> path; if (!sysfsFile.is_open())
{
return nullptr;
}
sysfsFile >> value;
sysfsFile.close(); sysfsFile.close();
return value; char *result = new char[value.length() + 1];
} strcpy(result, value.c_str());
return result;
}
char *getprop(char *key) char *getprop(char *key)
{ {