From fbc375f0de26342a22c52bb78e14b4f78d2243c1 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 25 Dec 2022 13:21:15 -0500 Subject: [PATCH] fsp_srv: Use ReadBufferSpan --- src/common/string_util.cpp | 2 +- src/common/string_util.h | 3 +- src/core/hle/service/filesystem/fsp_srv.cpp | 31 ++++++++++----------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index b26db4796..e0b6180c5 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -30,7 +30,7 @@ std::string ToUpper(std::string str) { return str; } -std::string StringFromBuffer(const std::vector& data) { +std::string StringFromBuffer(std::span data) { return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); } diff --git a/src/common/string_util.h b/src/common/string_util.h index ce18a33cf..f8aecc875 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "common/common_types.h" @@ -17,7 +18,7 @@ namespace Common { /// Make a string uppercase [[nodiscard]] std::string ToUpper(std::string str); -[[nodiscard]] std::string StringFromBuffer(const std::vector& data); +[[nodiscard]] std::string StringFromBuffer(std::span data); [[nodiscard]] std::string StripSpaces(const std::string& s); [[nodiscard]] std::string StripQuotes(const std::string& s); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index fbb16a7da..efebb0ccc 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -190,7 +190,7 @@ private: return; } - const std::vector data = ctx.ReadBuffer(); + const auto data = ctx.ReadBufferSpan(); ASSERT_MSG( static_cast(data.size()) <= length, @@ -337,7 +337,7 @@ public: void CreateFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); const u64 file_mode = rp.Pop(); @@ -351,7 +351,7 @@ public: } void DeleteFile(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. file={}", name); @@ -361,7 +361,7 @@ public: } void CreateDirectory(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -371,7 +371,7 @@ public: } void DeleteDirectory(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -381,7 +381,7 @@ public: } void DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. directory={}", name); @@ -391,7 +391,7 @@ public: } void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. Directory: {}", name); @@ -401,11 +401,8 @@ public: } void RenameFile(Kernel::HLERequestContext& ctx) { - std::vector buffer = ctx.ReadBuffer(0); - const std::string src_name = Common::StringFromBuffer(buffer); - - buffer = ctx.ReadBuffer(1); - const std::string dst_name = Common::StringFromBuffer(buffer); + const std::string src_name = Common::StringFromBuffer(ctx.ReadBufferSpan(0)); + const std::string dst_name = Common::StringFromBuffer(ctx.ReadBufferSpan(1)); LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); @@ -416,7 +413,7 @@ public: void OpenFile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); const auto mode = static_cast(rp.Pop()); @@ -440,7 +437,7 @@ public: void OpenDirectory(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); // TODO(Subv): Implement this filter. @@ -463,7 +460,7 @@ public: } void GetEntryType(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_DEBUG(Service_FS, "called. file={}", name); @@ -504,7 +501,7 @@ public: } void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); + const auto file_buffer = ctx.ReadBufferSpan(); const std::string name = Common::StringFromBuffer(file_buffer); LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); @@ -1086,7 +1083,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { } void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { - const auto raw = ctx.ReadBuffer(); + const auto raw = ctx.ReadBufferSpan(); auto log = Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(raw.data()), raw.size());