John Stiles | 964d8f1 | 2022-10-26 13:52:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "tools/SkGetExecutablePath.h" |
| 9 | #include <mach-o/dyld.h> |
| 10 | |
John Stiles | f04b827 | 2022-11-04 13:58:26 -0400 | [diff] [blame] | 11 | std::string SkGetExecutablePath() { |
John Stiles | 964d8f1 | 2022-10-26 13:52:03 -0400 | [diff] [blame] | 12 | uint32_t size = 0; |
| 13 | _NSGetExecutablePath(nullptr, &size); |
| 14 | |
John Stiles | f04b827 | 2022-11-04 13:58:26 -0400 | [diff] [blame] | 15 | std::string result(size, '\0'); |
John Stiles | 1e64fb9 | 2022-10-27 14:02:39 -0400 | [diff] [blame] | 16 | if (_NSGetExecutablePath(result.data(), &size) != 0) { |
John Stiles | f04b827 | 2022-11-04 13:58:26 -0400 | [diff] [blame] | 17 | result.clear(); |
John Stiles | 964d8f1 | 2022-10-26 13:52:03 -0400 | [diff] [blame] | 18 | } |
| 19 | return result; |
| 20 | } |