X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f73bc315aac67f087106454a7f23a8a0d3a4bda2..fef5c55604e20e2a90843a2278b1f5c8c817dcee:/src/common/filefn.cpp?ds=sidebyside diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 80c870d8b8..c9daf16772 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -80,16 +80,20 @@ #endif #endif -#ifdef __UNIX__ +#ifdef __OS2__ +// need to check for __OS2__ first since currently both +// __OS2__ and __UNIX__ are defined. + #include + #include "wx/os2/private.h" +#ifdef __EMX__ + #include +#endif +#elif defined(__UNIX__) #include #include #include #endif -#ifdef __WXPM__ - #include - #include "wx/os2/private.h" -#endif #if defined(__WINDOWS__) && !defined(__WXMICROWIN__) #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__) #include @@ -196,25 +200,6 @@ const off_t wxInvalidOffset = (off_t)-1; // implementation // ============================================================================ -#if defined(__WXMAC__) && !defined(__DARWIN__) && !defined(wxUSE_UNICODE) - -WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) -{ - return stat( wxMacStringToCString( file_name ), buf ); -} - -WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode ) -{ - return access( wxMacStringToCString( pathname ), mode ); -} - -WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode ) -{ - return open( wxMacStringToCString( pathname ), flags, mode ); -} - -#endif - #ifdef wxNEED_WX_UNISTD_H WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) @@ -264,7 +249,7 @@ void wxPathList::AddEnvList (const wxString& envVariable) // No environment variables on WinCE #ifndef __WXWINCE__ static const wxChar PATH_TOKS[] = -#ifdef __WINDOWS__ +#if defined(__WINDOWS__) || defined(__OS2__) /* The space has been removed from the tokenizers, otherwise a path such as "C:\Program Files" would be split into 2 paths: @@ -323,7 +308,7 @@ bool wxPathList::Member (const wxString& path) { wxString path2( node->GetData() ); if ( -#if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__) +#if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined (__WXMAC__) // Case INDEPENDENT path.CompareTo (path2, wxString::ignoreCase) == 0 #else @@ -344,8 +329,7 @@ wxString wxPathList::FindValidPath (const wxString& file) wxChar buf[_MAXPATHLEN]; wxStrcpy(buf, wxFileFunctionsBuffer); - wxChar *filename = (wxChar*) NULL; /* shut up buggy egcs warning */ - filename = wxIsAbsolutePath (buf) ? wxFileNameFromPath (buf) : (wxChar *)buf; + wxChar *filename = wxIsAbsolutePath (buf) ? wxFileNameFromPath (buf) : (wxChar *)buf; for (wxStringList::compatibility_iterator node = GetFirst(); node; node = node->GetNext()) { @@ -423,7 +407,7 @@ wxIsAbsolutePath (const wxString& filename) if ((filename[0] == wxT('[') && filename[1] != wxT('.'))) return TRUE; #endif -#ifdef __WINDOWS__ +#if defined(__WINDOWS__) || defined(__OS2__) // MSDOS like if (filename[0] == wxT('\\') || (wxIsalpha (filename[0]) && filename[1] == wxT(':'))) return TRUE; @@ -505,7 +489,7 @@ wxChar *wxRealPath (wxChar *path) path[0] = SEP; path[1] = wxT('\0'); } -#ifdef __WXMSW__ +#if defined(__WXMSW__) || defined(__OS2__) /* Check that path[2] is NULL! */ else if (path[1] == wxT(':') && !path[2]) { @@ -751,9 +735,9 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin #endif // Handle environment - const wxChar *val = (const wxChar *) NULL; + const wxChar *val; #ifndef __WXWINCE__ - wxChar *tcp = (wxChar *) NULL; + wxChar *tcp; if (envname != WXSTRINGCAST NULL && (val = wxGetenv (WXSTRINGCAST envname)) != NULL && (tcp = wxStrstr (dest, val)) != NULL) { @@ -767,7 +751,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin #endif // Handle User's home (ignore root homes!) - size_t len = 0; + size_t len; if ((val = wxGetUserHome (user)) != NULL && (len = wxStrlen(val)) > 2 && wxStrncmp(dest, val, len) == 0) @@ -848,7 +832,7 @@ wxPathOnly (wxChar *path) i --; } -#if defined(__WXMSW__) || defined(__WXPM__) +#if defined(__WXMSW__) || defined(__OS2__) // Try Drive specifier if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) { @@ -904,7 +888,7 @@ wxString wxPathOnly (const wxString& path) i --; } -#if defined(__WXMSW__) || defined(__WXPM__) +#if defined(__WXMSW__) || defined(__OS2__) // Try Drive specifier if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) { @@ -929,7 +913,7 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) int i; int j; OSErr theErr; - OSStatus theStatus; + OSStatus theStatus = noErr; Boolean isDirectory = FALSE; Str255 theParentPath = "\p"; FSSpec theParentSpec; @@ -991,7 +975,7 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) (*myPath)[length-1] = 0 ; // create path string for return value - wxString result = wxMacMakeStringFromCString( *myPath ) ; + wxString result( *myPath , wxConvLocal) ; // free allocated handle ::HUnlock( myPath ) ; @@ -1037,7 +1021,7 @@ void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) #if wxUSE_UNICODE WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec ) { - return wxMacFilename2FSSpec( wxMacStringToCString( wxString( path ) ) , spec ) ; + return wxMacFilename2FSSpec( wxConvFile.cWC2MB(path) , spec ) ; } #endif @@ -1137,14 +1121,14 @@ wxDos2UnixFilename (wxChar *s) } void -#if defined(__WXMSW__) || defined(__WXPM__) +#if defined(__WXMSW__) || defined(__OS2__) wxUnix2DosFilename (wxChar *s) #else wxUnix2DosFilename (wxChar *WXUNUSED(s) ) #endif { // Yes, I really mean this to happen under DOS only! JACS -#if defined(__WXMSW__) || defined(__WXPM__) +#if defined(__WXMSW__) || defined(__OS2__) if (s) while (*s) { @@ -1163,9 +1147,9 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil if ( !wxGetTempFileName( wxT("cat"), outfile) ) return FALSE; - FILE *fp1 = (FILE *) NULL; - FILE *fp2 = (FILE *) NULL; - FILE *fp3 = (FILE *) NULL; + FILE *fp1 wxDUMMY_INITIALIZE(NULL); + FILE *fp2 = NULL; + FILE *fp3 = NULL; // Open the inputs and outputs if ((fp1 = wxFopen ( file1, wxT("rb"))) == NULL || (fp2 = wxFopen ( file2, wxT("rb"))) == NULL || @@ -1210,7 +1194,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) return FALSE; } -#elif defined(__WXPM__) +#elif defined(__OS2__) if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 ) return FALSE; #else // !Win32 @@ -1319,6 +1303,7 @@ bool wxRemoveFile(const wxString& file) #if defined(__VISUALC__) \ || defined(__BORLANDC__) \ || defined(__WATCOMC__) \ + || defined(__DMC__) \ || defined(__GNUWIN32__) int res = wxRemove(file); #elif defined(__WXMAC__) @@ -1339,13 +1324,13 @@ bool wxMkdir(const wxString& dir, int perm) // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too // for the GNU compiler -#if (!(defined(__WXMSW__) || defined(__WXPM__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WINE__) || defined(__WXMICROWIN__) +#if (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WINE__) || defined(__WXMICROWIN__) #ifndef MSVCRT if ( mkdir(wxFNCONV(dirname), perm) != 0 ) #else if ( mkdir(wxFNCONV(dirname)) != 0 ) #endif -#elif defined(__WXPM__) +#elif defined(__OS2__) if (::DosCreateDir((PSZ)dirname, NULL) != 0) // enhance for EAB's?? #elif defined(__DOS__) #if defined(__WATCOMC__) @@ -1378,7 +1363,7 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags)) { #ifdef __VMS__ return FALSE; //to be changed since rmdir exists in VMS7.x -#elif defined(__WXPM__) +#elif defined(__OS2__) return (::DosDeleteDir((PSZ)dir.c_str()) == 0); #else @@ -1396,7 +1381,7 @@ bool wxPathExists(const wxChar *pszPathName) { wxString strPath(pszPathName); -#ifdef __WINDOWS__ +#if defined(__WINDOWS__) || defined(__OS2__) // 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 // the pathes "d:\" (which are different from "d:") nor for just "\" @@ -1410,6 +1395,12 @@ bool wxPathExists(const wxChar *pszPathName) } #endif // __WINDOWS__ +#ifdef __OS2__ + // OS/2 can't handle "d:", it wants either "d:\" or "d:." + if (strPath.length() == 2 && strPath[1u] == _T(':')) + strPath << _T('.'); +#endif + #if defined(__WIN32__) && !defined(__WXMICROWIN__) // stat() can't cope with network paths DWORD ret = ::GetFileAttributes(strPath); @@ -1419,7 +1410,7 @@ bool wxPathExists(const wxChar *pszPathName) wxStructStat st; #ifndef __VISAGECPP__ - return wxStat(pszPathName, &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR); + return wxStat(strPath.c_str(), &st) == 0 && ((st.st_mode & S_IFMT) == S_IFDIR); #else // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only return wxStat(pszPathName, &st) == 0 && (st.st_mode == S_IFDIR); @@ -1473,7 +1464,7 @@ wxString wxFindFirstFile(const wxChar *spec, int flags) return wxEmptyString; } - int dirFlags = 0; + int dirFlags; switch (flags) { case wxDIR: dirFlags = wxDIR_DIRS; break; @@ -1522,7 +1513,7 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) buf = new wxChar[sz + 1]; } - bool ok = FALSE; + 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 @@ -1579,13 +1570,24 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) { ok = FALSE; } - #elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__)) + #elif defined(__OS2__) APIRET rc; - rc = ::DosQueryCurrentDir( 0 // current drive - ,cbuf - ,(PULONG)&sz - ); - ok = rc != 0; + 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] = 'A' + (ulDriveNum - 1); + cbuf[1] = ':'; + cbuf[2] = '\\'; + ok = rc == 0; + } #else // !Win32/VC++ !Mac !OS2 ok = getcwd(cbuf, sz) != NULL; #endif // platform @@ -1649,10 +1651,10 @@ wxString wxGetCwd() bool wxSetWorkingDirectory(const wxString& d) { -#if defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__) - return (chdir(wxFNSTRINGCAST d.fn_str()) == 0); -#elif defined(__WXPM__) +#if defined(__OS2__) return (::DosSetCurrentDir((PSZ)d.c_str()) == 0); +#elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__) + return (chdir(wxFNSTRINGCAST d.fn_str()) == 0); #elif defined(__WINDOWS__) #ifdef __WIN32__