Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1596)

Unified Diff: runtime/bin/platform_macos.cc

Issue 1145053002: Make Platform.executable return a fully qualified path the the executable (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix comment Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/platform_macos.cc
diff --git a/runtime/bin/platform_macos.cc b/runtime/bin/platform_macos.cc
index 55ccd213f87b3e7ec1ea6b3192112cbea22c803c..3699a33ff736fb3208d359dd8b5dd8432f1e1a80 100644
--- a/runtime/bin/platform_macos.cc
+++ b/runtime/bin/platform_macos.cc
@@ -5,6 +5,8 @@
#include "platform/globals.h"
#if defined(TARGET_OS_MACOS)
+#include <mach-o/dyld.h>
+
#include "bin/platform.h"
#include <crt_externs.h> // NOLINT
@@ -75,6 +77,23 @@ void Platform::FreeEnvironment(char** env, intptr_t count) {
delete[] env;
}
+
+char* Platform::ResolveExecutablePath() {
+ // Get the required length of the buffer.
+ uint32_t path_size = 0;
+ char* path = NULL;
+ if (_NSGetExecutablePath(path, &path_size) != -1) {
Lasse Reichstein Nielsen 2015/05/20 10:48:43 Could "!= -1" be ">= 0". (I just don't like unname
Søren Gjesse 2015/05/20 11:14:24 Changed to "== 0" then. The documentation explicit
+ return NULL;
+ }
+ // Allocate buffer and get executable path.
+ path = reinterpret_cast<char*>(malloc(path_size));
+ if (_NSGetExecutablePath(path, &path_size) != 0) {
+ free(path);
+ return NULL;
+ }
+ return path;
+}
+
} // namespace bin
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698