/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#include "ExeAppendedZipResourceLoaderLinux.hpp"
#include <unistd.h>
#include <climits>

namespace OpenVulkano
{
	namespace
	{
		void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique<ExeAppendedZipResourceLoaderLinux>());
	}

	std::string OpenVulkano::ExeAppendedZipResourceLoaderLinux::GetCurrentExecutablePath() const
	{
		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;
	}

}
