nanoMMO
0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
settings.cc
Go to the documentation of this file.
1
#include "
protocol/settings.h
"
2
3
#include <sys/stat.h>
4
5
#include <cstdlib>
6
#include <string>
7
8
#include "absl/strings/str_cat.h"
9
10
namespace
nanommo
{
11
12
namespace
{
13
14
// stat, which Windows has too, where it hasn't POSIX's access.
15
bool
Exists(
const
std::string& path) {
16
struct
stat status;
17
return
stat(path.c_str(), &status) == 0;
18
}
19
20
}
// namespace
21
22
std::string
FileSetting
(
const
char
* name,
const
std::string& path) {
23
if
(
const
char
* value = std::getenv(name)) {
24
return
value;
25
}
26
// The build puts the repository's folder in NANOMMO_SOURCE_DIR.
27
// Not const, so that returning it moves it.
28
std::string repository = absl::StrCat(NANOMMO_SOURCE_DIR,
"/"
, path);
29
if
(Exists(repository) || !Exists(path)) {
30
return
repository;
31
}
32
return
path;
33
}
34
35
}
// namespace nanommo
nanommo
Definition
chat.cc:9
nanommo::FileSetting
std::string FileSetting(const char *name, const std::string &path)
Definition
settings.cc:22
settings.h
protocol
settings.cc
Generated by
1.15.0