• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <limits.h>
6 #include <mach-o/dyld.h>
7 #include <stdlib.h>
8 
9 #include "platform/test/paths_internal.h"
10 #include "util/osp_logging.h"
11 #include "util/std_util.h"
12 
13 namespace openscreen {
14 
GetExePath()15 std::string GetExePath() {
16   uint32_t path_size = 0;
17   _NSGetExecutablePath(nullptr, &path_size);
18   OSP_DCHECK(path_size > 0u);
19   std::string exe_path(path_size, 0);
20   int ret = _NSGetExecutablePath(data(exe_path), &path_size);
21   OSP_DCHECK_EQ(ret, 0);
22   char* resolved = realpath(exe_path.c_str(), nullptr);
23   std::string final_path(resolved);
24   free(resolved);
25   return final_path;
26 }
27 
28 }  // namespace openscreen
29