ams: use util::SNPrintf over std:: (size/linker improvements)
This commit is contained in:
@@ -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<u64>(program_id), src_path);
|
||||
util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx%s", static_cast<u64>(program_id), src_path);
|
||||
} else {
|
||||
std::snprintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s", static_cast<u64>(program_id), src_path);
|
||||
util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s", static_cast<u64>(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<u64>(program_id), subdir, src_path);
|
||||
util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s%s", static_cast<u64>(program_id), subdir, src_path);
|
||||
} else {
|
||||
std::snprintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s/%s", static_cast<u64>(program_id), subdir, src_path);
|
||||
util::SNPrintf(dst_path, dst_path_size, "/atmosphere/contents/%016lx/%s/%s", static_cast<u64>(program_id), subdir, src_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<size_t>(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<size_t>(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<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast<u64>(program_id), attribute.user_id.data[1], attribute.user_id.data[0]));
|
||||
out_path_len = static_cast<size_t>(util::SNPrintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast<u64>(program_id), attribute.user_id.data[1], attribute.user_id.data[0]));
|
||||
}
|
||||
|
||||
R_UNLESS(out_path_len < dst_size, fs::ResultTooLongPath());
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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:<user_path>/ */
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user