blob: ddf7cdac16041c17ee3a1904eeb82d654e1a8cfa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "path.h"
#include <stdexcept>
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h> // Para PATH_MAX
bool path_exists(const std::string &path)
{
struct stat buffer;
return (stat(path.c_str(), &buffer) == 0);
}
std::string path_canonicalize(const std::string &path)
{
char resolved_path[PATH_MAX];
if (realpath(path.c_str(), resolved_path) == nullptr) {
throw std::runtime_error("Error canonicalizing path");
}
return std::string(resolved_path);
}
|