Rewrite isWriteModeEnabled() with API

This also introduces a slight behavioral change: Previously, only the
core file with the "raised" io desc was checked, which is RzIO.desc. But
that member is deprecated for good reasons, so now we just check if
there is any core file whose primary fd has write enabled.
This commit is contained in:
Florian Märkl 2022-03-14 10:01:48 +01:00
parent 9441c3b470
commit bca7a7a2a6

View File

@ -4042,12 +4042,18 @@ void CutterCore::setWriteMode(bool enabled)
bool CutterCore::isWriteModeEnabled()
{
for (CutterJson v : cmdj("oj")) {
if (v["raised"].toBool()) {
return v["writable"].toBool();
CORE_LOCK();
RzListIter *it;
RzCoreFile *cf;
CutterRzListForeach (core->files, it, RzCoreFile, cf) {
RzIODesc *desc = rz_io_desc_get(core->io, cf->fd);
if (!desc) {
continue;
}
if (desc->perm & RZ_PERM_W) {
return true;
}
}
return false;
}