Fixed & improved file handling on OS/2.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@24647 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2003-11-23 22:29:46 +00:00
parent 4785fdae07
commit f9f19528bd
3 changed files with 70 additions and 49 deletions

View File

@@ -27,6 +27,10 @@
#if wxUSE_FILE #if wxUSE_FILE
#ifdef __EMX__
#define __OS2__
#endif
// standard // standard
#if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__WXMICROWIN__) #if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__WXWINE__) && !defined(__WXMICROWIN__)
#include <io.h> #include <io.h>
@@ -54,6 +58,8 @@
#define NOMCX #define NOMCX
#endif #endif
#elif (defined(__OS2__))
#include <io.h>
#elif (defined(__UNIX__) || defined(__GNUWIN32__)) #elif (defined(__UNIX__) || defined(__GNUWIN32__))
#include <unistd.h> #include <unistd.h>
#ifdef __GNUWIN32__ #ifdef __GNUWIN32__
@@ -69,8 +75,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>
@@ -523,7 +527,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

@@ -6,7 +6,7 @@
// Created: 29/01/98 // Created: 29/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1998 Julian Smart // Copyright: (c) 1998 Julian Smart
// Licence: wxWindows license // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================ // ============================================================================
@@ -65,16 +65,24 @@
#include <unix.h> #include <unix.h>
#endif #endif
#ifdef __UNIX__ #ifdef __EMX__
#define __OS2__
#endif
#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__) && !defined(__WXWINE__) #if defined(__WINDOWS__) && !defined(__WXMICROWIN__) && !defined(__WXWINE__)
#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
#include <direct.h> #include <direct.h>
@@ -211,7 +219,7 @@ void wxPathList::Add (const wxString& path)
void wxPathList::AddEnvList (const wxString& envVariable) void wxPathList::AddEnvList (const wxString& envVariable)
{ {
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:
@@ -269,7 +277,7 @@ bool wxPathList::Member (const wxString& path)
{ {
wxString path2((wxChar *) node->Data ()); wxString path2((wxChar *) node->Data ());
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
@@ -369,7 +377,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;
@@ -447,7 +455,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])
{ {
@@ -774,7 +782,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(':'))
{ {
@@ -830,7 +838,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(':'))
{ {
@@ -1055,14 +1063,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)
{ {
@@ -1128,7 +1136,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
@@ -1253,9 +1261,9 @@ 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(__WXWINE__) || defined(__WXMICROWIN__) #if (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WXWINE__) || defined(__WXMICROWIN__)
if ( mkdir(wxFNCONV(dirname), perm) != 0 ) if ( mkdir(wxFNCONV(dirname), perm) != 0 )
#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__)
@@ -1284,7 +1292,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
@@ -1302,7 +1310,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 "\"
@@ -1316,6 +1324,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);
@@ -1325,7 +1339,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);
@@ -1485,13 +1499,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
@@ -1552,10 +1577,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

@@ -6,7 +6,7 @@
// Created: 28.12.2000 // Created: 28.12.2000
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2000 Robert Roebling // Copyright: (c) 2000 Robert Roebling
// Licence: wxWindows license // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
/* /*
@@ -94,6 +94,10 @@
#include "wx/mac/private.h" // includes mac headers #include "wx/mac/private.h" // includes mac headers
#endif #endif
#ifdef __EMX__
#define __OS2__
#endif
// utime() is POSIX so should normally be available on all Unices // utime() is POSIX so should normally be available on all Unices
#ifdef __UNIX_LIKE__ #ifdef __UNIX_LIKE__
#include <sys/types.h> #include <sys/types.h>
@@ -594,21 +598,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__)
@@ -623,7 +613,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");
@@ -1433,7 +1423,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;