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

View File

@@ -25,7 +25,7 @@ char *get_gadget_root()
{
gadgetRoot = strjin(usbGadgetRoot, entry->d_name);
udc = sysfs_read(strjin(gadgetRoot, "/UDC"));
if (strcmp(udc, getprop("sys.usb.controller")) == 1)
if (strcmp(udc, getprop("sys.usb.controller")) == 0)
break;
}
}

View File

@@ -65,14 +65,20 @@ void sysfs_write(char *path, char *content)
char *sysfs_read(char *path)
{
char *value = nullptr;
std::string value;
std::ifstream sysfsFile(path);
sysfsFile >> path;
if (!sysfsFile.is_open())
{
return nullptr;
}
sysfsFile >> value;
sysfsFile.close();
return value;
char *result = new char[value.length() + 1];
strcpy(result, value.c_str());
return result;
}
char *getprop(char *key)
{
std::array<char, 128> buffer;