Fixed & improved file handling on OS/2.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24647 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2003-11-23 22:29:46 +00:00
parent 22e0b22bac
commit 5a3912f2ab
3 changed files with 56 additions and 47 deletions

View File

@@ -61,6 +61,8 @@
#elif defined(__WXMSW__) && defined(__WXWINCE__) #elif defined(__WXMSW__) && defined(__WXWINCE__)
// TODO: what to include? // TODO: what to include?
#elif (defined(__OS2__))
#include <io.h>
#elif (defined(__UNIX__) || defined(__GNUWIN32__)) #elif (defined(__UNIX__) || defined(__GNUWIN32__))
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
@@ -78,8 +80,6 @@
#else #else
#error "Please specify the header with file functions declarations." #error "Please specify the header with file functions declarations."
#endif #endif
#elif (defined(__WXPM__))
#include <io.h>
#elif (defined(__WXSTUBS__)) #elif (defined(__WXSTUBS__))
// Have to ifdef this for different environments // Have to ifdef this for different environments
#include <io.h> #include <io.h>
@@ -697,7 +697,9 @@ bool wxTempFile::Open(const wxString& strName)
if ( chmod( (const char*) m_strTemp.fn_str(), mode) == -1 ) if ( chmod( (const char*) m_strTemp.fn_str(), mode) == -1 )
{ {
#ifndef __OS2__
wxLogSysError(_("Failed to set temporary file permissions")); wxLogSysError(_("Failed to set temporary file permissions"));
#endif
} }
#endif // Unix #endif // Unix

View File

@@ -80,16 +80,20 @@
#endif #endif
#endif #endif
#ifdef __UNIX__ #ifdef __OS2__
// need to check for __OS2__ first since currently both
// __OS2__ and __UNIX__ are defined.
#include <process.h>
#include "wx/os2/private.h"
#ifdef __EMX__
#include <unistd.h>
#endif
#elif defined(__UNIX__)
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#ifdef __WXPM__
#include <process.h>
#include "wx/os2/private.h"
#endif
#if defined(__WINDOWS__) && !defined(__WXMICROWIN__) #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__) #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__)
#include <direct.h> #include <direct.h>
@@ -245,7 +249,7 @@ void wxPathList::AddEnvList (const wxString& envVariable)
// No environment variables on WinCE // No environment variables on WinCE
#ifndef __WXWINCE__ #ifndef __WXWINCE__
static const wxChar PATH_TOKS[] = static const wxChar PATH_TOKS[] =
#ifdef __WINDOWS__ #if defined(__WINDOWS__) || defined(__OS2__)
/* /*
The space has been removed from the tokenizers, otherwise a The space has been removed from the tokenizers, otherwise a
path such as "C:\Program Files" would be split into 2 paths: 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() ); wxString path2( node->GetData() );
if ( if (
#if defined(__WINDOWS__) || defined(__VMS__) || defined (__WXMAC__) #if defined(__WINDOWS__) || defined(__OS2__) || defined(__VMS__) || defined (__WXMAC__)
// Case INDEPENDENT // Case INDEPENDENT
path.CompareTo (path2, wxString::ignoreCase) == 0 path.CompareTo (path2, wxString::ignoreCase) == 0
#else #else
@@ -403,7 +407,7 @@ wxIsAbsolutePath (const wxString& filename)
if ((filename[0] == wxT('[') && filename[1] != wxT('.'))) if ((filename[0] == wxT('[') && filename[1] != wxT('.')))
return TRUE; return TRUE;
#endif #endif
#ifdef __WINDOWS__ #if defined(__WINDOWS__) || defined(__OS2__)
// MSDOS like // MSDOS like
if (filename[0] == wxT('\\') || (wxIsalpha (filename[0]) && filename[1] == wxT(':'))) if (filename[0] == wxT('\\') || (wxIsalpha (filename[0]) && filename[1] == wxT(':')))
return TRUE; return TRUE;
@@ -485,7 +489,7 @@ wxChar *wxRealPath (wxChar *path)
path[0] = SEP; path[0] = SEP;
path[1] = wxT('\0'); path[1] = wxT('\0');
} }
#ifdef __WXMSW__ #if defined(__WXMSW__) || defined(__OS2__)
/* Check that path[2] is NULL! */ /* Check that path[2] is NULL! */
else if (path[1] == wxT(':') && !path[2]) else if (path[1] == wxT(':') && !path[2])
{ {
@@ -828,7 +832,7 @@ wxPathOnly (wxChar *path)
i --; i --;
} }
#if defined(__WXMSW__) || defined(__WXPM__) #if defined(__WXMSW__) || defined(__OS2__)
// Try Drive specifier // Try Drive specifier
if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) if (wxIsalpha (buf[0]) && buf[1] == wxT(':'))
{ {
@@ -884,7 +888,7 @@ wxString wxPathOnly (const wxString& path)
i --; i --;
} }
#if defined(__WXMSW__) || defined(__WXPM__) #if defined(__WXMSW__) || defined(__OS2__)
// Try Drive specifier // Try Drive specifier
if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) if (wxIsalpha (buf[0]) && buf[1] == wxT(':'))
{ {
@@ -1117,14 +1121,14 @@ wxDos2UnixFilename (wxChar *s)
} }
void void
#if defined(__WXMSW__) || defined(__WXPM__) #if defined(__WXMSW__) || defined(__OS2__)
wxUnix2DosFilename (wxChar *s) wxUnix2DosFilename (wxChar *s)
#else #else
wxUnix2DosFilename (wxChar *WXUNUSED(s) ) wxUnix2DosFilename (wxChar *WXUNUSED(s) )
#endif #endif
{ {
// Yes, I really mean this to happen under DOS only! JACS // Yes, I really mean this to happen under DOS only! JACS
#if defined(__WXMSW__) || defined(__WXPM__) #if defined(__WXMSW__) || defined(__OS2__)
if (s) if (s)
while (*s) while (*s)
{ {
@@ -1190,7 +1194,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite)
return FALSE; return FALSE;
} }
#elif defined(__WXPM__) #elif defined(__OS2__)
if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 ) if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
return FALSE; return FALSE;
#else // !Win32 #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 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
// for the GNU compiler // 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 #ifndef MSVCRT
if ( mkdir(wxFNCONV(dirname), perm) != 0 ) if ( mkdir(wxFNCONV(dirname), perm) != 0 )
#else #else
if ( mkdir(wxFNCONV(dirname)) != 0 ) if ( mkdir(wxFNCONV(dirname)) != 0 )
#endif #endif
#elif defined(__WXPM__) #elif defined(__OS2__)
if (::DosCreateDir((PSZ)dirname, NULL) != 0) // enhance for EAB's?? if (::DosCreateDir((PSZ)dirname, NULL) != 0) // enhance for EAB's??
#elif defined(__DOS__) #elif defined(__DOS__)
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
@@ -1358,7 +1362,7 @@ bool wxRmdir(const wxString& dir, int WXUNUSED(flags))
{ {
#ifdef __VMS__ #ifdef __VMS__
return FALSE; //to be changed since rmdir exists in VMS7.x return FALSE; //to be changed since rmdir exists in VMS7.x
#elif defined(__WXPM__) #elif defined(__OS2__)
return (::DosDeleteDir((PSZ)dir.c_str()) == 0); return (::DosDeleteDir((PSZ)dir.c_str()) == 0);
#else #else
@@ -1376,7 +1380,7 @@ bool wxPathExists(const wxChar *pszPathName)
{ {
wxString strPath(pszPathName); wxString strPath(pszPathName);
#ifdef __WINDOWS__ #if defined(__WINDOWS__) || defined(__OS2__)
// Windows fails to find directory named "c:\dir\" even if "c:\dir" exists, // 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 // 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 "\" // the pathes "d:\" (which are different from "d:") nor for just "\"
@@ -1390,6 +1394,12 @@ bool wxPathExists(const wxChar *pszPathName)
} }
#endif // __WINDOWS__ #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__) #if defined(__WIN32__) && !defined(__WXMICROWIN__)
// stat() can't cope with network paths // stat() can't cope with network paths
DWORD ret = ::GetFileAttributes(strPath); DWORD ret = ::GetFileAttributes(strPath);
@@ -1399,7 +1409,7 @@ bool wxPathExists(const wxChar *pszPathName)
wxStructStat st; wxStructStat st;
#ifndef __VISAGECPP__ #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 #else
// S_IFMT not supported in VA compilers.. st_mode is a 2byte value only // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only
return wxStat(pszPathName, &st) == 0 && (st.st_mode == S_IFDIR); return wxStat(pszPathName, &st) == 0 && (st.st_mode == S_IFDIR);
@@ -1559,13 +1569,24 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
{ {
ok = FALSE; ok = FALSE;
} }
#elif defined(__VISAGECPP__) || (defined (__OS2__) && defined (__WATCOMC__)) #elif defined(__OS2__)
APIRET rc; APIRET rc;
ULONG ulDriveNum = 0;
ULONG ulDriveMap = 0;
rc = ::DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
ok = rc == 0;
if (ok)
{
sz -= 3;
rc = ::DosQueryCurrentDir( 0 // current drive rc = ::DosQueryCurrentDir( 0 // current drive
,cbuf ,cbuf + 3
,(PULONG)&sz ,(PULONG)&sz
); );
ok = rc != 0; cbuf[0] = 'A' + (ulDriveNum - 1);
cbuf[1] = ':';
cbuf[2] = '\\';
ok = rc == 0;
}
#else // !Win32/VC++ !Mac !OS2 #else // !Win32/VC++ !Mac !OS2
ok = getcwd(cbuf, sz) != NULL; ok = getcwd(cbuf, sz) != NULL;
#endif // platform #endif // platform
@@ -1629,10 +1650,10 @@ wxString wxGetCwd()
bool wxSetWorkingDirectory(const wxString& d) bool wxSetWorkingDirectory(const wxString& d)
{ {
#if defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__) #if defined(__OS2__)
return (chdir(wxFNSTRINGCAST d.fn_str()) == 0);
#elif defined(__WXPM__)
return (::DosSetCurrentDir((PSZ)d.c_str()) == 0); return (::DosSetCurrentDir((PSZ)d.c_str()) == 0);
#elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
return (chdir(wxFNSTRINGCAST d.fn_str()) == 0);
#elif defined(__WINDOWS__) #elif defined(__WINDOWS__)
#ifdef __WIN32__ #ifdef __WIN32__

View File

@@ -619,21 +619,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
} }
#endif // Win32/16 #endif // Win32/16
#elif defined(__WXPM__) #else // !Windows
// 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
if ( dir.empty() ) if ( dir.empty() )
{ {
#if defined(__WXMAC__) && !defined(__DARWIN__) #if defined(__WXMAC__) && !defined(__DARWIN__)
@@ -648,7 +634,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
if ( dir.empty() ) if ( dir.empty() )
{ {
// default // default
#ifdef __DOS__ #if defined(__DOS__) || defined(__OS2__)
dir = _T("."); dir = _T(".");
#else #else
dir = _T("/tmp"); dir = _T("/tmp");
@@ -1526,7 +1512,7 @@ wxPathFormat wxFileName::GetFormat( wxPathFormat format )
{ {
if (format == wxPATH_NATIVE) if (format == wxPATH_NATIVE)
{ {
#if defined(__WXMSW__) || defined(__WXPM__) || defined(__DOS__) #if defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__)
format = wxPATH_DOS; format = wxPATH_DOS;
#elif defined(__WXMAC__) && !defined(__DARWIN__) #elif defined(__WXMAC__) && !defined(__DARWIN__)
format = wxPATH_MAC; format = wxPATH_MAC;