Removing trailing newline in zenity file dialogs.

PiperOrigin-RevId: 864842389
Change-Id: Ie4cc61a91732fcde0ef2c7eba927aede217b2e6d
This commit is contained in:
Haroon Qureshi
2026-02-03 06:14:07 -08:00
committed by Copybara-Service
parent e82253e86c
commit 34add7bb32
@@ -15,6 +15,7 @@
#include "experimental/platform/file_dialog.h" #include "experimental/platform/file_dialog.h"
#include <assert.h> #include <assert.h>
#include <cstring>
#include <fcntl.h> #include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
@@ -45,8 +46,10 @@ static DialogResult RunZenity(std::vector<std::string>& args) {
if (ret == nullptr || ferror(output)) { if (ret == nullptr || ferror(output)) {
return DialogResult{.status = DialogResult::kError}; return DialogResult{.status = DialogResult::kError};
} }
if (buffer[kBufferSize - 1] == '\0') { // Zenity outputs a newline at the end of the buffer which we need to remove.
buffer[0] = '\0'; const int len = std::strlen(buffer);
if (len > 0) {
buffer[len - 1] = '\0';
} }
return DialogResult{.status = DialogResult::kAccepted, return DialogResult{.status = DialogResult::kAccepted,
.path = std::string(buffer)}; .path = std::string(buffer)};