1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-11 08:30:55 +00:00

Ensure that the output of xdg-user-dir is properly filtered.

This commit is contained in:
Thomas Harte 2018-07-28 10:45:50 -04:00
parent 34aa78b7ce
commit 99c770eab4

View File

@ -635,9 +635,14 @@ int main(int argc, char *argv[]) {
memcpy(&pixels[(window_height - 1 - y)*proportional_width*4], swap_buffer.data(), swap_buffer.size());
}
// Pick the directory for images. Try `xdg-user-dir PICTURES` first; failing that
// fall back on the HOME directory.
// Pick the directory for images. Try `xdg-user-dir PICTURES` first.
std::string target_directory = system_get("xdg-user-dir PICTURES");
// Make sure there are no newlines.
target_directory.erase(std::remove(target_directory.begin(), target_directory.end(), '\n'), target_directory.end());
target_directory.erase(std::remove(target_directory.begin(), target_directory.end(), '\r'), target_directory.end());
// Fall back on the HOME directory if necessary.
if(target_directory.empty()) target_directory = getenv("HOME");
// Find the first available name of the form ~/clk-screenshot-<number>.bmp.