mirror of
https://github.com/luanti-org/minetestmapper.git
synced 2025-10-06 22:05:22 +02:00
Improve handling of input path and map backend
This commit is contained in:
20
src/util.cpp
20
src/util.cpp
@@ -1,11 +1,15 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
static std::string trim(const std::string &s)
|
||||
{
|
||||
auto isspace = [] (char c) -> bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n'; };
|
||||
auto isspace = [] (char c) {
|
||||
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
||||
};
|
||||
|
||||
size_t front = 0;
|
||||
while (isspace(s[front]))
|
||||
@@ -20,6 +24,7 @@ static std::string trim(const std::string &s)
|
||||
std::string read_setting(const std::string &name, std::istream &is)
|
||||
{
|
||||
char linebuf[512];
|
||||
is.seekg(0);
|
||||
while (is.good()) {
|
||||
is.getline(linebuf, sizeof(linebuf));
|
||||
|
||||
@@ -53,3 +58,16 @@ std::string read_setting_default(const std::string &name, std::istream &is,
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
bool file_exists(const char *path)
|
||||
{
|
||||
struct stat s{};
|
||||
// check for !dir to allow symlinks or such
|
||||
return stat(path, &s) == 0 && (s.st_mode & S_IFDIR) != S_IFDIR;
|
||||
}
|
||||
|
||||
bool dir_exists(const char *path)
|
||||
{
|
||||
struct stat s{};
|
||||
return stat(path, &s) == 0 && (s.st_mode & S_IFDIR) == S_IFDIR;
|
||||
}
|
||||
|
Reference in New Issue
Block a user