From 9d2404b486ae89a109335d0cfadfa1b1fd390503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Mon, 14 Mar 2022 10:01:48 +0100 Subject: [PATCH] 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. --- src/core/Cutter.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index d5db389b..b0731590 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -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; }