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
This commit is contained in:
Vadim Zeitlin
2010-07-23 23:32:46 +00:00
parent 3d4e20dd0b
commit 715e4f7e3e
15 changed files with 67 additions and 28 deletions

View File

@@ -400,6 +400,14 @@ Major new features in this release
was added. was added.
2.9.2:
------
MSW:
- Fix Cygwin 1.7 build (David Gangola).
2.9.1: 2.9.1:
------ ------

View File

@@ -497,7 +497,7 @@ protected:
wxDECLARE_NO_COPY_CLASS(wxAppConsoleBase); wxDECLARE_NO_COPY_CLASS(wxAppConsoleBase);
}; };
#if defined(__UNIX__) #if defined(__UNIX__) && !defined(__CYGWIN__)
#include "wx/unix/app.h" #include "wx/unix/app.h"
#else #else
// this has to be a class and not a typedef as we forward declare it // this has to be a class and not a typedef as we forward declare it

View File

@@ -193,6 +193,12 @@
#define va_list __gnuc_va_list #define va_list __gnuc_va_list
#endif /* HP-UX */ #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 */ /* check for native bool type and TRUE/FALSE constants */
/* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */

View File

@@ -17,7 +17,7 @@
// TODO: implement wxEventLoopSource for MSW (it should wrap a HANDLE and be // TODO: implement wxEventLoopSource for MSW (it should wrap a HANDLE and be
// monitored using MsgWaitForMultipleObjects()) // monitored using MsgWaitForMultipleObjects())
#if defined(__WXOSX__) || defined(__UNIX__) #if defined(__WXOSX__) || (defined(__UNIX__) && !defined(__CYGWIN__))
#define wxUSE_EVENTLOOP_SOURCE 1 #define wxUSE_EVENTLOOP_SOURCE 1
#else #else
#define wxUSE_EVENTLOOP_SOURCE 0 #define wxUSE_EVENTLOOP_SOURCE 0
@@ -310,7 +310,7 @@ protected:
#endif // wxUSE_GUI #endif // wxUSE_GUI
// include the header defining wxConsoleEventLoop for Unix systems // include the header defining wxConsoleEventLoop for Unix systems
#if defined(__UNIX__) #if defined(__UNIX__) && !defined(__CYGWIN__)
#include "wx/unix/evtloop.h" #include "wx/unix/evtloop.h"
#endif #endif

View File

@@ -578,7 +578,8 @@ inline int wxLstat(const wxString& path, wxStructStat *buf)
{ return wxCRT_Lstat(path.fn_str(), buf); } { return wxCRT_Lstat(path.fn_str(), buf); }
inline int wxRmDir(const wxString& path) inline int wxRmDir(const wxString& path)
{ return wxCRT_RmDir(path.fn_str()); } { 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) inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
{ return wxCRT_MkDir(path.fn_str()); } { return wxCRT_MkDir(path.fn_str()); }
#else #else

View File

@@ -64,11 +64,13 @@
#include "wx/msw/mslu.h" #include "wx/msw/mslu.h"
// sys/cygwin.h is needed for cygwin_conv_to_full_win32_path() // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
// and for cygwin_conv_path()
// //
// note that it must be included after <windows.h> // note that it must be included after <windows.h>
#ifdef __GNUWIN32__ #ifdef __GNUWIN32__
#ifdef __CYGWIN__ #ifdef __CYGWIN__
#include <sys/cygwin.h> #include <sys/cygwin.h>
#include <cygwin/version.h>
#endif #endif
#endif // __GNUWIN32__ #endif // __GNUWIN32__
@@ -1062,7 +1064,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
// instead of our code if available // instead of our code if available
// //
// NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite // 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'"), wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
file1.c_str(), file2.c_str()); file1.c_str(), file2.c_str());
@@ -1505,11 +1507,19 @@ wxChar *wxDoGetCwd(wxChar *buf, int sz)
// another example of DOS/Unix mix (Cygwin) // another example of DOS/Unix mix (Cygwin)
wxString pathUnix = buf; wxString pathUnix = buf;
#if wxUSE_UNICODE #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]; char bufA[_MAXPATHLEN];
cygwin_conv_to_full_win32_path(pathUnix.mb_str(wxConvFile), bufA); cygwin_conv_to_full_win32_path(pathUnix.mb_str(wxConvFile), bufA);
wxConvFile.MB2WC(buf, bufA, sz); wxConvFile.MB2WC(buf, bufA, sz);
#endif
#else #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); cygwin_conv_to_full_win32_path(pathUnix, buf);
#endif
#endif // wxUSE_UNICODE #endif // wxUSE_UNICODE
#endif // __CYGWIN__ #endif // __CYGWIN__
} }

View File

@@ -188,7 +188,7 @@ public:
// access time (see #10567) // access time (see #10567)
m_hFile = ::CreateFile m_hFile = ::CreateFile
( (
filename.fn_str(), // name filename.t_str(), // name
mode == ReadAttr ? FILE_READ_ATTRIBUTES // access mask mode == ReadAttr ? FILE_READ_ATTRIBUTES // access mask
: FILE_WRITE_ATTRIBUTES, : FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | // sharing mode FILE_SHARE_READ | // sharing mode
@@ -613,7 +613,7 @@ bool wxFileName::FileExists( const wxString &filePath )
#elif defined(__WIN32__) && !defined(__WXMICROWIN__) #elif defined(__WIN32__) && !defined(__WXMICROWIN__)
// we must use GetFileAttributes() instead of the ANSI C functions because // we must use GetFileAttributes() instead of the ANSI C functions because
// it can cope with network (UNC) paths unlike them // 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); return (ret != INVALID_FILE_ATTRIBUTES) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else // !__WIN32__ #else // !__WIN32__
@@ -670,7 +670,7 @@ bool wxFileName::DirExists( const wxString &dirPath )
return false; return false;
#elif defined(__WIN32__) && !defined(__WXMICROWIN__) #elif defined(__WIN32__) && !defined(__WXMICROWIN__)
// stat() can't cope with network paths // 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); return (ret != INVALID_FILE_ATTRIBUTES) && (ret & FILE_ATTRIBUTE_DIRECTORY);
#elif defined(__OS2__) #elif defined(__OS2__)
@@ -876,8 +876,8 @@ static wxString wxCreateTempImpl(
} }
#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
if ( !::GetTempFileName(dir.fn_str(), name.fn_str(), 0, if (!::GetTempFileName(dir.t_str(), name.t_str(), 0,
wxStringBuffer(path, MAX_PATH + 1)) ) wxStringBuffer(path, MAX_PATH + 1)))
{ {
wxLogLastError(wxT("GetTempFileName")); wxLogLastError(wxT("GetTempFileName"));
@@ -1287,7 +1287,11 @@ bool wxFileName::Rmdir(const wxString& dir, int flags)
SHFILEOPSTRUCT fileop; SHFILEOPSTRUCT fileop;
wxZeroMemory(fileop); wxZeroMemory(fileop);
fileop.wFunc = FO_DELETE; fileop.wFunc = FO_DELETE;
#if defined(__CYGWIN__) && defined(wxUSE_UNICODE)
fileop.pFrom = path.wc_str();
#else
fileop.pFrom = path.fn_str(); fileop.pFrom = path.fn_str();
#endif
fileop.fFlags = FOF_SILENT | FOF_NOCONFIRMATION; fileop.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;
#ifndef __WXWINCE__ #ifndef __WXWINCE__
// FOF_NOERRORUI is not defined in WinCE // FOF_NOERRORUI is not defined in WinCE
@@ -2058,13 +2062,13 @@ wxString wxFileName::GetShortPath() const
wxString path(GetFullPath()); wxString path(GetFullPath());
#if defined(__WXMSW__) && defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__) #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 ) if ( sz != 0 )
{ {
wxString pathOut; wxString pathOut;
if ( ::GetShortPathName if ( ::GetShortPathName
( (
path.fn_str(), path.t_str(),
wxStringBuffer(pathOut, sz), wxStringBuffer(pathOut, sz),
sz sz
) != 0 ) ) != 0 )
@@ -2122,12 +2126,12 @@ wxString wxFileName::GetLongPath() const
if ( s_pfnGetLongPathName ) 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 ( dwSize > 0 )
{ {
if ( (*s_pfnGetLongPathName) if ( (*s_pfnGetLongPathName)
( (
path.fn_str(), path.t_str(),
wxStringBuffer(pathOut, dwSize), wxStringBuffer(pathOut, dwSize),
dwSize dwSize
) != 0 ) ) != 0 )
@@ -2179,7 +2183,7 @@ wxString wxFileName::GetLongPath() const
continue; continue;
} }
hFind = ::FindFirstFile(tmpPath.fn_str(), &findFileData); hFind = ::FindFirstFile(tmpPath.t_str(), &findFileData);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
{ {
// Error: most likely reason is that path doesn't exist, so // Error: most likely reason is that path doesn't exist, so

View File

@@ -49,7 +49,7 @@
#include <errno.h> #include <errno.h>
#ifdef __UNIX__ #if defined(__UNIX__) && !defined(__CYGWIN__)
#include <netdb.h> #include <netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#endif // __UNIX__ #endif // __UNIX__
@@ -82,8 +82,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxUNIXaddress, wxSockAddress)
#ifdef __WXMSW__ #ifdef __WXMSW__
#define HAVE_INET_ADDR #define HAVE_INET_ADDR
#ifndef HAVE_GETHOSTBYNAME
#define HAVE_GETHOSTBYNAME #define HAVE_GETHOSTBYNAME
#endif
#ifndef HAVE_GETSERVBYNAME
#define HAVE_GETSERVBYNAME #define HAVE_GETSERVBYNAME
#endif
// under MSW getxxxbyname() functions are MT-safe (but not reentrant) so // under MSW getxxxbyname() functions are MT-safe (but not reentrant) so
// we don't need to serialize calls to them // we don't need to serialize calls to them

View File

@@ -375,7 +375,7 @@ private:
size_t m_nCopied; size_t m_nCopied;
}; };
#ifdef __WINDOWS__ #if defined(__WINDOWS__) && !defined(__CYGWIN__)
// on Windows, we should use %s and %c regardless of the build: // on Windows, we should use %s and %c regardless of the build:
class wxPrintfFormatConverterWchar : public wxFormatConverterBase<wchar_t> class wxPrintfFormatConverterWchar : public wxFormatConverterBase<wchar_t>

View File

@@ -236,12 +236,12 @@ wxCursor::wxCursor(const wxString& filename,
switch ( kind ) switch ( kind )
{ {
case wxBITMAP_TYPE_CUR_RESOURCE: case wxBITMAP_TYPE_CUR_RESOURCE:
hcursor = ::LoadCursor(wxGetInstance(), filename.fn_str()); hcursor = ::LoadCursor(wxGetInstance(), filename.t_str());
break; break;
#ifndef __WXWINCE__ #ifndef __WXWINCE__
case wxBITMAP_TYPE_CUR: case wxBITMAP_TYPE_CUR:
hcursor = ::LoadCursorFromFile(filename.fn_str()); hcursor = ::LoadCursorFromFile(filename.t_str());
break; break;
#endif #endif

View File

@@ -280,7 +280,7 @@ bool wxDIB::Load(const wxString& filename)
m_handle = (HBITMAP)::LoadImage m_handle = (HBITMAP)::LoadImage
( (
wxGetInstance(), wxGetInstance(),
filename.fn_str(), filename.t_str(),
IMAGE_BITMAP, IMAGE_BITMAP,
0, 0, // don't specify the size 0, 0, // don't specify the size
LR_CREATEDIBSECTION | LR_LOADFROMFILE LR_CREATEDIBSECTION | LR_LOADFROMFILE

View File

@@ -67,7 +67,7 @@ inline void FreeFindData(FIND_DATA fd)
inline FIND_DATA FindFirst(const wxString& spec, inline FIND_DATA FindFirst(const wxString& spec,
FIND_STRUCT *finddata) FIND_STRUCT *finddata)
{ {
return ::FindFirstFile(spec.fn_str(), finddata); return ::FindFirstFile(spec.t_str(), finddata);
} }
inline bool FindNext(FIND_DATA fd, FIND_STRUCT *finddata) inline bool FindNext(FIND_DATA fd, FIND_STRUCT *finddata)

View File

@@ -92,7 +92,7 @@ void wxEnhMetaFile::Init()
} }
else // have valid file name, load metafile from it 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 ) if ( !m_hMF )
{ {
wxLogSysError(_("Failed to load metafile from file \"%s\"."), wxLogSysError(_("Failed to load metafile from file \"%s\"."),

View File

@@ -55,7 +55,7 @@
#include "wx/msw/ole/oleutils.h" #include "wx/msw/ole/oleutils.h"
#include <shldisp.h> #include <shldisp.h>
#if defined(__MINGW32__) || defined (__WATCOMC__) #if defined(__MINGW32__) || defined (__WATCOMC__) || defined(__CYGWIN__)
// needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST // needed for IID_IAutoComplete, IID_IAutoComplete2 and ACO_AUTOSUGGEST
#include <shlguid.h> #include <shlguid.h>
#endif #endif

View File

@@ -67,7 +67,9 @@
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
#include <sys/unistd.h> #include <sys/unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/cygwin.h> // for cygwin_conv_to_full_win32_path() #include <sys/cygwin.h> // for cygwin_conv_path()
// and cygwin_conv_to_full_win32_path()
#include <cygwin/version.h>
#endif //GNUWIN32 #endif //GNUWIN32
#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs #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 // first branch is for Cygwin
#if defined(__UNIX__) && !defined(__WINE__) #if defined(__UNIX__) && !defined(__WINE__)
const wxChar *szHome = wxGetenv("HOME"); const wxChar *szHome = wxGetenv(wxT("HOME"));
if ( szHome == NULL ) { if ( szHome == NULL ) {
// we're homeless... // we're homeless...
wxLogWarning(_("can't find user's HOME, using current directory.")); wxLogWarning(_("can't find user's HOME, using current directory."));
@@ -383,7 +385,11 @@ const wxChar* wxGetHomeDir(wxString *pstr)
#ifdef __CYGWIN__ #ifdef __CYGWIN__
// Cygwin returns unix type path but that does not work well // Cygwin returns unix type path but that does not work well
static wxChar windowsPath[MAX_PATH]; 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; strDir = windowsPath;
#endif #endif
#elif defined(__WXWINCE__) #elif defined(__WXWINCE__)
@@ -494,7 +500,7 @@ bool wxGetDiskSpace(const wxString& WXUNUSED_IN_WINCE(path),
ULARGE_INTEGER bytesFree, bytesTotal; ULARGE_INTEGER bytesFree, bytesTotal;
// may pass the path as is, GetDiskFreeSpaceEx() is smart enough // may pass the path as is, GetDiskFreeSpaceEx() is smart enough
if ( !pGetDiskFreeSpaceEx(path.fn_str(), if ( !pGetDiskFreeSpaceEx(path.t_str(),
&bytesFree, &bytesFree,
&bytesTotal, &bytesTotal,
NULL) ) 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 // FIXME: this is wrong, we should extract the root drive from path
// instead, but this is the job for wxFileName... // instead, but this is the job for wxFileName...
if ( !::GetDiskFreeSpace(path.fn_str(), if ( !::GetDiskFreeSpace(path.t_str(),
&lSectorsPerCluster, &lSectorsPerCluster,
&lBytesPerSector, &lBytesPerSector,
&lNumberOfFreeClusters, &lNumberOfFreeClusters,