/* # _____ ____ ___ # | \/ ____| |___| # | | | \ | | #----------------------------------------------------------------------- # Copyright 2022, tyra - https://github.com/h4570/tyra # Licensed under Apache License 2.0 # Wellington Carvalho */ #include "debug/debug.hpp" #include #include #include #include #include #include #include #include "file/file_utils.hpp" namespace Tyra { FileUtils::FileUtils() { getcwd(cwd, sizeof(cwd)); setPathInfo(cwd); } FileUtils::~FileUtils() {} void FileUtils::setPathInfo(const char* path) { char* ptr; strcpy(this->elfName, path); strcpy(this->elfPath, path); ptr = strrchr(this->elfPath, '/'); if (ptr == nullptr) { ptr = strrchr(this->elfPath, '\\'); if (ptr == nullptr) { ptr = strrchr(this->elfPath, ':'); if (ptr == nullptr) { TYRA_TRAP("Did not find path! PATH: ", path); } } } ptr++; *ptr = '\0'; } std::string FileUtils::getCwd() { std::string result; char _cwd[NAME_MAX]; getcwd(_cwd, sizeof(_cwd)); result = _cwd; return result; } std::string FileUtils::fromCwd(const std::string& relativePath) { return fromCwd(relativePath.c_str()); } std::string FileUtils::fromCwd(const char* file) { auto cwd = getCwd(); return cwd + file; } } // namespace Tyra