From 094cede39ec59f183e81c0b1f7b3a8bbe89f3a30 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 12 Jan 2021 02:59:41 -0800 Subject: [PATCH] ams: use util::SNPrintf over std:: (size/linker improvements) --- .../include/stratosphere/fs/fs_path_utils.hpp | 2 +- .../stratosphere/kvdb/kvdb_bounded_string.hpp | 6 +++--- .../source/ams/ams_emummc_api.cpp | 6 +++--- .../libstratosphere/source/boot2/boot2_api.cpp | 2 +- .../libstratosphere/source/cfg/cfg_flags.cpp | 10 +++++----- .../libstratosphere/source/cfg/cfg_override.cpp | 8 ++++---- .../source/diag/diag_assertion_impl.cpp | 2 +- .../source/erpt/srv/erpt_srv_attachment.cpp | 2 +- .../source/erpt/srv/erpt_srv_report.cpp | 2 +- .../libstratosphere/source/fs/fs_access_log.cpp | 10 +++++----- libraries/libstratosphere/source/fs/fs_bis.cpp | 2 +- libraries/libstratosphere/source/fs/fs_code.cpp | 4 ++-- .../source/fs/fs_content_storage.cpp | 2 +- .../libstratosphere/source/fs/fs_game_card.cpp | 2 +- .../libstratosphere/source/fs/fs_sd_card.cpp | 2 +- .../source/fs/fsa/fs_mount_utils.cpp | 2 +- .../source/fssystem/fssystem_utility.cpp | 4 ++-- .../source/ncm/ncm_content_id_utils.cpp | 6 +++--- .../source/ncm/ncm_content_management_utils.cpp | 2 +- .../source/ncm/ncm_content_manager_impl.cpp | 8 ++++---- .../libstratosphere/source/ncm/ncm_fs_utils.cpp | 4 ++-- .../libstratosphere/source/ncm/ncm_make_path.cpp | 2 +- .../source/patcher/patcher_api.cpp | 6 +++--- .../source/pgl/srv/pgl_srv_shell.cpp | 6 +++--- .../source/pgl/srv/pgl_srv_shell_host_utils.cpp | 8 ++++---- .../include/vapours/util/util_uuid.hpp | 2 +- .../ams_mitm/source/amsmitm_fs_utils.cpp | 16 ++++++++-------- .../ams_mitm/source/amsmitm_initialization.cpp | 6 +++--- .../ams_mitm/source/amsmitm_prodinfo_utils.cpp | 10 +++++----- .../source/fs_mitm/fsmitm_save_utils.cpp | 4 ++-- .../source/set_mitm/setsys_mitm_service.cpp | 2 +- .../source/sysupdater/sysupdater_service.cpp | 6 +++--- .../creport/source/creport_crash_report.cpp | 6 +++--- stratosphere/creport/source/creport_modules.cpp | 6 +++--- .../creport/source/creport_scoped_file.cpp | 4 ++-- .../dmnt/source/cheat/impl/dmnt_cheat_api.cpp | 8 ++++---- .../dmnt/source/cheat/impl/dmnt_cheat_vm.cpp | 6 +++--- stratosphere/erpt/source/erpt_main.cpp | 4 ++-- stratosphere/fatal/source/fatal_font.cpp | 8 ++++---- stratosphere/fatal/source/fatal_scoped_file.cpp | 4 ++-- .../fatal/source/fatal_task_error_report.cpp | 4 ++-- 41 files changed, 103 insertions(+), 103 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp index 7ddeb8a78..04dc2f6c3 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_path_utils.hpp @@ -75,7 +75,7 @@ namespace ams::fs { /* Format the path. */ std::va_list va_list; va_start(va_list, format); - const size_t len = std::vsnprintf(dst->str, sizeof(dst->str), format, va_list); + const size_t len = util::VSNPrintf(dst->str, sizeof(dst->str), format, va_list); va_end(va_list); /* Validate length. */ diff --git a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp index 0c85ddc76..322a3641b 100644 --- a/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp +++ b/libraries/libstratosphere/include/stratosphere/kvdb/kvdb_bounded_string.hpp @@ -49,7 +49,7 @@ namespace ams::kvdb { std::va_list args; va_start(args, format); - CheckLength(std::vsnprintf(string.buffer, N, format, args)); + CheckLength(util::VSNPrintf(string.buffer, N, format, args)); string.buffer[N - 1] = 0; va_end(args); @@ -81,7 +81,7 @@ namespace ams::kvdb { /* Format into the buffer, abort if too large. */ std::va_list args; va_start(args, format); - CheckLength(std::vsnprintf(this->buffer, N, format, args)); + CheckLength(util::VSNPrintf(this->buffer, N, format, args)); va_end(args); } @@ -103,7 +103,7 @@ namespace ams::kvdb { const size_t length = GetLength(); std::va_list args; va_start(args, format); - CheckLength(std::vsnprintf(this->buffer + length, N - length, format, args) + length); + CheckLength(util::VSNPrintf(this->buffer + length, N - length, format, args) + length); va_end(args); } diff --git a/libraries/libstratosphere/source/ams/ams_emummc_api.cpp b/libraries/libstratosphere/source/ams/ams_emummc_api.cpp index 585cac264..02dd75f9c 100644 --- a/libraries/libstratosphere/source/ams/ams_emummc_api.cpp +++ b/libraries/libstratosphere/source/ams/ams_emummc_api.cpp @@ -88,14 +88,14 @@ namespace ams::emummc { /* Format paths. */ if (storage == Storage_SdFile) { - std::snprintf(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), "/%s", paths->file_path); + util::SNPrintf(g_exo_config.file_cfg.path, sizeof(g_exo_config.file_cfg.path), "/%s", paths->file_path); } - std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/%s", paths->nintendo_path); + util::SNPrintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/%s", paths->nintendo_path); /* If we're emummc, implement default nintendo redirection path. */ if (g_is_emummc && std::strcmp(g_exo_config.emu_dir_path, "/") == 0) { - std::snprintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id); + util::SNPrintf(g_exo_config.emu_dir_path, sizeof(g_exo_config.emu_dir_path), "/emummc/Nintendo_%04x", g_exo_config.base_cfg.id); } } diff --git a/libraries/libstratosphere/source/boot2/boot2_api.cpp b/libraries/libstratosphere/source/boot2/boot2_api.cpp index ad56ffac0..c089267b7 100644 --- a/libraries/libstratosphere/source/boot2/boot2_api.cpp +++ b/libraries/libstratosphere/source/boot2/boot2_api.cpp @@ -238,7 +238,7 @@ namespace ams::boot2 { /* Read the mitm list off the SD card. */ { char path[fs::EntryNameLengthMax]; - std::snprintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/mitm.lst", static_cast(program_id)); + util::SNPrintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/mitm.lst", static_cast(program_id)); fs::FileHandle f; if (R_FAILED(fs::OpenFile(&f, path, fs::OpenMode_Read))) { diff --git a/libraries/libstratosphere/source/cfg/cfg_flags.cpp b/libraries/libstratosphere/source/cfg/cfg_flags.cpp index abf078a09..be0b1bb03 100644 --- a/libraries/libstratosphere/source/cfg/cfg_flags.cpp +++ b/libraries/libstratosphere/source/cfg/cfg_flags.cpp @@ -23,7 +23,7 @@ namespace ams::cfg { /* Helper. */ void GetFlagMountName(char *dst) { - std::snprintf(dst, fs::MountNameLengthMax + 1, "#flag%08x", g_flag_mount_count.fetch_add(1)); + util::SNPrintf(dst, fs::MountNameLengthMax + 1, "#flag%08x", g_flag_mount_count.fetch_add(1)); } bool HasFlagFile(const char *flag_path) { @@ -42,7 +42,7 @@ namespace ams::cfg { /* Check if the entry exists. */ char full_path[fs::EntryNameLengthMax + 1]; - std::snprintf(full_path, sizeof(full_path), "%s:/%s", mount_name, flag_path[0] == '/' ? flag_path + 1 : flag_path); + util::SNPrintf(full_path, sizeof(full_path), "%s:/%s", mount_name, flag_path[0] == '/' ? flag_path + 1 : flag_path); bool has_file; if (R_FAILED(fs::HasFile(std::addressof(has_file), full_path))) { @@ -61,19 +61,19 @@ namespace ams::cfg { bool HasContentSpecificFlag(ncm::ProgramId program_id, const char *flag) { char content_flag[fs::EntryNameLengthMax + 1]; - std::snprintf(content_flag, sizeof(content_flag) - 1, "/atmosphere/contents/%016lx/flags/%s.flag", static_cast(program_id), flag); + util::SNPrintf(content_flag, sizeof(content_flag) - 1, "/atmosphere/contents/%016lx/flags/%s.flag", static_cast(program_id), flag); return HasFlagFile(content_flag); } bool HasGlobalFlag(const char *flag) { char global_flag[fs::EntryNameLengthMax + 1]; - std::snprintf(global_flag, sizeof(global_flag) - 1, "/atmosphere/flags/%s.flag", flag); + util::SNPrintf(global_flag, sizeof(global_flag) - 1, "/atmosphere/flags/%s.flag", flag); return HasFlagFile(global_flag); } bool HasHblFlag(const char *flag) { char hbl_flag[0x100]; - std::snprintf(hbl_flag, sizeof(hbl_flag) - 1, "hbl_%s", flag); + util::SNPrintf(hbl_flag, sizeof(hbl_flag) - 1, "hbl_%s", flag); return HasGlobalFlag(hbl_flag); } diff --git a/libraries/libstratosphere/source/cfg/cfg_override.cpp b/libraries/libstratosphere/source/cfg/cfg_override.cpp index fb819e29a..d7ffd145c 100644 --- a/libraries/libstratosphere/source/cfg/cfg_override.cpp +++ b/libraries/libstratosphere/source/cfg/cfg_override.cpp @@ -252,7 +252,7 @@ namespace ams::cfg { while (*value == '/' || *value == '\\') { value++; } - std::snprintf(g_hbl_sd_path, sizeof(g_hbl_sd_path) - 1, "/%s", value); + util::SNPrintf(g_hbl_sd_path, sizeof(g_hbl_sd_path) - 1, "/%s", value); g_hbl_sd_path[sizeof(g_hbl_sd_path) - 1] = '\0'; for (size_t i = 0; i < sizeof(g_hbl_sd_path); i++) { @@ -332,7 +332,7 @@ namespace ams::cfg { std::atomic g_ini_mount_count; void GetIniMountName(char *dst) { - std::snprintf(dst, fs::MountNameLengthMax + 1, "#ini%08x", g_ini_mount_count.fetch_add(1)); + util::SNPrintf(dst, fs::MountNameLengthMax + 1, "#ini%08x", g_ini_mount_count.fetch_add(1)); } void ParseIniFile(util::ini::Handler handler, const char *path, void *user_ctx) { @@ -348,7 +348,7 @@ namespace ams::cfg { fs::FileHandle file; { char full_path[fs::EntryNameLengthMax + 1]; - std::snprintf(full_path, sizeof(full_path), "%s:/%s", mount_name, path[0] == '/' ? path + 1 : path); + util::SNPrintf(full_path, sizeof(full_path), "%s:/%s", mount_name, path[0] == '/' ? path + 1 : path); if (R_FAILED(fs::OpenFile(std::addressof(file), full_path, fs::OpenMode_Read))) { return; } @@ -365,7 +365,7 @@ namespace ams::cfg { ContentSpecificOverrideConfig GetContentOverrideConfig(ncm::ProgramId program_id) { char path[fs::EntryNameLengthMax + 1]; - std::snprintf(path, sizeof(path), "/atmosphere/contents/%016lx/config.ini", static_cast(program_id)); + util::SNPrintf(path, sizeof(path), "/atmosphere/contents/%016lx/config.ini", static_cast(program_id)); ContentSpecificOverrideConfig config = { .override_key = g_default_override_key, diff --git a/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp index 11f6f4d20..77e41c0b1 100644 --- a/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp +++ b/libraries/libstratosphere/source/diag/diag_assertion_impl.cpp @@ -50,7 +50,7 @@ namespace ams::diag { void DebugLogImpl(const char *format, ::std::va_list vl) { std::scoped_lock lk(g_debug_log_lock); - std::vsnprintf(g_debug_buffer, sizeof(g_debug_buffer), format, vl); + util::VSNPrintf(g_debug_buffer, sizeof(g_debug_buffer), format, vl); svc::OutputDebugString(g_debug_buffer, strlen(g_debug_buffer)); } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp index 37f44d482..a4c89988e 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment.cpp @@ -24,7 +24,7 @@ namespace ams::erpt::srv { attachment_id.uuid.ToString(uuid_str, sizeof(uuid_str)); AttachmentFileName attachment_name; - std::snprintf(attachment_name.name, sizeof(attachment_name.name), "%s:/%s.att", ReportStoragePath, uuid_str); + util::SNPrintf(attachment_name.name, sizeof(attachment_name.name), "%s:/%s.att", ReportStoragePath, uuid_str); return attachment_name; } diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp index 290621fd8..197c251a2 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report.cpp @@ -21,7 +21,7 @@ namespace ams::erpt::srv { ReportFileName Report::FileName(ReportId report_id, bool redirect_to_sd) { ReportFileName report_name; - std::snprintf(report_name.name, sizeof(report_name.name), + util::SNPrintf(report_name.name, sizeof(report_name.name), "%s:/%08x-%04x-%04x-%02x%02x-%04x%08x", (redirect_to_sd ? ReportOnSdStoragePath : ReportStoragePath), report_id.uuid_data.time_low, diff --git a/libraries/libstratosphere/source/fs/fs_access_log.cpp b/libraries/libstratosphere/source/fs/fs_access_log.cpp index 7f06278a6..3db8f330b 100644 --- a/libraries/libstratosphere/source/fs/fs_access_log.cpp +++ b/libraries/libstratosphere/source/fs/fs_access_log.cpp @@ -80,7 +80,7 @@ namespace ams::fs { namespace ams::fs::impl { const char *IdString::ToValueString(int id) { - const int len = std::snprintf(this->buffer, sizeof(this->buffer), "%d", id); + const int len = util::SNPrintf(this->buffer, sizeof(this->buffer), "%d", id); AMS_ASSERT(static_cast(len) < sizeof(this->buffer)); return this->buffer; } @@ -202,7 +202,7 @@ namespace ams::fs::impl { return; } - const auto size = std::vsnprintf(log_buffer.get(), log_buffer_size, format, vl); + const auto size = util::VSNPrintf(log_buffer.get(), log_buffer_size, format, vl); if (size < log_buffer_size) { break; } @@ -233,7 +233,7 @@ namespace ams::fs::impl { return; } - const auto size = std::vsnprintf(str_buffer.get(), str_buffer_size, format, vl); + const auto size = util::VSNPrintf(str_buffer.get(), str_buffer_size, format, vl); if (size < str_buffer_size) { break; } @@ -269,7 +269,7 @@ namespace ams::fs::impl { return; } - log_buffer_size = 1 + std::snprintf(log_buffer.get(), try_size, FormatString, start_ms, end_ms, result.GetValue(), handle, priority, name, str_buffer.get()); + log_buffer_size = 1 + util::SNPrintf(log_buffer.get(), try_size, FormatString, start_ms, end_ms, result.GetValue(), handle, priority, name, str_buffer.get()); if (log_buffer_size <= try_size) { break; } @@ -312,7 +312,7 @@ namespace ams::fs::impl { " }\n"; char log_buffer[0x80]; - const int len = 1 + std::snprintf(log_buffer, sizeof(log_buffer), StartLog, static_cast(program_index)); + const int len = 1 + util::SNPrintf(log_buffer, sizeof(log_buffer), StartLog, static_cast(program_index)); if (static_cast(len) <= sizeof(log_buffer)) { OutputAccessLogImpl(log_buffer, len); } diff --git a/libraries/libstratosphere/source/fs/fs_bis.cpp b/libraries/libstratosphere/source/fs/fs_bis.cpp index 0d9694cd9..021913d71 100644 --- a/libraries/libstratosphere/source/fs/fs_bis.cpp +++ b/libraries/libstratosphere/source/fs/fs_bis.cpp @@ -33,7 +33,7 @@ namespace ams::fs { AMS_ABORT_UNLESS(dst_size >= needed_size); /* Generate the name. */ - auto size = std::snprintf(dst, dst_size, "%s:", bis_mount_name); + auto size = util::SNPrintf(dst, dst_size, "%s:", bis_mount_name); AMS_ASSERT(static_cast(size) == needed_size - 1); return ResultSuccess(); diff --git a/libraries/libstratosphere/source/fs/fs_code.cpp b/libraries/libstratosphere/source/fs/fs_code.cpp index 00e6a3481..3e706728d 100644 --- a/libraries/libstratosphere/source/fs/fs_code.cpp +++ b/libraries/libstratosphere/source/fs/fs_code.cpp @@ -172,7 +172,7 @@ namespace ams::fs { /* Create a redirection filesystem to the relevant content folder. */ char path[fs::EntryNameLengthMax + 1]; - std::snprintf(path, sizeof(path), "/atmosphere/contents/%016lx/exefs", program_id.value); + util::SNPrintf(path, sizeof(path), "/atmosphere/contents/%016lx/exefs", program_id.value); auto subdir_fs = std::make_unique(std::move(sd_fs), path); if (subdir_fs == nullptr) { @@ -190,7 +190,7 @@ namespace ams::fs { /* Create a path representing the stub. */ char stub_path[fs::EntryNameLengthMax + 1]; - std::snprintf(stub_path, sizeof(stub_path), "%s.stub", path); + util::SNPrintf(stub_path, sizeof(stub_path), "%s.stub", path); /* Query whether we have the file. */ bool has_file; diff --git a/libraries/libstratosphere/source/fs/fs_content_storage.cpp b/libraries/libstratosphere/source/fs/fs_content_storage.cpp index 3a0a7a717..96b31fb5b 100644 --- a/libraries/libstratosphere/source/fs/fs_content_storage.cpp +++ b/libraries/libstratosphere/source/fs/fs_content_storage.cpp @@ -32,7 +32,7 @@ namespace ams::fs { AMS_ABORT_UNLESS(dst_size >= needed_size); /* Generate the name. */ - auto size = std::snprintf(dst, dst_size, "%s:", GetContentStorageMountName(id)); + auto size = util::SNPrintf(dst, dst_size, "%s:", GetContentStorageMountName(id)); AMS_ASSERT(static_cast(size) == needed_size - 1); return ResultSuccess(); diff --git a/libraries/libstratosphere/source/fs/fs_game_card.cpp b/libraries/libstratosphere/source/fs/fs_game_card.cpp index d2ac95235..1e9739300 100644 --- a/libraries/libstratosphere/source/fs/fs_game_card.cpp +++ b/libraries/libstratosphere/source/fs/fs_game_card.cpp @@ -42,7 +42,7 @@ namespace ams::fs { AMS_ABORT_UNLESS(dst_size >= needed_size); /* Generate the name. */ - auto size = std::snprintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle); + auto size = util::SNPrintf(dst, dst_size, "%s%s%08x:", impl::GameCardFileSystemMountName, GetGameCardMountNameSuffix(this->partition), this->handle); AMS_ASSERT(static_cast(size) == needed_size - 1); return ResultSuccess(); diff --git a/libraries/libstratosphere/source/fs/fs_sd_card.cpp b/libraries/libstratosphere/source/fs/fs_sd_card.cpp index 576116ef9..d001cef8c 100644 --- a/libraries/libstratosphere/source/fs/fs_sd_card.cpp +++ b/libraries/libstratosphere/source/fs/fs_sd_card.cpp @@ -34,7 +34,7 @@ namespace ams::fs { AMS_ABORT_UNLESS(dst_size >= needed_size); /* Generate the name. */ - auto size = std::snprintf(dst, dst_size, "%s:", impl::SdCardFileSystemMountName); + auto size = util::SNPrintf(dst, dst_size, "%s:", impl::SdCardFileSystemMountName); AMS_ASSERT(static_cast(size) == needed_size - 1); return ResultSuccess(); diff --git a/libraries/libstratosphere/source/fs/fsa/fs_mount_utils.cpp b/libraries/libstratosphere/source/fs/fsa/fs_mount_utils.cpp index aeb04ee83..45f5a545c 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_mount_utils.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_mount_utils.cpp @@ -151,7 +151,7 @@ namespace ams::fs { AMS_FS_R_TRY(accessor->GetCommonMountName(dst, dst_size)); const auto mount_name_len = strnlen(dst, dst_size); - const auto common_path_len = std::snprintf(dst + mount_name_len, dst_size - mount_name_len, "%s", sub_path); + const auto common_path_len = util::SNPrintf(dst + mount_name_len, dst_size - mount_name_len, "%s", sub_path); AMS_FS_R_UNLESS(static_cast(common_path_len) < dst_size - mount_name_len, fs::ResultTooLongPath()); return ResultSuccess(); diff --git a/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp b/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp index 760f3c25b..cbfba3fc9 100644 --- a/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp +++ b/libraries/libstratosphere/source/fssystem/fssystem_utility.cpp @@ -78,7 +78,7 @@ namespace ams::fssystem { std::unique_ptr dst_file; { char dst_path[fs::EntryNameLengthMax + 1]; - const size_t original_size = static_cast(std::snprintf(dst_path, sizeof(dst_path), "%s%s", dst_parent_path, entry->name)); + const size_t original_size = static_cast(util::SNPrintf(dst_path, sizeof(dst_path), "%s%s", dst_parent_path, entry->name)); /* TODO: Error code? N aborts here. */ AMS_ABORT_UNLESS(original_size < sizeof(dst_path)); @@ -103,7 +103,7 @@ namespace ams::fssystem { Result CopyDirectoryRecursively(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) { char dst_path_buf[fs::EntryNameLengthMax + 1]; - const size_t original_size = static_cast(std::snprintf(dst_path_buf, sizeof(dst_path_buf), "%s", dst_path)); + const size_t original_size = static_cast(util::SNPrintf(dst_path_buf, sizeof(dst_path_buf), "%s", dst_path)); AMS_ABORT_UNLESS(original_size < sizeof(dst_path_buf)); return IterateDirectoryRecursively(src_fs, src_path, diff --git a/libraries/libstratosphere/source/ncm/ncm_content_id_utils.cpp b/libraries/libstratosphere/source/ncm/ncm_content_id_utils.cpp index a0a27b9d1..389b27b66 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_id_utils.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_id_utils.cpp @@ -21,7 +21,7 @@ namespace ams::ncm { void GetStringFromBytes(char *dst, const void *src, size_t count) { for (size_t i = 0; i < count; i++) { - std::snprintf(dst + 2 * i, 3, "%02x", static_cast(src)[i]); + util::SNPrintf(dst + 2 * i, 3, "%02x", static_cast(src)[i]); } } @@ -68,14 +68,14 @@ namespace ams::ncm { AMS_ABORT_UNLESS(dst_size > TicketFileStringLength); ContentIdString str; GetStringFromRightsId(str.data, sizeof(str), id); - std::snprintf(dst, dst_size, "%s.tik", str.data); + util::SNPrintf(dst, dst_size, "%s.tik", str.data); } void GetCertificateFileStringFromRightsId(char *dst, size_t dst_size, fs::RightsId id) { AMS_ABORT_UNLESS(dst_size > CertFileStringLength); ContentIdString str; GetStringFromRightsId(str.data, sizeof(str), id); - std::snprintf(dst, dst_size, "%s.cert", str.data); + util::SNPrintf(dst, dst_size, "%s.cert", str.data); } std::optional GetContentIdFromString(const char *str, size_t len) { diff --git a/libraries/libstratosphere/source/ncm/ncm_content_management_utils.cpp b/libraries/libstratosphere/source/ncm/ncm_content_management_utils.cpp index 170cc6fac..9c2403a95 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_management_utils.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_management_utils.cpp @@ -25,7 +25,7 @@ namespace ams::ncm { Result ConvertToFsCommonPath(char *dst, size_t dst_size, const char *package_root_path, const char *entry_path) { char package_path[MaxPackagePathLength]; - const size_t path_len = std::snprintf(package_path, sizeof(package_path), "%s%s", package_root_path, entry_path); + const size_t path_len = util::SNPrintf(package_path, sizeof(package_path), "%s%s", package_root_path, entry_path); AMS_ABORT_UNLESS(path_len < MaxPackagePathLength); return fs::ConvertToFsCommonPath(dst, dst_size, package_path); diff --git a/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp index 7302acc19..8915f7688 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp @@ -122,7 +122,7 @@ namespace ams::ncm { /* This also works on < 4.0.0 (though the system partition will never be on-sd there), */ /* and so this will always return false. */ char path[fs::MountNameLengthMax + 2 /* :/ */ + 1]; - std::snprintf(path, sizeof(path), "%s:/", bis_mount_name); + util::SNPrintf(path, sizeof(path), "%s:/", bis_mount_name); return fs::IsSignedSystemPartitionOnSdCardValid(path); } else { /* On 4.0.0-7.0.1, use the remote command to validate the system partition. */ @@ -203,7 +203,7 @@ namespace ams::ncm { /* Create a new mount name and copy it to out. */ std::strcpy(out->mount_name, impl::CreateUniqueMountName().str); - std::snprintf(out->path, sizeof(out->path), "%s:/", out->mount_name); + util::SNPrintf(out->path, sizeof(out->path), "%s:/", out->mount_name); return ResultSuccess(); } @@ -214,7 +214,7 @@ namespace ams::ncm { /* Create a new mount name and copy it to out. */ std::strcpy(out->mount_name, impl::CreateUniqueMountName().str); - std::snprintf(out->path, sizeof(out->path), "%s:/", out->mount_name); + util::SNPrintf(out->path, sizeof(out->path), "%s:/", out->mount_name); return ResultSuccess(); } @@ -230,7 +230,7 @@ namespace ams::ncm { /* Create a new mount name and copy it to out. */ std::strcpy(out->mount_name, impl::CreateUniqueMountName().str); out->mount_name[0] = '#'; - std::snprintf(out->path, sizeof(out->path), "%s:/meta", out->mount_name); + util::SNPrintf(out->path, sizeof(out->path), "%s:/meta", out->mount_name); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/ncm/ncm_fs_utils.cpp b/libraries/libstratosphere/source/ncm/ncm_fs_utils.cpp index f73698689..848ace07e 100644 --- a/libraries/libstratosphere/source/ncm/ncm_fs_utils.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_fs_utils.cpp @@ -39,13 +39,13 @@ namespace ams::ncm::impl { MountName CreateUniqueMountName() { MountName name = {}; - std::snprintf(name.str, sizeof(name.str), "@ncm%08x", g_mount_name_count.fetch_add(1)); + util::SNPrintf(name.str, sizeof(name.str), "@ncm%08x", g_mount_name_count.fetch_add(1)); return name; } RootDirectoryPath GetRootDirectoryPath(const MountName &mount_name) { RootDirectoryPath path = {}; - std::snprintf(path.str, sizeof(path.str), "%s:/", mount_name.str); + util::SNPrintf(path.str, sizeof(path.str), "%s:/", mount_name.str); return path; } diff --git a/libraries/libstratosphere/source/ncm/ncm_make_path.cpp b/libraries/libstratosphere/source/ncm/ncm_make_path.cpp index 594f912e6..9dafc3bec 100644 --- a/libraries/libstratosphere/source/ncm/ncm_make_path.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_make_path.cpp @@ -29,7 +29,7 @@ namespace ams::ncm { /* Create a hex string from bytes. */ for (size_t i = 0; i < sizeof(bytes); i++) { - std::snprintf(tmp, util::size(tmp), "%02x", bytes[i]); + util::SNPrintf(tmp, util::size(tmp), "%02x", bytes[i]); out->Append(tmp); } diff --git a/libraries/libstratosphere/source/patcher/patcher_api.cpp b/libraries/libstratosphere/source/patcher/patcher_api.cpp index d13fabbaa..177b80d94 100644 --- a/libraries/libstratosphere/source/patcher/patcher_api.cpp +++ b/libraries/libstratosphere/source/patcher/patcher_api.cpp @@ -217,7 +217,7 @@ namespace ams::patcher { /* Inspect all patches from /atmosphere//<*>/<*>.ips */ char path[fs::EntryNameLengthMax + 1]; - std::snprintf(path, sizeof(path), "%s:/atmosphere/%s", mount_name, patch_dir_name); + util::SNPrintf(path, sizeof(path), "%s:/atmosphere/%s", mount_name, patch_dir_name); const size_t patches_dir_path_len = std::strlen(path); /* Open the patch directory. */ @@ -237,7 +237,7 @@ namespace ams::patcher { } /* Print the path for this directory. */ - std::snprintf(path + patches_dir_path_len, sizeof(path) - patches_dir_path_len, "/%s", entry.name); + util::SNPrintf(path + patches_dir_path_len, sizeof(path) - patches_dir_path_len, "/%s", entry.name); const size_t patch_dir_path_len = patches_dir_path_len + 1 + std::strlen(entry.name); /* Open the patch directory. */ @@ -259,7 +259,7 @@ namespace ams::patcher { } /* Print the path for this file. */ - std::snprintf(path + patch_dir_path_len, sizeof(path) - patch_dir_path_len, "/%s", entry.name); + util::SNPrintf(path + patch_dir_path_len, sizeof(path) - patch_dir_path_len, "/%s", entry.name); /* Open the file. */ fs::FileHandle file; diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp index ef4185319..045c40fdc 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell.cpp @@ -124,9 +124,9 @@ namespace ams::pgl::srv { const s32 dump_arg = ConvertDumpTypeToArgument(dump_type); const s32 log_arg = GetSnapShotDumpOutputAllLog(process_id) ? 1 : 0; if (str_arg != nullptr) { - return std::snprintf(dst, dst_size, "D %010llu \"%s\" -log %d -dump %d", static_cast(static_cast(process_id)), str_arg, log_arg, dump_arg); + return util::SNPrintf(dst, dst_size, "D %010llu \"%s\" -log %d -dump %d", static_cast(static_cast(process_id)), str_arg, log_arg, dump_arg); } else { - return std::snprintf(dst, dst_size, "D %010llu -log %d -dump %d", static_cast(static_cast(process_id)), log_arg, dump_arg); + return util::SNPrintf(dst, dst_size, "D %010llu -log %d -dump %d", static_cast(static_cast(process_id)), log_arg, dump_arg); } } @@ -215,7 +215,7 @@ namespace ams::pgl::srv { /* Generate arguments. */ char arguments[0x40]; - const size_t len = std::snprintf(arguments, sizeof(arguments), "%ld %d %d %d", static_cast(static_cast(process_id)), GetCrashReportDetailedArgument(data_flags), GetCrashReportScreenShotArgument(data_flags), g_enable_jit_debug); + const size_t len = util::SNPrintf(arguments, sizeof(arguments), "%ld %d %d %d", static_cast(static_cast(process_id)), GetCrashReportDetailedArgument(data_flags), GetCrashReportScreenShotArgument(data_flags), g_enable_jit_debug); if (R_FAILED(ldr::SetProgramArgument(ncm::SystemProgramId::Creport, arguments, len + 1))) { return; } diff --git a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp index 95aa6d23c..a40c03d0d 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_host_utils.cpp @@ -174,7 +174,7 @@ namespace ams::pgl::srv { /* Get the file name. */ char file_name[ncm::ContentIdStringLength + 5]; - const size_t len = std::snprintf(file_name, sizeof(file_name), "%s.nca", id_str.data); + const size_t len = util::SNPrintf(file_name, sizeof(file_name), "%s.nca", id_str.data); R_UNLESS(len + 1 == sizeof(file_name), pgl::ResultBufferNotEnough()); /* Ensure we have the content. */ @@ -199,7 +199,7 @@ namespace ams::pgl::srv { /* Get the file name. */ /* NSPD does not support indexed content, so we always use 0 as the index. */ char file_name[0x20]; - const size_t len = std::snprintf(file_name, sizeof(file_name), "%s%d.ncd", content_name, 0); + const size_t len = util::SNPrintf(file_name, sizeof(file_name), "%s%d.ncd", content_name, 0); R_UNLESS(len + 1 <= sizeof(file_name), pgl::ResultBufferNotEnough()); /* Ensure we have the content. */ @@ -267,7 +267,7 @@ namespace ams::pgl::srv { Result SearchContent(bool *out, lr::Path *out_path, const char *extension, fs::OpenDirectoryMode mode) const { /* Generate the root directory path. */ char root_dir[sizeof(this->mount_name) + 2]; - std::snprintf(root_dir, sizeof(root_dir), "%s:/", this->mount_name); + util::SNPrintf(root_dir, sizeof(root_dir), "%s:/", this->mount_name); /* Open the root directory. */ fs::DirectoryHandle dir; @@ -287,7 +287,7 @@ namespace ams::pgl::srv { if (HasSuffix(entry.name, extension)) { *out = true; if (out_path) { - const size_t len = std::snprintf(out_path->str, sizeof(out_path->str), "%s/%s", this->content_path, entry.name); + const size_t len = util::SNPrintf(out_path->str, sizeof(out_path->str), "%s/%s", this->content_path, entry.name); R_UNLESS(len + 1 < sizeof(out_path->str), pgl::ResultBufferNotEnough()); if (entry.type == fs::DirectoryEntryType_Directory) { out_path->str[len] = '/'; diff --git a/libraries/libvapours/include/vapours/util/util_uuid.hpp b/libraries/libvapours/include/vapours/util/util_uuid.hpp index 2a75a9797..f876fb5eb 100644 --- a/libraries/libvapours/include/vapours/util/util_uuid.hpp +++ b/libraries/libvapours/include/vapours/util/util_uuid.hpp @@ -35,7 +35,7 @@ namespace ams::util { } const char *ToString(char *dst, size_t dst_size) const { - std::snprintf(dst, dst_size, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + util::SNPrintf(dst, dst_size, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", this->data[ 0], this->data[ 1], this->data[ 2], this->data[ 3], this->data[ 4], this->data[ 5], this->data[ 6], this->data[ 7], this->data[ 8], this->data[ 9], this->data[10], this->data[11], this->data[12], this->data[13], this->data[14], this->data[15]); diff --git a/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp b/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp index c43c92ca7..de7bc6eb0 100644 --- a/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_fs_utils.cpp @@ -124,33 +124,33 @@ namespace ams::mitm::fs { void FormatAtmosphereSdPath(char *dst_path, size_t dst_path_size, const char *src_path) { if (src_path[0] == '/') { - std::snprintf(dst_path, dst_path_size, "/atmosphere%s", src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere%s", src_path); } else { - std::snprintf(dst_path, dst_path_size, "/atmosphere/%s", src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/%s", src_path); } } void FormatAtmosphereSdPath(char *dst_path, size_t dst_path_size, const char *subdir, const char *src_path) { if (src_path[0] == '/') { - std::snprintf(dst_path, dst_path_size, "/atmosphere/%s%s", subdir, src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/%s%s", subdir, src_path); } else { - std::snprintf(dst_path, dst_path_size, "/atmosphere/%s/%s", subdir, src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/%s/%s", subdir, src_path); } } void FormatAtmosphereSdPath(char *dst_path, size_t dst_path_size, ncm::ProgramId program_id, const char *src_path) { if (src_path[0] == '/') { - std::snprintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx%s", static_cast(program_id), src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx%s", static_cast(program_id), src_path); } else { - std::snprintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s", static_cast(program_id), src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s", static_cast(program_id), src_path); } } void FormatAtmosphereSdPath(char *dst_path, size_t dst_path_size, ncm::ProgramId program_id, const char *subdir, const char *src_path) { if (src_path[0] == '/') { - std::snprintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s%s", static_cast(program_id), subdir, src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s%s", static_cast(program_id), subdir, src_path); } else { - std::snprintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s/%s", static_cast(program_id), subdir, src_path); + util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s/%s", static_cast(program_id), subdir, src_path); } } diff --git a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp index 38759498a..ecd395a61 100644 --- a/stratosphere/ams_mitm/source/amsmitm_initialization.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_initialization.cpp @@ -81,9 +81,9 @@ namespace ams::mitm { void GetBackupFileName(char *dst, size_t dst_size, const char *serial_number, const char *fn) { if (strlen(serial_number) > 0) { - std::snprintf(dst, dst_size, "automatic_backups/%s_%s", serial_number, fn); + util::SNPrintf(dst, dst_size, "automatic_backups/%s_%s", serial_number, fn); } else { - std::snprintf(dst, dst_size, "automatic_backups/%s", fn); + util::SNPrintf(dst, dst_size, "automatic_backups/%s", fn); } } @@ -166,7 +166,7 @@ namespace ams::mitm { if (emummc::IsActive()) { if (const char *emummc_file_path = emummc::GetFilePath(); emummc_file_path != nullptr) { char emummc_path[ams::fs::EntryNameLengthMax + 1]; - std::snprintf(emummc_path, sizeof(emummc_path), "%s/eMMC", emummc_file_path); + util::SNPrintf(emummc_path, sizeof(emummc_path), "%s/eMMC", emummc_file_path); mitm::fs::OpenSdFile(&g_emummc_file, emummc_path, ams::fs::OpenMode_Read); } } diff --git a/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp b/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp index a624b0da5..87f57d5a6 100644 --- a/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp +++ b/stratosphere/ams_mitm/source/amsmitm_prodinfo_utils.cpp @@ -404,7 +404,7 @@ namespace ams::mitm { if (IsValidForSecureBackup(info)) { GetSerialNumber(sn, info); - std::snprintf(dst, dst_size, "automatic_backups/%s_PRODINFO.bin", sn); + util::SNPrintf(dst, dst_size, "automatic_backups/%s_PRODINFO.bin", sn); } else { Sha256Hash hash; crypto::GenerateSha256Hash(std::addressof(hash), sizeof(hash), std::addressof(info), sizeof(info)); @@ -412,13 +412,13 @@ namespace ams::mitm { if (IsValid(info)) { if (IsBlank(info)) { - std::snprintf(dst, dst_size, "automatic_backups/BLANK_PRODINFO_%02X%02X%02X%02X.bin", hash.data[0], hash.data[1], hash.data[2], hash.data[3]); + util::SNPrintf(dst, dst_size, "automatic_backups/BLANK_PRODINFO_%02X%02X%02X%02X.bin", hash.data[0], hash.data[1], hash.data[2], hash.data[3]); } else { GetSerialNumber(sn, info); - std::snprintf(dst, dst_size, "automatic_backups/%s_PRODINFO_%02X%02X%02X%02X.bin", sn, hash.data[0], hash.data[1], hash.data[2], hash.data[3]); + util::SNPrintf(dst, dst_size, "automatic_backups/%s_PRODINFO_%02X%02X%02X%02X.bin", sn, hash.data[0], hash.data[1], hash.data[2], hash.data[3]); } } else { - std::snprintf(dst, dst_size, "automatic_backups/INVALID_PRODINFO_%02X%02X%02X%02X.bin", hash.data[0], hash.data[1], hash.data[2], hash.data[3]); + util::SNPrintf(dst, dst_size, "automatic_backups/INVALID_PRODINFO_%02X%02X%02X%02X.bin", hash.data[0], hash.data[1], hash.data[2], hash.data[3]); } } } @@ -581,7 +581,7 @@ namespace ams::mitm { ON_SCOPE_EXIT { crypto::ClearMemory(std::addressof(hash), sizeof(hash)); }; crypto::GenerateSha256Hash(std::addressof(hash), sizeof(hash), std::addressof(g_calibration_info), sizeof(g_calibration_info)); - std::snprintf(out_name, out_name_size, "%02X%02X%02X%02X", hash.data[0], hash.data[1], hash.data[2], hash.data[3]); + util::SNPrintf(out_name, out_name_size, "%02X%02X%02X%02X", hash.data[0], hash.data[1], hash.data[2], hash.data[3]); } SaveProdInfoBackup(std::addressof(g_prodinfo_backup_file), g_calibration_info); } diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp index 589fca44a..b64085fff 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp @@ -101,9 +101,9 @@ namespace ams::mitm::fs { const bool is_system = attribute.system_save_data_id != InvalidSystemSaveDataId && IsEmptyAccountId(attribute.user_id); size_t out_path_len; if (is_system) { - out_path_len = static_cast(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx", emummc_str, space_id_str, save_type_str, attribute.system_save_data_id)); + out_path_len = static_cast(util::SNPrintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx", emummc_str, space_id_str, save_type_str, attribute.system_save_data_id)); } else { - out_path_len = static_cast(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast(program_id), attribute.user_id.data[1], attribute.user_id.data[0])); + out_path_len = static_cast(util::SNPrintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast(program_id), attribute.user_id.data[1], attribute.user_id.data[0])); } R_UNLESS(out_path_len < dst_size, fs::ResultTooLongPath()); diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index 769242f88..de241b2fd 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -66,7 +66,7 @@ namespace ams::mitm::settings { /* No truncation occurs assuming two-digits for all version number components. */ char display_version[sizeof(g_ams_firmware_version.display_version)]; - std::snprintf(display_version, sizeof(display_version), "%s|AMS %c.%u.%u|%c", g_ams_firmware_version.display_version, mesosphere_char, api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); + util::SNPrintf(display_version, sizeof(display_version), "%s|AMS %c.%u.%u|%c", g_ams_firmware_version.display_version, mesosphere_char, api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char); std::memcpy(g_ams_firmware_version.display_version, display_version, sizeof(display_version)); } diff --git a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp index 713a208c2..f312bba6b 100644 --- a/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp +++ b/stratosphere/ams_mitm/source/sysupdater/sysupdater_service.cpp @@ -57,7 +57,7 @@ namespace ams::mitm::sysupdater { Result ConvertToFsCommonPath(char *dst, size_t dst_size, const char *package_root_path, const char *entry_path) { char package_path[ams::fs::EntryNameLengthMax]; - const size_t path_len = std::snprintf(package_path, sizeof(package_path), "%s%s", package_root_path, entry_path); + const size_t path_len = util::SNPrintf(package_path, sizeof(package_path), "%s%s", package_root_path, entry_path); AMS_ABORT_UNLESS(path_len < ams::fs::EntryNameLengthMax); return ams::fs::ConvertToFsCommonPath(dst, dst_size, package_path); @@ -209,7 +209,7 @@ namespace ams::mitm::sysupdater { fs::FileHandle file; { char path[fs::EntryNameLengthMax]; - std::snprintf(path, sizeof(path), "%s%s%s", package_root, content_id_str.data, content_info->GetType() == ncm::ContentType::Meta ? ".cnmt.nca" : ".nca"); + util::SNPrintf(path, sizeof(path), "%s%s%s", package_root, content_id_str.data, content_info->GetType() == ncm::ContentType::Meta ? ".cnmt.nca" : ".nca"); if (R_FAILED(ValidateResult(fs::OpenFile(std::addressof(file), path, ams::fs::OpenMode_Read)))) { *done = true; return ResultSuccess(); @@ -292,7 +292,7 @@ namespace ams::mitm::sysupdater { R_UNLESS(user_path.str[0] == '/', fs::ResultInvalidPath()); /* Print as @Sdcard:/ */ - std::snprintf(out->str, sizeof(out->str), "%s:%s/", ams::fs::impl::SdCardFileSystemMountName, user_path.str); + util::SNPrintf(out->str, sizeof(out->str), "%s:%s/", ams::fs::impl::SdCardFileSystemMountName, user_path.str); /* Normalize, if the user provided an ending / */ const size_t len = std::strlen(out->str); diff --git a/stratosphere/creport/source/creport_crash_report.cpp b/stratosphere/creport/source/creport_crash_report.cpp index ef23aeca5..f2df1c30c 100644 --- a/stratosphere/creport/source/creport_crash_report.cpp +++ b/stratosphere/creport/source/creport_crash_report.cpp @@ -303,7 +303,7 @@ namespace ams::creport { char file_path[fs::EntryNameLengthMax + 1]; /* Save crash report. */ - std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, this->process_info.program_id); + util::SNPrintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.log", timestamp, this->process_info.program_id); { ScopedFile file(file_path); if (file.IsOpen()) { @@ -312,7 +312,7 @@ namespace ams::creport { } /* Dump threads. */ - std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/dumps/%011lu_%016lx_thread_info.bin", timestamp, this->process_info.program_id); + util::SNPrintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/dumps/%011lu_%016lx_thread_info.bin", timestamp, this->process_info.program_id); { ScopedFile file(file_path); if (file.IsOpen()) { @@ -341,7 +341,7 @@ namespace ams::creport { if (capssc_holder) { u64 jpeg_size; if (R_SUCCEEDED(capsrv::CaptureJpegScreenshot(std::addressof(jpeg_size), this->heap_storage, sizeof(this->heap_storage), vi::LayerStack_ApplicationForDebug, TimeSpan::FromSeconds(10)))) { - std::snprintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.jpg", timestamp, this->process_info.program_id); + util::SNPrintf(file_path, sizeof(file_path), "sdmc:/atmosphere/crash_reports/%011lu_%016lx.jpg", timestamp, this->process_info.program_id); ScopedFile file(file_path); if (file.IsOpen()) { file.Write(this->heap_storage, jpeg_size); diff --git a/stratosphere/creport/source/creport_modules.cpp b/stratosphere/creport/source/creport_modules.cpp index 49694ee9a..a58528cff 100644 --- a/stratosphere/creport/source/creport_modules.cpp +++ b/stratosphere/creport/source/creport_modules.cpp @@ -107,7 +107,7 @@ namespace ams::creport { GetModuleBuildId(module.build_id, module.end_address); /* Some homebrew won't have a name. Add a fake one for readability. */ if (std::strcmp(module.name, "") == 0) { - std::snprintf(module.name, sizeof(module.name), "[%02x%02x%02x%02x]", module.build_id[0], module.build_id[1], module.build_id[2], module.build_id[3]); + util::SNPrintf(module.name, sizeof(module.name), "[%02x%02x%02x%02x]", module.build_id[0], module.build_id[1], module.build_id[2], module.build_id[3]); } } @@ -249,13 +249,13 @@ namespace ams::creport { const char *ModuleList::GetFormattedAddressString(uintptr_t address) { /* Print default formatted string. */ - std::snprintf(this->address_str_buf, sizeof(this->address_str_buf), "%016lx", address); + util::SNPrintf(this->address_str_buf, sizeof(this->address_str_buf), "%016lx", address); /* See if the address is inside a module, for pretty-printing. */ for (size_t i = 0; i < this->num_modules; i++) { const auto& module = this->modules[i]; if (module.start_address <= address && address < module.end_address) { - std::snprintf(this->address_str_buf, sizeof(this->address_str_buf), "%016lx (%s + 0x%lx)", address, module.name, address - module.start_address); + util::SNPrintf(this->address_str_buf, sizeof(this->address_str_buf), "%016lx (%s + 0x%lx)", address, module.name, address - module.start_address); break; } } diff --git a/stratosphere/creport/source/creport_scoped_file.cpp b/stratosphere/creport/source/creport_scoped_file.cpp index 916d7be56..1ab3fb26a 100644 --- a/stratosphere/creport/source/creport_scoped_file.cpp +++ b/stratosphere/creport/source/creport_scoped_file.cpp @@ -40,7 +40,7 @@ namespace ams::creport { { std::va_list vl; va_start(vl, fmt); - std::vsnprintf(g_format_buffer, sizeof(g_format_buffer), fmt, vl); + util::VSNPrintf(g_format_buffer, sizeof(g_format_buffer), fmt, vl); va_end(vl); } @@ -70,7 +70,7 @@ namespace ams::creport { { char hex[MaximumLineLength * 2 + 2] = {}; for (size_t i = 0; i < cur_size; i++) { - std::snprintf(hex + i * 2, 3, "%02X", data_u8[data_ofs++]); + util::SNPrintf(hex + i * 2, 3, "%02X", data_u8[data_ofs++]); } hex[cur_size * 2 + 0] = '\n'; hex[cur_size * 2 + 1] = '\x00'; diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp index ee88402c4..52678d88b 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_api.cpp @@ -970,7 +970,7 @@ namespace ams::dmnt::cheat::impl { fs::FileHandle file; { char path[fs::EntryNameLengthMax + 1]; - std::snprintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/cheats/%02x%02x%02x%02x%02x%02x%02x%02x.txt", program_id.value, + util::SNPrintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/cheats/%02x%02x%02x%02x%02x%02x%02x%02x.txt", program_id.value, build_id[0], build_id[1], build_id[2], build_id[3], build_id[4], build_id[5], build_id[6], build_id[7]); if (R_FAILED(fs::OpenFile(std::addressof(file), path, fs::OpenMode_Read))) { return false; @@ -1009,7 +1009,7 @@ namespace ams::dmnt::cheat::impl { fs::FileHandle file; { char path[fs::EntryNameLengthMax + 1]; - std::snprintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/cheats/toggles.txt", program_id.value); + util::SNPrintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/cheats/toggles.txt", program_id.value); if (R_FAILED(fs::OpenFile(std::addressof(file), path, fs::OpenMode_Read))) { /* No file presence is allowed. */ return true; @@ -1046,7 +1046,7 @@ namespace ams::dmnt::cheat::impl { fs::FileHandle file; { char path[fs::EntryNameLengthMax + 1]; - std::snprintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/cheats/toggles.txt", program_id.value); + util::SNPrintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/cheats/toggles.txt", program_id.value); fs::DeleteFile(path); fs::CreateFile(path, 0); if (R_FAILED(fs::OpenFile(std::addressof(file), path, fs::OpenMode_Write | fs::OpenMode_AllowAppend))) { @@ -1061,7 +1061,7 @@ namespace ams::dmnt::cheat::impl { /* Save all non-master cheats. */ for (size_t i = 1; i < MaxCheatCount; i++) { if (this->cheat_entries[i].definition.num_opcodes != 0) { - std::snprintf(buf, sizeof(buf), "[%s]\n", this->cheat_entries[i].definition.readable_name); + util::SNPrintf(buf, sizeof(buf), "[%s]\n", this->cheat_entries[i].definition.readable_name); const size_t name_len = std::strlen(buf); if (R_SUCCEEDED(fs::WriteFile(file, offset, buf, name_len, fs::WriteOption::Flush))) { offset += name_len; diff --git a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp index f3bb39036..1e670cae7 100644 --- a/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp +++ b/stratosphere/dmnt/source/cheat/impl/dmnt_cheat_vm.cpp @@ -26,7 +26,7 @@ namespace ams::dmnt::cheat::impl { fs::FileHandle log_file; { char log_path[fs::EntryNameLengthMax + 1]; - std::snprintf(log_path, sizeof(log_path), "sdmc:/atmosphere/cheat_vm_logs/%08x.log", log_id); + util::SNPrintf(log_path, sizeof(log_path), "sdmc:/atmosphere/cheat_vm_logs/%08x.log", log_id); if (R_FAILED(fs::OpenFile(std::addressof(log_file), log_path, fs::OpenMode_Write | fs::OpenMode_AllowAppend))) { return; } @@ -39,7 +39,7 @@ namespace ams::dmnt::cheat::impl { } char log_value[18]; - std::snprintf(log_value, sizeof(log_value), "%016lx\n", value); + util::SNPrintf(log_value, sizeof(log_value), "%016lx\n", value); fs::WriteFile(log_file, log_offset, log_value, std::strlen(log_value), fs::WriteOption::Flush); } @@ -69,7 +69,7 @@ namespace ams::dmnt::cheat::impl { { std::va_list vl; va_start(vl, format); - std::vsnprintf(this->debug_log_format_buf, sizeof(this->debug_log_format_buf) - 1, format, vl); + util::VSNPrintf(this->debug_log_format_buf, sizeof(this->debug_log_format_buf) - 1, format, vl); va_end(vl); } diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 1e7193ebc..b2b67f7bc 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -103,7 +103,7 @@ namespace ams::erpt { switch (model) { case settings::system::ProductModel_Invalid: return util::Strlcpy(dst, "Invalid", static_cast(dst_size)); case settings::system::ProductModel_Nx: return util::Strlcpy(dst, "NX", static_cast(dst_size)); - default: return std::snprintf(dst, dst_size, "%d", static_cast(model)); + default: return util::SNPrintf(dst, dst_size, "%d", static_cast(model)); } } @@ -141,7 +141,7 @@ int main(int argc, char **argv) settings::system::GetSerialNumber(std::addressof(serial_number)); char os_private[0x60]; - const auto os_priv_len = std::snprintf(os_private, sizeof(os_private), "%s (%.8s)", firmware_version.display_name, firmware_version.revision); + const auto os_priv_len = util::SNPrintf(os_private, sizeof(os_private), "%s (%.8s)", firmware_version.display_name, firmware_version.revision); AMS_ASSERT(static_cast(os_priv_len) < sizeof(os_private)); R_ABORT_UNLESS(erpt::srv::SetSerialNumberAndOsVersion(serial_number.str, diff --git a/stratosphere/fatal/source/fatal_font.cpp b/stratosphere/fatal/source/fatal_font.cpp index 67752e9d4..af967bdc8 100644 --- a/stratosphere/fatal/source/fatal_font.cpp +++ b/stratosphere/fatal/source/fatal_font.cpp @@ -135,7 +135,7 @@ namespace ams::fatal::srv::font { std::va_list va_arg; va_start(va_arg, format); - std::vsnprintf(char_buf, sizeof(char_buf), format, va_arg); + util::VSNPrintf(char_buf, sizeof(char_buf), format, va_arg); va_end(va_arg); PrintLine(char_buf); @@ -150,7 +150,7 @@ namespace ams::fatal::srv::font { std::va_list va_arg; va_start(va_arg, format); - std::vsnprintf(char_buf, sizeof(char_buf), format, va_arg); + util::VSNPrintf(char_buf, sizeof(char_buf), format, va_arg); va_end(va_arg); Print(char_buf); @@ -158,14 +158,14 @@ namespace ams::fatal::srv::font { void PrintMonospaceU64(u64 x) { char char_buf[0x400]; - std::snprintf(char_buf, sizeof(char_buf), "%016lX", x); + util::SNPrintf(char_buf, sizeof(char_buf), "%016lX", x); DrawString(char_buf, false, true); } void PrintMonospaceU32(u32 x) { char char_buf[0x400]; - std::snprintf(char_buf, sizeof(char_buf), "%08X", x); + util::SNPrintf(char_buf, sizeof(char_buf), "%08X", x); DrawString(char_buf, false, true); } diff --git a/stratosphere/fatal/source/fatal_scoped_file.cpp b/stratosphere/fatal/source/fatal_scoped_file.cpp index 4f3359255..50b82e263 100644 --- a/stratosphere/fatal/source/fatal_scoped_file.cpp +++ b/stratosphere/fatal/source/fatal_scoped_file.cpp @@ -40,7 +40,7 @@ namespace ams::fatal::srv { { std::va_list vl; va_start(vl, fmt); - std::vsnprintf(g_format_buffer, sizeof(g_format_buffer), fmt, vl); + util::VSNPrintf(g_format_buffer, sizeof(g_format_buffer), fmt, vl); va_end(vl); } @@ -70,7 +70,7 @@ namespace ams::fatal::srv { { char hex[MaximumLineLength * 2 + 2] = {}; for (size_t i = 0; i < cur_size; i++) { - std::snprintf(hex + i * 2, 3, "%02X", data_u8[data_ofs++]); + util::SNPrintf(hex + i * 2, 3, "%02X", data_u8[data_ofs++]); } hex[cur_size * 2 + 0] = '\n'; hex[cur_size * 2 + 1] = '\x00'; diff --git a/stratosphere/fatal/source/fatal_task_error_report.cpp b/stratosphere/fatal/source/fatal_task_error_report.cpp index 8247ac02d..85dc92d54 100644 --- a/stratosphere/fatal/source/fatal_task_error_report.cpp +++ b/stratosphere/fatal/source/fatal_task_error_report.cpp @@ -75,7 +75,7 @@ namespace ams::fatal::srv { /* Open report file. */ { - std::snprintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/%011lu_%016lx.log", timestamp, static_cast(this->context->program_id)); + util::SNPrintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/%011lu_%016lx.log", timestamp, static_cast(this->context->program_id)); ScopedFile file(file_path); if (file.IsOpen()) { file.WriteFormat("Atmosphère Fatal Report (v1.1):\n"); @@ -137,7 +137,7 @@ namespace ams::fatal::srv { /* Dump data to file. */ { - std::snprintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/dumps/%011lu_%016lx.bin", timestamp, static_cast(this->context->program_id)); + util::SNPrintf(file_path, sizeof(file_path) - 1, "sdmc:/atmosphere/fatal_reports/dumps/%011lu_%016lx.bin", timestamp, static_cast(this->context->program_id)); ScopedFile file(file_path); if (file.IsOpen()) { file.Write(this->context->tls_dump, sizeof(this->context->tls_dump));