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

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