summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-08-10 01:29:36 +0200
committerGitHub <noreply@github.com>2018-08-10 01:29:36 +0200
commit69cd213fac6b60dd044ec5598336c5b6cb201440 (patch)
tree121dadb00f25d4bea8f7c04c79b8aef4bc411b7b /src/core
parentMerge pull request #1001 from lioncash/reserve (diff)
parentfsp_srv: Use std::string_view's copy() function instead of strncpy() (diff)
downloadyuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.tar
yuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.tar.gz
yuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.tar.bz2
yuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.tar.lz
yuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.tar.xz
yuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.tar.zst
yuzu-69cd213fac6b60dd044ec5598336c5b6cb201440.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/file_sys/directory.h12
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp9
2 files changed, 12 insertions, 9 deletions
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
index 213ce1826..3759e743a 100644
--- a/src/core/file_sys/directory.h
+++ b/src/core/file_sys/directory.h
@@ -4,8 +4,9 @@
#pragma once
-#include <array>
#include <cstddef>
+#include <iterator>
+#include <string_view>
#include "common/common_funcs.h"
#include "common/common_types.h"
@@ -21,9 +22,14 @@ enum EntryType : u8 {
// Structure of a directory entry, from
// http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry
-const size_t FILENAME_LENGTH = 0x300;
struct Entry {
- char filename[FILENAME_LENGTH];
+ Entry(std::string_view view, EntryType entry_type, u64 entry_size)
+ : type{entry_type}, file_size{entry_size} {
+ const size_t copy_size = view.copy(filename, std::size(filename) - 1);
+ filename[copy_size] = '\0';
+ }
+
+ char filename[0x300];
INSERT_PADDING_BYTES(4);
EntryType type;
INSERT_PADDING_BYTES(3);
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index e7ffb6bd1..1470f9017 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -193,13 +193,10 @@ private:
template <typename T>
static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vector<T>& new_data,
FileSys::EntryType type) {
+ entries.reserve(entries.size() + new_data.size());
+
for (const auto& new_entry : new_data) {
- FileSys::Entry entry;
- entry.filename[0] = '\0';
- std::strncat(entry.filename, new_entry->GetName().c_str(), FileSys::FILENAME_LENGTH - 1);
- entry.type = type;
- entry.file_size = new_entry->GetSize();
- entries.emplace_back(std::move(entry));
+ entries.emplace_back(new_entry->GetName(), type, new_entry->GetSize());
}
}