summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ameerj2022-12-25 13:21:15 -0500
committerGravatar ameerj2022-12-25 13:21:15 -0500
commitfbc375f0de26342a22c52bb78e14b4f78d2243c1 (patch)
tree9b4b1bd226d3fd9595598ad8528a9c43077a5907
parenthle_ipc: Add ReadBufferSpan function (diff)
downloadyuzu-fbc375f0de26342a22c52bb78e14b4f78d2243c1.tar.gz
yuzu-fbc375f0de26342a22c52bb78e14b4f78d2243c1.tar.xz
yuzu-fbc375f0de26342a22c52bb78e14b4f78d2243c1.zip
fsp_srv: Use ReadBufferSpan
-rw-r--r--src/common/string_util.cpp2
-rw-r--r--src/common/string_util.h3
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp31
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) {
30 return str; 30 return str;
31} 31}
32 32
33std::string StringFromBuffer(const std::vector<u8>& data) { 33std::string StringFromBuffer(std::span<const u8> data) {
34 return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); 34 return std::string(data.begin(), std::find(data.begin(), data.end(), '\0'));
35} 35}
36 36
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 @@
5#pragma once 5#pragma once
6 6
7#include <cstddef> 7#include <cstddef>
8#include <span>
8#include <string> 9#include <string>
9#include <vector> 10#include <vector>
10#include "common/common_types.h" 11#include "common/common_types.h"
@@ -17,7 +18,7 @@ namespace Common {
17/// Make a string uppercase 18/// Make a string uppercase
18[[nodiscard]] std::string ToUpper(std::string str); 19[[nodiscard]] std::string ToUpper(std::string str);
19 20
20[[nodiscard]] std::string StringFromBuffer(const std::vector<u8>& data); 21[[nodiscard]] std::string StringFromBuffer(std::span<const u8> data);
21 22
22[[nodiscard]] std::string StripSpaces(const std::string& s); 23[[nodiscard]] std::string StripSpaces(const std::string& s);
23[[nodiscard]] std::string StripQuotes(const std::string& s); 24[[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:
190 return; 190 return;
191 } 191 }
192 192
193 const std::vector<u8> data = ctx.ReadBuffer(); 193 const auto data = ctx.ReadBufferSpan();
194 194
195 ASSERT_MSG( 195 ASSERT_MSG(
196 static_cast<s64>(data.size()) <= length, 196 static_cast<s64>(data.size()) <= length,
@@ -337,7 +337,7 @@ public:
337 void CreateFile(Kernel::HLERequestContext& ctx) { 337 void CreateFile(Kernel::HLERequestContext& ctx) {
338 IPC::RequestParser rp{ctx}; 338 IPC::RequestParser rp{ctx};
339 339
340 const auto file_buffer = ctx.ReadBuffer(); 340 const auto file_buffer = ctx.ReadBufferSpan();
341 const std::string name = Common::StringFromBuffer(file_buffer); 341 const std::string name = Common::StringFromBuffer(file_buffer);
342 342
343 const u64 file_mode = rp.Pop<u64>(); 343 const u64 file_mode = rp.Pop<u64>();
@@ -351,7 +351,7 @@ public:
351 } 351 }
352 352
353 void DeleteFile(Kernel::HLERequestContext& ctx) { 353 void DeleteFile(Kernel::HLERequestContext& ctx) {
354 const auto file_buffer = ctx.ReadBuffer(); 354 const auto file_buffer = ctx.ReadBufferSpan();
355 const std::string name = Common::StringFromBuffer(file_buffer); 355 const std::string name = Common::StringFromBuffer(file_buffer);
356 356
357 LOG_DEBUG(Service_FS, "called. file={}", name); 357 LOG_DEBUG(Service_FS, "called. file={}", name);
@@ -361,7 +361,7 @@ public:
361 } 361 }
362 362
363 void CreateDirectory(Kernel::HLERequestContext& ctx) { 363 void CreateDirectory(Kernel::HLERequestContext& ctx) {
364 const auto file_buffer = ctx.ReadBuffer(); 364 const auto file_buffer = ctx.ReadBufferSpan();
365 const std::string name = Common::StringFromBuffer(file_buffer); 365 const std::string name = Common::StringFromBuffer(file_buffer);
366 366
367 LOG_DEBUG(Service_FS, "called. directory={}", name); 367 LOG_DEBUG(Service_FS, "called. directory={}", name);
@@ -371,7 +371,7 @@ public:
371 } 371 }
372 372
373 void DeleteDirectory(Kernel::HLERequestContext& ctx) { 373 void DeleteDirectory(Kernel::HLERequestContext& ctx) {
374 const auto file_buffer = ctx.ReadBuffer(); 374 const auto file_buffer = ctx.ReadBufferSpan();
375 const std::string name = Common::StringFromBuffer(file_buffer); 375 const std::string name = Common::StringFromBuffer(file_buffer);
376 376
377 LOG_DEBUG(Service_FS, "called. directory={}", name); 377 LOG_DEBUG(Service_FS, "called. directory={}", name);
@@ -381,7 +381,7 @@ public:
381 } 381 }
382 382
383 void DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) { 383 void DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) {
384 const auto file_buffer = ctx.ReadBuffer(); 384 const auto file_buffer = ctx.ReadBufferSpan();
385 const std::string name = Common::StringFromBuffer(file_buffer); 385 const std::string name = Common::StringFromBuffer(file_buffer);
386 386
387 LOG_DEBUG(Service_FS, "called. directory={}", name); 387 LOG_DEBUG(Service_FS, "called. directory={}", name);
@@ -391,7 +391,7 @@ public:
391 } 391 }
392 392
393 void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) { 393 void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) {
394 const auto file_buffer = ctx.ReadBuffer(); 394 const auto file_buffer = ctx.ReadBufferSpan();
395 const std::string name = Common::StringFromBuffer(file_buffer); 395 const std::string name = Common::StringFromBuffer(file_buffer);
396 396
397 LOG_DEBUG(Service_FS, "called. Directory: {}", name); 397 LOG_DEBUG(Service_FS, "called. Directory: {}", name);
@@ -401,11 +401,8 @@ public:
401 } 401 }
402 402
403 void RenameFile(Kernel::HLERequestContext& ctx) { 403 void RenameFile(Kernel::HLERequestContext& ctx) {
404 std::vector<u8> buffer = ctx.ReadBuffer(0); 404 const std::string src_name = Common::StringFromBuffer(ctx.ReadBufferSpan(0));
405 const std::string src_name = Common::StringFromBuffer(buffer); 405 const std::string dst_name = Common::StringFromBuffer(ctx.ReadBufferSpan(1));
406
407 buffer = ctx.ReadBuffer(1);
408 const std::string dst_name = Common::StringFromBuffer(buffer);
409 406
410 LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); 407 LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name);
411 408
@@ -416,7 +413,7 @@ public:
416 void OpenFile(Kernel::HLERequestContext& ctx) { 413 void OpenFile(Kernel::HLERequestContext& ctx) {
417 IPC::RequestParser rp{ctx}; 414 IPC::RequestParser rp{ctx};
418 415
419 const auto file_buffer = ctx.ReadBuffer(); 416 const auto file_buffer = ctx.ReadBufferSpan();
420 const std::string name = Common::StringFromBuffer(file_buffer); 417 const std::string name = Common::StringFromBuffer(file_buffer);
421 418
422 const auto mode = static_cast<FileSys::Mode>(rp.Pop<u32>()); 419 const auto mode = static_cast<FileSys::Mode>(rp.Pop<u32>());
@@ -440,7 +437,7 @@ public:
440 void OpenDirectory(Kernel::HLERequestContext& ctx) { 437 void OpenDirectory(Kernel::HLERequestContext& ctx) {
441 IPC::RequestParser rp{ctx}; 438 IPC::RequestParser rp{ctx};
442 439
443 const auto file_buffer = ctx.ReadBuffer(); 440 const auto file_buffer = ctx.ReadBufferSpan();
444 const std::string name = Common::StringFromBuffer(file_buffer); 441 const std::string name = Common::StringFromBuffer(file_buffer);
445 442
446 // TODO(Subv): Implement this filter. 443 // TODO(Subv): Implement this filter.
@@ -463,7 +460,7 @@ public:
463 } 460 }
464 461
465 void GetEntryType(Kernel::HLERequestContext& ctx) { 462 void GetEntryType(Kernel::HLERequestContext& ctx) {
466 const auto file_buffer = ctx.ReadBuffer(); 463 const auto file_buffer = ctx.ReadBufferSpan();
467 const std::string name = Common::StringFromBuffer(file_buffer); 464 const std::string name = Common::StringFromBuffer(file_buffer);
468 465
469 LOG_DEBUG(Service_FS, "called. file={}", name); 466 LOG_DEBUG(Service_FS, "called. file={}", name);
@@ -504,7 +501,7 @@ public:
504 } 501 }
505 502
506 void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) { 503 void GetFileTimeStampRaw(Kernel::HLERequestContext& ctx) {
507 const auto file_buffer = ctx.ReadBuffer(); 504 const auto file_buffer = ctx.ReadBufferSpan();
508 const std::string name = Common::StringFromBuffer(file_buffer); 505 const std::string name = Common::StringFromBuffer(file_buffer);
509 506
510 LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); 507 LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name);
@@ -1086,7 +1083,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
1086} 1083}
1087 1084
1088void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { 1085void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) {
1089 const auto raw = ctx.ReadBuffer(); 1086 const auto raw = ctx.ReadBufferSpan();
1090 auto log = Common::StringFromFixedZeroTerminatedBuffer( 1087 auto log = Common::StringFromFixedZeroTerminatedBuffer(
1091 reinterpret_cast<const char*>(raw.data()), raw.size()); 1088 reinterpret_cast<const char*>(raw.data()), raw.size());
1092 1089