From 715e4f7e3e26595209b5fe8a9ad3e60cce317e5f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Jul 2010 23:32:46 +0000 Subject: [PATCH] Fix Cygwin 1.7 build. Avoid using Cygwin sockets as our code assumes that we use WinSock API under Windows currently (this might change in the future) by defining __USE_W32_SOCKETS. Use new, safer and more efficient cygwin_conv_path() function. Use t_str() instead of fn_str() with Windows API taking file names, under Cygwin they are different and using fn_str() is incorrect. A few other minor fixes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 8 ++++++++ include/wx/app.h | 2 +- include/wx/defs.h | 6 ++++++ include/wx/evtloop.h | 4 ++-- include/wx/filefn.h | 3 ++- src/common/filefn.cpp | 12 +++++++++++- src/common/filename.cpp | 24 ++++++++++++++---------- src/common/sckaddr.cpp | 6 +++++- src/common/strvararg.cpp | 2 +- src/msw/cursor.cpp | 4 ++-- src/msw/dib.cpp | 2 +- src/msw/dir.cpp | 2 +- src/msw/enhmeta.cpp | 2 +- src/msw/textentry.cpp | 2 +- src/msw/utils.cpp | 16 +++++++++++----- 15 files changed, 67 insertions(+), 28 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index beee8bcbfe..cd10d568e8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -400,6 +400,14 @@ Major new features in this release was added. +2.9.2: +------ + +MSW: + +- Fix Cygwin 1.7 build (David Gangola). + + 2.9.1: ------ diff --git a/include/wx/app.h b/include/wx/app.h index 89df53f419..4b0c4fbc9d 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -497,7 +497,7 @@ protected: wxDECLARE_NO_COPY_CLASS(wxAppConsoleBase); }; -#if defined(__UNIX__) +#if defined(__UNIX__) && !defined(__CYGWIN__) #include "wx/unix/app.h" #else // this has to be a class and not a typedef as we forward declare it diff --git a/include/wx/defs.h b/include/wx/defs.h index 33a0c79c0c..9ac8e09e78 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -193,6 +193,12 @@ #define va_list __gnuc_va_list #endif /* HP-UX */ +/* Prevents conflicts between sys/types.h and winsock.h with Cygwin, */ +/* when using Windows sockets. */ +#if defined(__CYGWIN__) && (__WXMSW__) +#define __USE_W32_SOCKETS +#endif + /* ---------------------------------------------------------------------------- */ /* check for native bool type and TRUE/FALSE constants */ /* ---------------------------------------------------------------------------- */ diff --git a/include/wx/evtloop.h b/include/wx/evtloop.h index 04f0a97761..af4f7baf99 100644 --- a/include/wx/evtloop.h +++ b/include/wx/evtloop.h @@ -17,7 +17,7 @@ // TODO: implement wxEventLoopSource for MSW (it should wrap a HANDLE and be // monitored using MsgWaitForMultipleObjects()) -#if defined(__WXOSX__) || defined(__UNIX__) +#if defined(__WXOSX__) || (defined(__UNIX__) && !defined(__CYGWIN__)) #define wxUSE_EVENTLOOP_SOURCE 1 #else #define wxUSE_EVENTLOOP_SOURCE 0 @@ -310,7 +310,7 @@ protected: #endif // wxUSE_GUI // include the header defining wxConsoleEventLoop for Unix systems -#if defined(__UNIX__) +#if defined(__UNIX__) && !defined(__CYGWIN__) #include "wx/unix/evtloop.h" #endif diff --git a/include/wx/filefn.h b/include/wx/filefn.h index fac3cff5ee..79d20a0d1b 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -578,7 +578,8 @@ inline int wxLstat(const wxString& path, wxStructStat *buf) { return wxCRT_Lstat(path.fn_str(), buf); } inline int wxRmDir(const wxString& path) { return wxCRT_RmDir(path.fn_str()); } -#if defined(__WINDOWS__) || (defined(__OS2__) && defined(__WATCOMC__)) +#if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \ + || (defined(__OS2__) && defined(__WATCOMC__)) inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0) { return wxCRT_MkDir(path.fn_str()); } #else diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 21598eae9c..4dd3e7a486 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -64,11 +64,13 @@ #include "wx/msw/mslu.h" // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path() + // and for cygwin_conv_path() // // note that it must be included after #ifdef __GNUWIN32__ #ifdef __CYGWIN__ #include + #include #endif #endif // __GNUWIN32__ @@ -1062,7 +1064,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) // instead of our code if available // // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite - if ( !::CopyFile(file1.fn_str(), file2.fn_str(), !overwrite) ) + if ( !::CopyFile(file1.t_str(), file2.t_str(), !overwrite) ) { wxLogSysError(_("Failed to copy the file '%s' to '%s'"), file1.c_str(), file2.c_str()); @@ -1505,11 +1507,19 @@ wxChar *wxDoGetCwd(wxChar *buf, int sz) // another example of DOS/Unix mix (Cygwin) wxString pathUnix = buf; #if wxUSE_UNICODE + #if CYGWIN_VERSION_DLL_MAJOR >= 1007 + cygwin_conv_path(CCP_POSIX_TO_WIN_W, pathUnix.mb_str(wxConvFile), buf, sz); + #else char bufA[_MAXPATHLEN]; cygwin_conv_to_full_win32_path(pathUnix.mb_str(wxConvFile), bufA); wxConvFile.MB2WC(buf, bufA, sz); + #endif #else + #if CYGWIN_VERSION_DLL_MAJOR >= 1007 + cygwin_conv_path(CCP_POSIX_TO_WIN_A, pathUnix, buf, sz); + #else cygwin_conv_to_full_win32_path(pathUnix, buf); + #endif #endif // wxUSE_UNICODE #endif // __CYGWIN__ } diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 8a713ba7a4..882581cded 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -188,7 +188,7 @@ public: // access time (see #10567) m_hFile = ::CreateFile ( - filename.fn_str(), // name + filename.t_str(), // name mode == ReadAttr ? FILE_READ_ATTRIBUTES // access mask : FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | // sharing mode @@ -613,7 +613,7 @@ bool wxFileName::FileExists( const wxString &filePath ) #elif defined(__WIN32__) && !defined(__WXMICROWIN__) // we must use GetFileAttributes() instead of the ANSI C functions because // it can cope with network (UNC) paths unlike them - DWORD ret = ::GetFileAttributes(filePath.fn_str()); + DWORD ret = ::GetFileAttributes(filePath.t_str()); return (ret != INVALID_FILE_ATTRIBUTES) && !(ret & FILE_ATTRIBUTE_DIRECTORY); #else // !__WIN32__ @@ -670,7 +670,7 @@ bool wxFileName::DirExists( const wxString &dirPath ) return false; #elif defined(__WIN32__) && !defined(__WXMICROWIN__) // stat() can't cope with network paths - DWORD ret = ::GetFileAttributes(strPath.fn_str()); + DWORD ret = ::GetFileAttributes(strPath.t_str()); return (ret != INVALID_FILE_ATTRIBUTES) && (ret & FILE_ATTRIBUTE_DIRECTORY); #elif defined(__OS2__) @@ -876,8 +876,8 @@ static wxString wxCreateTempImpl( } #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) - if ( !::GetTempFileName(dir.fn_str(), name.fn_str(), 0, - wxStringBuffer(path, MAX_PATH + 1)) ) + if (!::GetTempFileName(dir.t_str(), name.t_str(), 0, + wxStringBuffer(path, MAX_PATH + 1))) { wxLogLastError(wxT("GetTempFileName")); @@ -1287,7 +1287,11 @@ bool wxFileName::Rmdir(const wxString& dir, int flags) SHFILEOPSTRUCT fileop; wxZeroMemory(fileop); fileop.wFunc = FO_DELETE; + #if defined(__CYGWIN__) && defined(wxUSE_UNICODE) + fileop.pFrom = path.wc_str(); + #else fileop.pFrom = path.fn_str(); + #endif fileop.fFlags = FOF_SILENT | FOF_NOCONFIRMATION; #ifndef __WXWINCE__ // FOF_NOERRORUI is not defined in WinCE @@ -2058,13 +2062,13 @@ wxString wxFileName::GetShortPath() const wxString path(GetFullPath()); #if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__) - DWORD sz = ::GetShortPathName(path.fn_str(), NULL, 0); + DWORD sz = ::GetShortPathName(path.t_str(), NULL, 0); if ( sz != 0 ) { wxString pathOut; if ( ::GetShortPathName ( - path.fn_str(), + path.t_str(), wxStringBuffer(pathOut, sz), sz ) != 0 ) @@ -2122,12 +2126,12 @@ wxString wxFileName::GetLongPath() const if ( s_pfnGetLongPathName ) { - DWORD dwSize = (*s_pfnGetLongPathName)(path.fn_str(), NULL, 0); + DWORD dwSize = (*s_pfnGetLongPathName)(path.t_str(), NULL, 0); if ( dwSize > 0 ) { if ( (*s_pfnGetLongPathName) ( - path.fn_str(), + path.t_str(), wxStringBuffer(pathOut, dwSize), dwSize ) != 0 ) @@ -2179,7 +2183,7 @@ wxString wxFileName::GetLongPath() const continue; } - hFind = ::FindFirstFile(tmpPath.fn_str(), &findFileData); + hFind = ::FindFirstFile(tmpPath.t_str(), &findFileData); if (hFind == INVALID_HANDLE_VALUE) { // Error: most likely reason is that path doesn't exist, so diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index 5f2797cf5c..ea2fc9d89f 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -49,7 +49,7 @@ #include -#ifdef __UNIX__ +#if defined(__UNIX__) && !defined(__CYGWIN__) #include #include #endif // __UNIX__ @@ -82,8 +82,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress) #ifdef __WXMSW__ #define HAVE_INET_ADDR + #ifndef HAVE_GETHOSTBYNAME #define HAVE_GETHOSTBYNAME + #endif + #ifndef HAVE_GETSERVBYNAME #define HAVE_GETSERVBYNAME + #endif // under MSW getxxxbyname() functions are MT-safe (but not reentrant) so // we don't need to serialize calls to them diff --git a/src/common/strvararg.cpp b/src/common/strvararg.cpp index f70593c0c5..a4c2256dfb 100644 --- a/src/common/strvararg.cpp +++ b/src/common/strvararg.cpp @@ -375,7 +375,7 @@ private: size_t m_nCopied; }; -#ifdef __WINDOWS__ +#if defined(__WINDOWS__) && !defined(__CYGWIN__) // on Windows, we should use %s and %c regardless of the build: class wxPrintfFormatConverterWchar : public wxFormatConverterBase diff --git a/src/msw/cursor.cpp b/src/msw/cursor.cpp index a839795758..bfa5771d24 100644 --- a/src/msw/cursor.cpp +++ b/src/msw/cursor.cpp @@ -236,12 +236,12 @@ wxCursor::wxCursor(const wxString& filename, switch ( kind ) { case wxBITMAP_TYPE_CUR_RESOURCE: - hcursor = ::LoadCursor(wxGetInstance(), filename.fn_str()); + hcursor = ::LoadCursor(wxGetInstance(), filename.t_str()); break; #ifndef __WXWINCE__ case wxBITMAP_TYPE_CUR: - hcursor = ::LoadCursorFromFile(filename.fn_str()); + hcursor = ::LoadCursorFromFile(filename.t_str()); break; #endif diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index 9ea25315bf..be10fcf047 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -280,7 +280,7 @@ bool wxDIB::Load(const wxString& filename) m_handle = (HBITMAP)::LoadImage ( wxGetInstance(), - filename.fn_str(), + filename.t_str(), IMAGE_BITMAP, 0, 0, // don't specify the size LR_CREATEDIBSECTION | LR_LOADFROMFILE diff --git a/src/msw/dir.cpp b/src/msw/dir.cpp index 81c312e825..48d4e4e0a5 100644 --- a/src/msw/dir.cpp +++ b/src/msw/dir.cpp @@ -67,7 +67,7 @@ inline void FreeFindData(FIND_DATA fd) inline FIND_DATA FindFirst(const wxString& spec, FIND_STRUCT *finddata) { - return ::FindFirstFile(spec.fn_str(), finddata); + return ::FindFirstFile(spec.t_str(), finddata); } inline bool FindNext(FIND_DATA fd, FIND_STRUCT *finddata) diff --git a/src/msw/enhmeta.cpp b/src/msw/enhmeta.cpp index a59f622acc..97850755ea 100644 --- a/src/msw/enhmeta.cpp +++ b/src/msw/enhmeta.cpp @@ -92,7 +92,7 @@ void wxEnhMetaFile::Init() } else // have valid file name, load metafile from it { - m_hMF = (WXHANDLE)::GetEnhMetaFile(m_filename.fn_str()); + m_hMF = (WXHANDLE)::GetEnhMetaFile(m_filename.t_str()); if ( !m_hMF ) { wxLogSysError(_("Failed to load metafile from file \"%s\"."), diff --git a/src/msw/textentry.cpp b/src/msw/textentry.cpp index 298e07b8eb..b52704883d 100644 --- a/src/msw/textentry.cpp +++ b/src/msw/textentry.cpp @@ -55,7 +55,7 @@ #include "wx/msw/ole/oleutils.h" #include -#if defined(__MINGW32__) || defined (__WATCOMC__) +#if defined(__MINGW32__) || defined (__WATCOMC__) || defined(__CYGWIN__) // needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST #include #endif diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index c7b64cc6dd..e23656dfa9 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -67,7 +67,9 @@ #if defined(__CYGWIN__) #include #include - #include // for cygwin_conv_to_full_win32_path() + #include // for cygwin_conv_path() + // and cygwin_conv_to_full_win32_path() + #include #endif //GNUWIN32 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs @@ -367,7 +369,7 @@ const wxChar* wxGetHomeDir(wxString *pstr) // first branch is for Cygwin #if defined(__UNIX__) && !defined(__WINE__) - const wxChar *szHome = wxGetenv("HOME"); + const wxChar *szHome = wxGetenv(wxT("HOME")); if ( szHome == NULL ) { // we're homeless... wxLogWarning(_("can't find user's HOME, using current directory.")); @@ -383,7 +385,11 @@ const wxChar* wxGetHomeDir(wxString *pstr) #ifdef __CYGWIN__ // Cygwin returns unix type path but that does not work well static wxChar windowsPath[MAX_PATH]; - cygwin_conv_to_full_win32_path(strDir, windowsPath); + #if CYGWIN_VERSION_DLL_MAJOR >= 1007 + cygwin_conv_path(CCP_POSIX_TO_WIN_W, strDir, windowsPath, MAX_PATH); + #else + cygwin_conv_to_full_win32_path(strDir, windowsPath); + #endif strDir = windowsPath; #endif #elif defined(__WXWINCE__) @@ -494,7 +500,7 @@ bool wxGetDiskSpace(const wxString& WXUNUSED_IN_WINCE(path), ULARGE_INTEGER bytesFree, bytesTotal; // may pass the path as is, GetDiskFreeSpaceEx() is smart enough - if ( !pGetDiskFreeSpaceEx(path.fn_str(), + if ( !pGetDiskFreeSpaceEx(path.t_str(), &bytesFree, &bytesTotal, NULL) ) @@ -544,7 +550,7 @@ bool wxGetDiskSpace(const wxString& WXUNUSED_IN_WINCE(path), // FIXME: this is wrong, we should extract the root drive from path // instead, but this is the job for wxFileName... - if ( !::GetDiskFreeSpace(path.fn_str(), + if ( !::GetDiskFreeSpace(path.t_str(), &lSectorsPerCluster, &lBytesPerSector, &lNumberOfFreeClusters, -- 2.45.2