From 7c2e9a6596c8b6c5d366c3eaaf926ad7db406486 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Thu, 8 Feb 2024 16:58:44 -0600 Subject: service: bcat: Migrate and refractor service to new IPC --- src/core/hle/service/bcat/bcat_util.h | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/core/hle/service/bcat/bcat_util.h (limited to 'src/core/hle/service/bcat/bcat_util.h') diff --git a/src/core/hle/service/bcat/bcat_util.h b/src/core/hle/service/bcat/bcat_util.h new file mode 100644 index 000000000..6bf2657ee --- /dev/null +++ b/src/core/hle/service/bcat/bcat_util.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include +#include +#include + +#include "core/hle/service/bcat/bcat_result.h" +#include "core/hle/service/bcat/bcat_types.h" + +namespace Service::BCAT { + +// For a name to be valid it must be non-empty, must have a null terminating character as the final +// char, can only contain numbers, letters, underscores and a hyphen if directory and a period if +// file. +constexpr Result VerifyNameValidInternal(std::array name, char match_char) { + const auto null_chars = std::count(name.begin(), name.end(), 0); + const auto bad_chars = std::count_if(name.begin(), name.end(), [match_char](char c) { + return !std::isalnum(static_cast(c)) && c != '_' && c != match_char && c != '\0'; + }); + if (null_chars == 0x20 || null_chars == 0 || bad_chars != 0 || name[0x1F] != '\0') { + LOG_ERROR(Service_BCAT, "Name passed was invalid!"); + return ResultInvalidArgument; + } + + return ResultSuccess; +} + +constexpr Result VerifyNameValidDir(DirectoryName name) { + return VerifyNameValidInternal(name, '-'); +} + +constexpr Result VerifyNameValidFile(FileName name) { + return VerifyNameValidInternal(name, '.'); +} + +} // namespace Service::BCAT -- cgit v1.2.3