X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b0091f58f89adc3c3ced38353aedffa0effde17f..b1a046e821900affb64c4a267c653a6a7eafd94c:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 819602adea..59d875f298 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -68,13 +68,14 @@ #ifdef __UNIX__ #include #include + #include #endif #ifdef __WXPM__ #include #include "wx/os2/private.h" #endif -#if defined(__WINDOWS__) && !defined(__WXMICROWIN__) +#if defined(__WINDOWS__) && !defined(__WXMICROWIN__) && !defined(__WXWINE__) #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) #include #include @@ -150,12 +151,11 @@ # 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 @@ -177,6 +177,32 @@ const off_t wxInvalidOffset = (off_t)-1; // 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); @@ -307,7 +333,7 @@ wxFileExists (const wxString& filename) 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; @@ -669,11 +695,6 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin 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); } @@ -681,75 +702,27 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin 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 @@ -947,26 +920,40 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) 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) { @@ -1092,9 +1079,9 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil 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); @@ -1139,10 +1126,10 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) 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 @@ -1173,6 +1160,7 @@ wxCopyFile (const wxString& file1, const wxString& file2, bool overwrite) // 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; @@ -1331,12 +1319,10 @@ bool wxPathExists(const wxChar *pszPathName) 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__ @@ -1396,7 +1382,7 @@ wxString wxFindFirstFile(const wxChar *spec, int flags) } wxString result; - gs_dir->GetFirst(&result, wxFileNameFromPath((wxChar*) spec), dirFlags); + gs_dir->GetFirst(&result, wxFileNameFromPath(wxString(spec)), dirFlags); if ( result.IsEmpty() ) { wxDELETE(gs_dir); @@ -1443,8 +1429,11 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) 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 @@ -1529,7 +1518,9 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) } #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); @@ -1545,15 +1536,11 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) 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; } @@ -1670,8 +1657,8 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName, time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) { wxStructStat buf; - - wxStat(filename.fn_str(), &buf); + wxStat( filename, &buf); + return buf.st_mtime; }