ams: use util::SNPrintf over std:: (size/linker improvements)

This commit is contained in:
Michael Scire 2021-01-12 02:59:41 -08:00
parent 9cfd259c5c
commit 094cede39e
41 changed files with 103 additions and 103 deletions

View file

@ -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);
}
}

View file

@ -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<u64>(program_id));
util::SNPrintf(path, sizeof(path), "sdmc:/atmosphere/contents/%016lx/mitm.lst", static_cast<u64>(program_id));
fs::FileHandle f;
if (R_FAILED(fs::OpenFile(&f, path, fs::OpenMode_Read))) {

View file

@ -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<u64>(program_id), flag);
util::SNPrintf(content_flag, sizeof(content_flag) - 1, "/atmosphere/contents/%016lx/flags/%s.flag", static_cast<u64>(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);
}

View file

@ -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<u32> 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<u64>(program_id));
util::SNPrintf(path, sizeof(path), "/atmosphere/contents/%016lx/config.ini", static_cast<u64>(program_id));
ContentSpecificOverrideConfig config = {
.override_key = g_default_override_key,

View file

@ -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));
}

View file

@ -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;
}

View file

@ -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,

View file

@ -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<size_t>(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<int>(program_index));
const int len = 1 + util::SNPrintf(log_buffer, sizeof(log_buffer), StartLog, static_cast<int>(program_index));
if (static_cast<size_t>(len) <= sizeof(log_buffer)) {
OutputAccessLogImpl(log_buffer, len);
}

View file

@ -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_t>(size) == needed_size - 1);
return ResultSuccess();

View file

@ -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<fssystem::SubDirectoryFileSystem>(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;

View file

@ -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_t>(size) == needed_size - 1);
return ResultSuccess();

View file

@ -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_t>(size) == needed_size - 1);
return ResultSuccess();

View file

@ -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_t>(size) == needed_size - 1);
return ResultSuccess();

View file

@ -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<size_t>(common_path_len) < dst_size - mount_name_len, fs::ResultTooLongPath());
return ResultSuccess();

View file

@ -78,7 +78,7 @@ namespace ams::fssystem {
std::unique_ptr<fs::fsa::IFile> dst_file;
{
char dst_path[fs::EntryNameLengthMax + 1];
const size_t original_size = static_cast<size_t>(std::snprintf(dst_path, sizeof(dst_path), "%s%s", dst_parent_path, entry->name));
const size_t original_size = static_cast<size_t>(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<size_t>(std::snprintf(dst_path_buf, sizeof(dst_path_buf), "%s", dst_path));
const size_t original_size = static_cast<size_t>(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,

View file

@ -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<const u8 *>(src)[i]);
util::SNPrintf(dst + 2 * i, 3, "%02x", static_cast<const u8 *>(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<ContentId> GetContentIdFromString(const char *str, size_t len) {

View file

@ -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);

View file

@ -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();
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -217,7 +217,7 @@ namespace ams::patcher {
/* Inspect all patches from /atmosphere/<patch_dir>/<*>/<*>.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;

View file

@ -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<unsigned long long>(static_cast<u64>(process_id)), str_arg, log_arg, dump_arg);
return util::SNPrintf(dst, dst_size, "D %010llu \"%s\" -log %d -dump %d", static_cast<unsigned long long>(static_cast<u64>(process_id)), str_arg, log_arg, dump_arg);
} else {
return std::snprintf(dst, dst_size, "D %010llu -log %d -dump %d", static_cast<unsigned long long>(static_cast<u64>(process_id)), log_arg, dump_arg);
return util::SNPrintf(dst, dst_size, "D %010llu -log %d -dump %d", static_cast<unsigned long long>(static_cast<u64>(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<s64>(static_cast<u64>(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<s64>(static_cast<u64>(process_id)), GetCrashReportDetailedArgument(data_flags), GetCrashReportScreenShotArgument(data_flags), g_enable_jit_debug);
if (R_FAILED(ldr::SetProgramArgument(ncm::SystemProgramId::Creport, arguments, len + 1))) {
return;
}

View file

@ -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] = '/';