#ifdef __UNIX__
#include <unistd.h>
#include <dirent.h>
+ #include <fcntl.h>
#endif
#ifdef __WXPM__
#ifdef __WINDOWS__
#include <windows.h>
#include "wx/msw/mslu.h"
-
+
// sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
//
// note that it must be included after <windows.h>
# include "FSpCompat.h"
#endif
-IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
-
// ----------------------------------------------------------------------------
// private globals
// ----------------------------------------------------------------------------
+// MT-FIXME: get rid of this horror and all code using it
static wxChar wxFileFunctionsBuffer[4*_MAXPATHLEN];
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
// implementation
// ============================================================================
+#ifdef wxNEED_WX_UNISTD_H
+
+WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf )
+{
+ return stat( wxConvFile.cWX2MB( file_name ), buf );
+}
+
+WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode )
+{
+ return access( wxConvFile.cWX2MB( pathname ), mode );
+}
+
+WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode )
+{
+ return open( wxConvFile.cWX2MB( pathname ), flags, mode );
+}
+
+#endif
+ // wxNEED_WX_UNISTD_H
+
+// ----------------------------------------------------------------------------
+// wxPathList
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
+
void wxPathList::Add (const wxString& path)
{
wxStringList::Add (WXSTRINGCAST path);
return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY);
#else
wxStructStat stbuf;
- if ( !filename.empty() && wxStat (OS_FILENAME(filename), &stbuf) == 0 )
+ if ( !filename.empty() && wxStat( filename, &stbuf) == 0 )
return TRUE;
return FALSE;
wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
if (user != wxT(""))
wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user);
-#ifdef __WXMSW__
-// strcat(wxFileFunctionsBuffer, "\\");
-#else
-// strcat(wxFileFunctionsBuffer, "/");
-#endif
wxStrcat(wxFileFunctionsBuffer, dest + len);
wxStrcpy (dest, wxFileFunctionsBuffer);
}
return dest;
}
-// Return just the filename, not the path
-// (basename)
+// Return just the filename, not the path (basename)
wxChar *wxFileNameFromPath (wxChar *path)
{
- if (path)
- {
- register wxChar *tcp;
+ wxString p = path;
+ wxString n = wxFileNameFromPath(p);
- tcp = path + wxStrlen (path);
- while (--tcp >= path)
- {
-#if defined(__WXMAC__) && !defined(__DARWIN__)
- // Classic or Carbon CodeWarrior like
- // Carbon with Apple DevTools is Unix like
- if (*tcp == wxT(':'))
- return tcp + 1;
-#else
- // Unix like or Windows
- if (*tcp == wxT('/') || *tcp == wxT('\\'))
- return tcp + 1;
-#endif
-#ifdef __VMS__
- if (*tcp == wxT(':') || *tcp == wxT(']'))
- return tcp + 1;
-#endif
- } /* while */
-#if defined(__WXMSW__) || defined(__WXPM__)
- // MSDOS like
- if (wxIsalpha (*path) && *(path + 1) == wxT(':'))
- return path + 2;
-#endif
- }
- return path;
+ return path + p.length() - n.length();
}
-wxString wxFileNameFromPath (const wxString& path1)
+wxString wxFileNameFromPath (const wxString& path)
{
- if (path1 != wxT(""))
- {
- wxChar *path = WXSTRINGCAST path1 ;
- register wxChar *tcp;
+ wxString name, ext;
+ wxFileName::SplitPath(path, NULL, &name, &ext);
- tcp = path + wxStrlen (path);
- while (--tcp >= path)
- {
-#if defined(__WXMAC__) && !defined(__DARWIN__)
- // Classic or Carbon CodeWarrior like
- // Carbon with Apple DevTools is Unix like
- if (*tcp == wxT(':') )
- return wxString(tcp + 1);
-#else
- // Unix like or Windows
- if (*tcp == wxT('/') || *tcp == wxT('\\'))
- return wxString(tcp + 1);
-#endif
-#ifdef __VMS__
- if (*tcp == wxT(':') || *tcp == wxT(']'))
- return wxString(tcp + 1);
-#endif
- } /* while */
-#if defined(__WXMSW__) || defined(__WXPM__)
- // MSDOS like
- if (wxIsalpha (*path) && *(path + 1) == wxT(':'))
- return wxString(path + 2);
-#endif
+ wxString fullname = name;
+ if ( !ext.empty() )
+ {
+ fullname << wxFILE_SEP_EXT << ext;
}
- // Yes, this should return the path, not an empty string, otherwise
- // we get "thing.txt" -> "".
- return path1;
+
+ return fullname;
}
// Return just the directory, or NULL if no directory
// includes previously prepended path separator
strcat(thePath, theFileName);
}
-
+
// create path string for return value
wxString result( thePath ) ;
#else
return result ;
}
+#ifndef __DARWIN__
+// Mac file names are POSIX (Unix style) under Darwin
+// therefore the conversion functions below are not needed
+
+static char sMacFileNameConversion[ 1000 ] ;
+#endif
void wxMacFilename2FSSpec( const char *path , FSSpec *spec )
{
+ OSStatus err = noErr ;
#ifdef __DARWIN__
FSRef theRef;
// get the FSRef associated with the POSIX path
- (void) FSPathMakeRef((const UInt8 *) path, &theRef, NULL);
+ err = FSPathMakeRef((const UInt8 *) path, &theRef, NULL);
// convert the FSRef to an FSSpec
- (void) FSGetCatalogInfo(&theRef, kFSCatInfoNone, NULL, NULL, spec, NULL);
+ err = FSGetCatalogInfo(&theRef, kFSCatInfoNone, NULL, NULL, spec, NULL);
#else
- FSpLocationFromFullPath( strlen(path) , path , spec ) ;
+ if ( strchr( path , ':' ) == NULL )
+ {
+ // try whether it is a volume / or a mounted volume
+ strncpy( sMacFileNameConversion , path , 1000 ) ;
+ sMacFileNameConversion[998] = 0 ;
+ strcat( sMacFileNameConversion , ":" ) ;
+ err = FSpLocationFromFullPath( strlen(sMacFileNameConversion) , sMacFileNameConversion , spec ) ;
+ }
+ else
+ {
+ err = FSpLocationFromFullPath( strlen(path) , path , spec ) ;
+ }
#endif
}
#ifndef __DARWIN__
-// Mac file names are POSIX (Unix style) under Darwin
-// therefore the conversion functions below are not needed
-
-static char sMacFileNameConversion[ 1000 ] ;
wxString wxMac2UnixFilename (const char *str)
{
FILE *fp2 = (FILE *) NULL;
FILE *fp3 = (FILE *) NULL;
// Open the inputs and outputs
- if ((fp1 = wxFopen (OS_FILENAME( file1 ), wxT("rb"))) == NULL ||
- (fp2 = wxFopen (OS_FILENAME( file2 ), wxT("rb"))) == NULL ||
- (fp3 = wxFopen (OS_FILENAME( outfile ), wxT("wb"))) == NULL)
+ if ((fp1 = wxFopen ( file1, wxT("rb"))) == NULL ||
+ (fp2 = wxFopen ( file2, wxT("rb"))) == NULL ||
+ (fp3 = wxFopen ( outfile, wxT("wb"))) == NULL)
{
if (fp1)
fclose (fp1);
if ( ::DosCopy(file2, file2, overwrite ? DCPY_EXISTING : 0) != 0 )
return FALSE;
#else // !Win32
- wxStructStat fbuf;
+ wxStructStat fbuf;
// get permissions of file1
- if ( wxStat(OS_FILENAME(file1), &fbuf) != 0 )
+ if ( wxStat( file1.c_str(), &fbuf) != 0 )
{
// the file probably doesn't exist or we haven't the rights to read
// from it anyhow
// create file2 with the same permissions than file1 and open it for
// writing
+
wxFile fileOut;
if ( !fileOut.Create(file2, overwrite, fbuf.st_mode & 0777) )
return FALSE;
wxStructStat st;
#ifndef __VISAGECPP__
- return wxStat(wxFNSTRINGCAST strPath.fn_str(), &st) == 0 &&
- ((st.st_mode & S_IFMT) == S_IFDIR);
+ return wxStat(pszPathName, &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(wxFNSTRINGCAST strPath.fn_str(), &st) == 0 &&
- (st.st_mode == S_IFDIR);
+ return wxStat(pszPathName, &st) == 0 && (st.st_mode == S_IFDIR);
#endif
#endif // __WIN32__/!__WIN32__
}
wxString result;
- gs_dir->GetFirst(&result, wxFileNameFromPath((wxChar) spec), dirFlags);
+ gs_dir->GetFirst(&result, wxFileNameFromPath(wxString(spec)), dirFlags);
if ( result.IsEmpty() )
{
wxDELETE(gs_dir);
bool needsANSI = TRUE;
#if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
- wxCharBuffer c_buffer(sz);
- char *cbuf = (char*)(const char*)c_buffer;
+ // This is not legal code as the compiler
+ // is allowed destroy the wxCharBuffer.
+ // wxCharBuffer c_buffer(sz);
+ // char *cbuf = (char*)(const char*)c_buffer;
+ char cbuf[_MAXPATHLEN];
#endif
#ifdef HAVE_WGETCWD
}
#endif // __DJGPP__
-#ifdef __CYGWIN__
+// 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;
cygwin_conv_to_full_win32_path(pathUnix, buf);
wxString wxGetCwd()
{
- wxString str;
-
- // we can't create wxStringBuffer object inline: Sun CC generates buggy
- // code in this case!
- {
- wxStringBuffer buf(str, _MAXPATHLEN);
- wxGetWorkingDirectory(buf, _MAXPATHLEN);
- }
-
+ wxChar *buffer = new wxChar[_MAXPATHLEN];
+ wxGetWorkingDirectory(buffer, _MAXPATHLEN);
+ wxString str( buffer );
+ delete [] buffer;
+
return str;
}
time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename)
{
wxStructStat buf;
-
- wxStat(filename.fn_str(), &buf);
+ wxStat( filename, &buf);
+
return buf.st_mtime;
}
bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
-#if defined(HAVE_FNMATCH_H)
+#ifdef HAVE_FNMATCH
{
// this probably won't work well for multibyte chars in Unicode mode?
if(dot_special)
else
return fnmatch(pat.fn_str(), text.fn_str(), 0) == 0;
}
-#else
+#else // !HAVE_FNMATCH
// #pragma error Broken implementation of wxMatchWild() -- needs fixing!
return ((*str == wxT('\0')) && (*pattern == wxT('\0')));
};
-#endif
+#endif // HAVE_FNMATCH/!HAVE_FNMATCH
#ifdef __VISUALC__
#pragma warning(default:4706) // assignment within conditional expression