//
// note that it must be included after <windows.h>
#ifdef __GNUWIN32__
- #include <sys/cygwin.h>
+ #ifdef __CYGWIN__
+ #include <sys/cygwin.h>
+ #endif
#include <wchar.h>
#ifndef __TWIN32__
#include <sys/unistd.h>
#define _MAXPATHLEN 1024
#endif
-extern wxChar *wxBuffer;
-
#ifdef __WXMAC__
# include "MoreFiles.h"
# include "MoreFilesExtras.h"
wxFileExists (const wxString& filename)
{
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
- // GetFileAttributes can copy with network paths
+ // GetFileAttributes can copy with network paths unlike stat()
DWORD ret = ::GetFileAttributes(filename);
- if ( ret == (DWORD)-1 )
- {
- wxLogLastError(_T("GetFileAttributes"));
-
- return FALSE;
- }
- return !(ret & FILE_ATTRIBUTE_DIRECTORY);
+ return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else
wxStructStat stbuf;
if ( !filename.empty() && wxStat (OS_FILENAME(filename), &stbuf) == 0 )
bool wxPathExists(const wxChar *pszPathName)
{
wxString strPath(pszPathName);
+
#ifdef __WINDOWS__
// Windows fails to find directory named "c:\dir\" even if "c:\dir" exists,
// so remove all trailing backslashes from the path - but don't do this for
#endif // __WINDOWS__
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
- // Stat can't cope with network paths
- DWORD ret = ::GetFileAttributes(filename);
- if ( ret == (DWORD)-1 )
- {
- wxLogLastError(_T("GetFileAttributes"));
+ // stat() can't cope with network paths
+ DWORD ret = ::GetFileAttributes(strPath);
- return FALSE;
- }
-
- return (ret & FILE_ATTRIBUTE_DIRECTORY) != 0;
-#else
+ return (ret != (DWORD)-1) && (ret & FILE_ATTRIBUTE_DIRECTORY);
+#else // !__WIN32__
wxStructStat st;
#ifndef __VISAGECPP__
(st.st_mode == S_IFDIR);
#endif
-#endif
+#endif // __WIN32__/!__WIN32__
}
// Get a temporary filename, opening and closing the file.
buf = new wxChar[sz + 1];
}
- bool ok;
+ bool ok = FALSE;
// for the compilers which have Unicode version of _getcwd(), call it
// directly, for the others call the ANSI version and do the translation
-#if wxUSE_UNICODE
+#if !wxUSE_UNICODE
+ #define cbuf buf
+#else // wxUSE_UNICODE
+ bool needsANSI = TRUE;
+
+ #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
+ wxCharBuffer c_buffer(sz);
+ char *cbuf = (char*)(const char*)c_buffer;
+ #endif
+
#ifdef HAVE_WGETCWD
- ok = _wgetcwd(buf, sz) != NULL;
- #else // !HAVE_WGETCWD
- wxCharBuffer cbuf(sz);
+ #if wxUSE_UNICODE_MSLU
+ if ( wxGetOsVersion() != wxWIN95 )
+ #endif
+ {
+ ok = _wgetcwd(buf, sz) != NULL;
+ needsANSI = FALSE;
+ }
#endif
-#endif //
-#if !wxUSE_UNICODE || !defined(HAVE_WGETCWD)
+ if ( needsANSI )
+#endif // wxUSE_UNICODE
+ {
#ifdef _MSC_VER
- ok = _getcwd(buf, sz) != NULL;
+ ok = _getcwd(cbuf, sz) != NULL;
#elif defined(__WXMAC__) && !defined(__DARWIN__)
FSSpec cwdSpec ;
FCBPBRec pb;
cwdSpec.name[0] = 0 ;
wxString res = wxMacFSSpec2MacFilename( &cwdSpec ) ;
- strcpy( buf , res ) ;
- buf[res.length()]=0 ;
+ strcpy( cbuf , res ) ;
+ cbuf[res.length()]=0 ;
ok = TRUE;
}
#elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__))
APIRET rc;
rc = ::DosQueryCurrentDir( 0 // current drive
- ,buf
+ ,cbuf
,(PULONG)&sz
);
ok = rc != 0;
#else // !Win32/VC++ !Mac !OS2
- ok = getcwd(buf, sz) != NULL;
+ ok = getcwd(cbuf, sz) != NULL;
#endif // platform
-#endif // !wxUSE_UNICODE || !HAVE_WGETCWD
+ }
if ( !ok )
{
}
#endif // __DJGPP__
-#ifdef __GNUWIN32__
+#ifdef __CYGWIN__
// another example of DOS/Unix mix (Cygwin)
wxString pathUnix = buf;
cygwin_conv_to_full_win32_path(pathUnix, buf);
-#endif // __GNUWIN32__
+#endif // __CYGWIN__
// finally convert the result to Unicode if needed
-#if wxUSE_UNICODE && !defined(HAVE_WGETCWD)
+#if wxUSE_UNICODE
wxConvFile.MB2WC(buf, cbuf, sz);
#endif // wxUSE_UNICODE
}
return buf;
+
+#if !wxUSE_UNICODE
+ #undef cbuf
+#endif
}
wxString wxGetCwd()