-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Expand file tree
/
Copy pathpath_utils.cc
More file actions
37 lines (32 loc) · 1019 Bytes
/
path_utils.cc
File metadata and controls
37 lines (32 loc) · 1019 Bytes
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
29
30
31
32
33
34
35
36
37
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/common/path_utils.h"
#if defined(_WIN32)
#include <windows.h>
#elif defined(__linux__)
#include <linux/limits.h>
#include <unistd.h>
#endif
namespace flutter {
std::filesystem::path GetExecutableDirectory() {
#if defined(_WIN32)
wchar_t buffer[MAX_PATH];
if (GetModuleFileName(nullptr, buffer, MAX_PATH) == 0) {
return std::filesystem::path();
}
std::filesystem::path executable_path(buffer);
return executable_path.remove_filename();
#elif defined(__linux__)
char buffer[PATH_MAX];
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
if (length < 0) {
return std::filesystem::path();
}
std::filesystem::path executable_path(std::string(buffer, length));
return executable_path.remove_filename();
#else
return std::filesystem::path();
#endif
}
} // namespace flutter