code review refactoring

This commit is contained in:
ohyzha
2024-12-21 17:11:29 +02:00
parent 9d6756bbad
commit d3750f2b8a
10 changed files with 88 additions and 117 deletions

View File

@@ -4,7 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "ExeAppendedZipLoaderLinux.hpp"
#include "ExeAppendedZipResourceLoaderLinux.hpp"
#include <unistd.h>
#include <climits>
@@ -12,19 +12,15 @@ namespace OpenVulkano
{
namespace
{
void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique<ExeAppendedZipLoaderLinux>());
void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique<ExeAppendedZipResourceLoaderLinux>());
}
std::string OpenVulkano::ExeAppendedZipLoaderLinux::GetCurrentExecutablePath() const
std::string OpenVulkano::ExeAppendedZipResourceLoaderLinux::GetCurrentExecutablePath() const
{
char dest[PATH_MAX];
memset(dest, 0, sizeof(dest)); // readlink does not null terminate!
size_t sz = 0;
if ((sz = readlink("/proc/self/exe", dest, PATH_MAX)) != -1)
{
return std::string(dest, sz);
}
return "";
std::string path(PATH_MAX, '\0');
ssize_t sz = readlink("/proc/self/exe", path.data(), path.capacity()));
path.resize(std::max<ssize_t>(0, sz));
return path;
}
}