Find the name of the current executable
| 118 | |
| 119 | // Find the name of the current executable |
| 120 | std::filesystem::path findExecutableName() |
| 121 | { |
| 122 | // We use /proc/self/cmdline to get the command line |
| 123 | // the user used to invoke this instance of the application |
| 124 | const int file = ::open("/proc/self/cmdline", O_RDONLY | O_NONBLOCK); |
| 125 | |
| 126 | if (file < 0) |
| 127 | return "sfml"; |
| 128 | |
| 129 | std::vector<char> buffer(256, 0); |
| 130 | std::size_t offset = 0; |
| 131 | ssize_t result = 0; |
| 132 | |
| 133 | while ((result = read(file, &buffer[offset], 256)) > 0) |
| 134 | { |
| 135 | buffer.resize(buffer.size() + static_cast<std::size_t>(result), 0); |
| 136 | offset += static_cast<std::size_t>(result); |
| 137 | } |
| 138 | |
| 139 | ::close(file); |
| 140 | |
| 141 | if (offset) |
| 142 | { |
| 143 | buffer[offset] = 0; |
| 144 | |
| 145 | // Remove the path to keep the executable name only |
| 146 | return basename(buffer.data()); |
| 147 | } |
| 148 | |
| 149 | // Default fallback name |
| 150 | return "sfml"; |
| 151 | } |
| 152 | |
| 153 | // Get features supported by the current window manager |
| 154 | const std::vector<std::string>& getSupportedFeatures() |
no test coverage detected