+
+ bool ok wxDUMMY_INITIALIZE(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
+ #define cbuf buf
+#else // wxUSE_UNICODE
+ bool needsANSI = true;
+
+ #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
+ char cbuf[_MAXPATHLEN];
+ #endif
+
+ #ifdef HAVE_WGETCWD
+ #if wxUSE_UNICODE_MSLU
+ if ( wxGetOsVersion() != wxOS_WINDOWS_9X )
+ #else
+ char *cbuf = NULL; // never really used because needsANSI will always be false
+ #endif
+ {
+ ok = _wgetcwd(buf, sz) != NULL;
+ needsANSI = false;
+ }
+ #endif
+
+ if ( needsANSI )
+#endif // wxUSE_UNICODE
+ {
+ #if defined(_MSC_VER) || defined(__MINGW32__)
+ ok = _getcwd(cbuf, sz) != NULL;
+ #elif defined(__WXMAC__) && !defined(__DARWIN__)
+ char lbuf[1024] ;
+ if ( getcwd( lbuf , sizeof( lbuf ) ) )
+ {
+ wxString res( lbuf , *wxConvCurrent ) ;
+ wxStrcpy( buf , res ) ;
+ ok = true;
+ }
+ else
+ ok = false ;
+ #elif defined(__OS2__)
+ APIRET rc;
+ ULONG ulDriveNum = 0;
+ ULONG ulDriveMap = 0;
+ rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
+ ok = rc == 0;
+ if (ok)
+ {
+ sz -= 3;
+ rc = ::DosQueryCurrentDir( 0 // current drive
+ ,cbuf + 3
+ ,(PULONG)&sz
+ );
+ cbuf[0] = char('A' + (ulDriveNum - 1));
+ cbuf[1] = ':';
+ cbuf[2] = '\\';
+ ok = rc == 0;
+ }
+ #else // !Win32/VC++ !Mac !OS2
+ ok = getcwd(cbuf, sz) != NULL;
+ #endif // platform
+
+ #if wxUSE_UNICODE && !(defined(__WXMAC__) && !defined(__DARWIN__))
+ // finally convert the result to Unicode if needed
+ wxConvFile.MB2WC(buf, cbuf, sz);
+ #endif // wxUSE_UNICODE
+ }
+
+ if ( !ok )
+ {
+ wxLogSysError(_("Failed to get the working directory"));
+
+ // VZ: the old code used to return "." on error which didn't make any
+ // sense at all to me - empty string is a better error indicator
+ // (NULL might be even better but I'm afraid this could lead to
+ // problems with the old code assuming the return is never NULL)
+ buf[0] = _T('\0');
+ }
+ else // ok, but we might need to massage the path into the right format
+ {
+#ifdef __DJGPP__
+ // VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
+ // with / deliminers. We don't like that.
+ for (wxChar *ch = buf; *ch; ch++)
+ {
+ if (*ch == wxT('/'))
+ *ch = wxT('\\');
+ }
+#endif // __DJGPP__
+
+// MBN: we hope that in the case the user is compiling a GTK+/Motif app,
+// he needs Unix as opposed to Win32 pathnames
+#if defined( __CYGWIN__ ) && defined( __WINDOWS__ )
+ // another example of DOS/Unix mix (Cygwin)
+ wxString pathUnix = buf;
+#if wxUSE_UNICODE
+ char bufA[_MAXPATHLEN];
+ cygwin_conv_to_full_win32_path(pathUnix.mb_str(wxConvFile), bufA);
+ wxConvFile.MB2WC(buf, bufA, sz);
+#else
+ cygwin_conv_to_full_win32_path(pathUnix, buf);
+#endif // wxUSE_UNICODE
+#endif // __CYGWIN__
+ }
+
+ return buf;
+
+#if !wxUSE_UNICODE
+ #undef cbuf