From: Vadim Zeitlin Date: Sun, 4 Dec 2005 13:01:50 +0000 (+0000) Subject: fixed broken code using readlink(): please don't just cast wxChar * to char *, this... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d5437b854cece72d2ee069a7cd8b5776acc1b4ff fixed broken code using readlink(): please don't just cast wxChar * to char *, this doesn't risk to ever work git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36341 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/unix/stdpaths.cpp b/src/unix/stdpaths.cpp index f662d45cfc..fbecba3600 100644 --- a/src/unix/stdpaths.cpp +++ b/src/unix/stdpaths.cpp @@ -53,36 +53,35 @@ void wxStandardPaths::SetInstallPrefix(const wxString& prefix) wxString wxStandardPaths::GetInstallPrefix() const { - if (m_prefix.empty()) + if ( m_prefix.empty() ) { wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this); #ifdef __LINUX__ - // under Linux, we can get location of the executable - wxChar buf[4096]; - int result; - - // FIXME: is readlink() Unicode-aware or not??? - result = readlink( (const char*)wxT("/proc/self/exe"), (char*)buf, WXSIZEOF(buf) - sizeof(wxChar) ); - if (result != -1) + // under Linux, we can try to infer the prefix from the location of the + // executable + char buf[4096]; + int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char)); + if ( result != -1 ) { - buf[result] = wxChar(0); - wxString exeStr( buf, wxConvLibc ); + buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer + + wxString exeStr(buf, wxConvLibc); // consider that we're in the last "bin" subdirectory of our prefix - wxString basename( wxString(wxTheApp->argv[0]).AfterLast( wxChar('/')) ); - size_t pos = exeStr.find( wxT("/bin/") + basename ); - if (pos != wxString::npos) - pathPtr->m_prefix.assign( exeStr, 0, pos ); + wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/'))); + size_t pos = exeStr.find(wxT("/bin/") + basename); + if ( pos != wxString::npos ) + pathPtr->m_prefix.assign(exeStr, 0, pos); } #endif // __LINUX__ - if (m_prefix.empty()) + if ( m_prefix.empty() ) { #ifdef __VMS - pathPtr->m_prefix = wxT("/sys$system"); + pathPtr->m_prefix = wxT("/sys$system"); #else - pathPtr->m_prefix = wxT("/usr/local"); + pathPtr->m_prefix = wxT("/usr/local"); #endif } }