From 84f6686e39264cd4f5afb079ac13e9cc6d97b719 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 12 Feb 2015 21:56:32 +0000 Subject: [PATCH] Avoid warnings about not checking chdir() result in wxGTK. Give error if changing directory when wxFD_CHANGE_DIR or wxDIRP_CHANGE_DIR flags are used, this is a good idea generally speaking and it also avoids warnings about not checking chdir() return value that we got under Ubuntu. This is the backport of 3f6741a770be745537affdae2a063e801f22ad8b from master with the changes of cb06ecb9eb641fe07d1ed65e249db33a02d16c81 and de27f4b08fb437314496225632096d5308365a9d too. --- src/gtk/filedlg.cpp | 7 ++++++- src/gtk/filepicker.cpp | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index e6f6320b86..44087dd65e 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -15,6 +15,7 @@ #ifndef WX_PRECOMP #include "wx/intl.h" + #include "wx/log.h" #include "wx/msgdlg.h" #endif @@ -81,7 +82,11 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) { // Use chdir to not care about filename encodings wxGtkString folder(g_path_get_dirname(filename)); - chdir(folder); + if ( chdir(folder) != 0 ) + { + wxLogSysError(_("Changing current directory to \"%s\" failed"), + wxString::FromUTF8(folder)); + } } wxCommandEvent event(wxEVT_BUTTON, wxID_OK); diff --git a/src/gtk/filepicker.cpp b/src/gtk/filepicker.cpp index 3abea8d7cf..d8d0c6b01d 100644 --- a/src/gtk/filepicker.cpp +++ b/src/gtk/filepicker.cpp @@ -18,6 +18,10 @@ #if wxUSE_FILEPICKERCTRL +#ifndef WX_PRECOMP + #include "wx/log.h" +#endif + #include "wx/filepicker.h" #include "wx/tooltip.h" @@ -180,7 +184,13 @@ static void file_set(GtkFileChooser* widget, wxDirButton* p) // thus we need to make sure the current working directory is updated if wxDIRP_CHANGE_DIR // style was given. if (p->HasFlag(wxDIRP_CHANGE_DIR)) - chdir(filename); + { + if ( chdir(filename) != 0 ) + { + wxLogSysError(_("Changing current directory to \"%s\" failed"), + wxString::FromUTF8(filename)); + } + } // ...and fire an event wxFileDirPickerEvent event(wxEVT_DIRPICKER_CHANGED, p, p->GetId(), p->GetPath());