summaryrefslogtreecommitdiff
path: root/platform/default/application_root.cpp
blob: 6669a049a498cd58d49880c3a34c467e638ec389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <mbgl/platform/platform.hpp>

#include <uv.h>
#include <libgen.h>

namespace mbgl {
namespace platform {

// Returns the path to the root folder of the application.
const std::string &applicationRoot() {
    static const std::string root = []() -> std::string {
        size_t max = 0;
        std::string dir;
        do {
            // Gradually increase the length of the string in case the path was truncated.
            max += 256;
            dir.resize(max);
            uv_exepath(const_cast<char *>(dir.data()), &max);
        } while (max == dir.size());
        dir.resize(max - 1);
        dir = dirname(const_cast<char *>(dir.c_str()));
        return dir;
    }();
    return root;
}

}
}