From 5a3912f2aba8f5232315f7ca2206c50295ec21ea Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Sun, 23 Nov 2003 22:29:46 +0000 Subject: [PATCH] Fixed & improved file handling on OS/2. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24647 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/file.cpp | 6 ++-- src/common/filefn.cpp | 77 ++++++++++++++++++++++++++--------------- src/common/filename.cpp | 20 ++--------- 3 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/common/file.cpp b/src/common/file.cpp index 83423c7ffa..3eacce8a6a 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -61,6 +61,8 @@ #elif defined(__WXMSW__) && defined(__WXWINCE__) // TODO: what to include? +#elif (defined(__OS2__)) + #include #elif (defined(__UNIX__) || defined(__GNUWIN32__)) #include #include @@ -78,8 +80,6 @@ #else #error "Please specify the header with file functions declarations." #endif -#elif (defined(__WXPM__)) - #include #elif (defined(__WXSTUBS__)) // Have to ifdef this for different environments #include @@ -697,7 +697,9 @@ bool wxTempFile::Open(const wxString& strName) if ( chmod( (const char*) m_strTemp.fn_str(), mode) == -1 ) { +#ifndef __OS2__ wxLogSysError(_("Failed to set temporary file permissions")); +#endif } #endif // Unix diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 1d7119cabe..0df53ba158 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 @@ -245,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: @@ -304,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 @@ -403,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; @@ -485,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]) { @@ -828,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(':')) { @@ -884,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(':')) { @@ -1117,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) { @@ -1190,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,13 +1323,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__) @@ -1358,7 +1362,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 @@ -1376,7 +1380,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 "\" @@ -1390,6 +1394,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[1] == _T(':')) + strPath << _T('.'); +#endif + #if defined(__WIN32__) && !defined(__WXMICROWIN__) // stat() can't cope with network paths DWORD ret = ::GetFileAttributes(strPath); @@ -1399,7 +1409,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); @@ -1559,13 +1569,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 @@ -1629,10 +1650,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__ diff --git a/src/common/filename.cpp b/src/common/filename.cpp index e18d20c657..062ddc41fb 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -619,21 +619,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) } #endif // Win32/16 -#elif defined(__WXPM__) - // for now just create a file - // - // future enhancements can be to set some extended attributes for file - // systems OS/2 supports that have them (HPFS, FAT32) and security - // (HPFS386) - static const wxChar *szMktempSuffix = wxT("XXX"); - path << dir << _T('/') << name << szMktempSuffix; - - // Temporarily remove - MN - #ifndef __WATCOMC__ - ::DosCreateDir(wxStringBuffer(path, MAX_PATH), NULL); - #endif - -#else // !Windows, !OS/2 +#else // !Windows if ( dir.empty() ) { #if defined(__WXMAC__) && !defined(__DARWIN__) @@ -648,7 +634,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp) if ( dir.empty() ) { // default - #ifdef __DOS__ + #if defined(__DOS__) || defined(__OS2__) dir = _T("."); #else dir = _T("/tmp"); @@ -1526,7 +1512,7 @@ wxPathFormat wxFileName::GetFormat( wxPathFormat format ) { if (format == wxPATH_NATIVE) { -#if defined(__WXMSW__) || defined(__WXPM__) || defined(__DOS__) +#if defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__) format = wxPATH_DOS; #elif defined(__WXMAC__) && !defined(__DARWIN__) format = wxPATH_MAC; -- 2.45.2