X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/acdc3b6b5c870778f17fcfaac0353371bd7ab033..2035e10e83324c6925d12725b842768f6e2b00a2:/src/common/filefn.cpp?ds=sidebyside diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 7e2b9c3855..2a1694b0a7 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -112,7 +112,7 @@ #define _MAXPATHLEN 500 -extern char *wxBuffer; +extern wxChar *wxBuffer; #ifdef __WXMAC__ @@ -122,9 +122,7 @@ extern char *wxBuffer; #include "fspcompa.h" #endif -#if !USE_SHARED_LIBRARIES IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList) -#endif // ---------------------------------------------------------------------------- // private globals @@ -132,6 +130,14 @@ extern char *wxBuffer; static wxChar wxFileFunctionsBuffer[4*_MAXPATHLEN]; +#if defined(__VISAGECPP__) && __IBMCPP__ >= 400 +// +// VisualAge C++ V4.0 cannot have any external linkage const decs +// in headers included by more than one primary source +// +const off_t wxInvalidOffset = (off_t)-1; +#endif + // ============================================================================ // implementation // ============================================================================ @@ -612,7 +618,6 @@ wxChar *wxExpandPath(wxChar *buf, const wxChar *name) return wxRealPath(buf); } - /* Contract Paths to be build upon an environment variable component: @@ -946,9 +951,9 @@ wxDos2UnixFilename (char *s) void #if defined(__WXMSW__) || defined(__WXPM__) -wxUnix2DosFilename (char *s) +wxUnix2DosFilename (wxChar *s) #else -wxUnix2DosFilename (char *WXUNUSED(s) ) +wxUnix2DosFilename (wxChar *WXUNUSED(s) ) #endif { // Yes, I really mean this to happen under DOS only! JACS @@ -978,9 +983,9 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil (fp2 = fopen (wxUnix2MacFilename( file2 ), "rb")) == NULL || (fp3 = fopen (wxUnix2MacFilename( outfile ), "wb")) == NULL) #else - if ((fp1 = fopen (WXSTRINGCAST file1, "rb")) == NULL || - (fp2 = fopen (WXSTRINGCAST file2, "rb")) == NULL || - (fp3 = fopen (outfile, "wb")) == NULL) + if ((fp1 = wxFopen (WXSTRINGCAST file1, wxT("rb"))) == NULL || + (fp2 = wxFopen (WXSTRINGCAST file2, wxT("rb"))) == NULL || + (fp3 = wxFopen (outfile, wxT("wb"))) == NULL) #endif { if (fp1) @@ -1020,9 +1025,9 @@ wxCopyFile (const wxString& file1, const wxString& file2) return FALSE; if ((fd2 = fopen (wxUnix2MacFilename( file2 ), "wb")) == NULL) #else - if ((fd1 = fopen (WXSTRINGCAST file1, "rb")) == NULL) + if ((fd1 = wxFopen (WXSTRINGCAST file1, wxT("rb"))) == NULL) return FALSE; - if ((fd2 = fopen (WXSTRINGCAST file2, "wb")) == NULL) + if ((fd2 = wxFopen (WXSTRINGCAST file2, wxT("wb"))) == NULL) #endif { fclose (fd1); @@ -1078,9 +1083,9 @@ 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(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WXWINE__) +#if (!(defined(__WXMSW__) || defined(__OS2__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WXWINE__) if ( mkdir(wxFNCONV(dirname), perm) != 0 ) -#else // MSW and OS/2 +#else // !MSW and !OS/2 VAC++ if ( mkdir(wxFNSTRINGCAST wxFNCONV(dirname)) != 0 ) #endif // !MSW/MSW { @@ -1220,6 +1225,18 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) #endif } +bool wxGetTempFileName(const wxString& prefix, wxString& buf) +{ + wxChar buf2[512]; + if (wxGetTempFileName(prefix, buf2) != (wxChar*) NULL) + { + buf = buf2; + return TRUE; + } + else + return FALSE; +} + // Get first file name matching given wild card. #ifdef __UNIX__ @@ -1293,7 +1310,9 @@ wxString wxFindNextFile() nextDir != NULL; nextDir = readdir(gs_dirStream) ) { - if (wxMatchWild(name, nextDir->d_name)) + if (wxMatchWild(name, nextDir->d_name, FALSE) && // RR: added FALSE to find hidden files + strcmp(nextDir->d_name, ".") && + strcmp(nextDir->d_name, "..") ) { result.Empty(); if ( !path.IsEmpty() ) @@ -1397,7 +1416,7 @@ wxString wxFindNextFile() if ( ( g_iter.m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(g_iter_flags & wxFILE ) ) continue ; - + // hit ! break ; } @@ -1411,7 +1430,7 @@ wxString wxFindNextFile() g_iter.m_dirId, g_iter.m_name, &spec) ; - + return wxMacFSSpec2UnixFilename( &spec ) ; } @@ -1505,6 +1524,7 @@ wxString wxFindFirstFile(const wxChar *spec, int flags) return result; } + wxString wxFindNextFile() { wxString result; @@ -1576,7 +1596,51 @@ try_again: return result; } -#endif // Unix/Windows +#elif defined(__WXPM__) + +wxString wxFindFirstFile(const wxChar *spec, int flags) +{ + wxString result; + + /* + // TODO: figure something out here for OS/2 + gs_strFileSpec = spec; + gs_findFlags = flags; + + // Find path only so we can concatenate found file onto path + wxString path(wxPathOnly(gs_strFileSpec)); + if ( !path.IsEmpty() ) + result << path << wxT('\\'); + + int flag = _A_NORMAL; + if (flags & wxDIR) + flag = _A_SUBDIR; + + if (_dos_findfirst(WXSTRINGCAST spec, flag, &gs_findDataStruct) == 0) + { + char attrib; + attrib = gs_findDataStruct.attrib; + + if (attrib & _A_SUBDIR) { + if (!(gs_findFlags & wxDIR)) + return wxFindNextFile(); + } else if (gs_findFlags && !(gs_findFlags & wxFILE)) + return wxFindNextFile(); + + result += gs_findDataStruct.name; + } + */ + return result; +} + +wxString wxFindNextFile() +{ + wxString result; + // TODO: + return result; +} + +#endif // Unix/Windows/OS/2 // Get current working directory. // If buf is NULL, allocates space using new, else @@ -1608,9 +1672,9 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) #ifdef _MSC_VER if (_getcwd(buf, sz) == NULL) { #elif defined( __WXMAC__) - enum - { - SFSaveDisk = 0x214, CurDirStore = 0x398 + enum + { + SFSaveDisk = 0x214, CurDirStore = 0x398 }; FSSpec cwdSpec ; @@ -1762,14 +1826,18 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName, #else // assume Unix const wxChar *pLastSeparator = wxStrrchr(pszFileName, wxFILE_SEP_PATH_UNIX); - if ( pDot == pszFileName ) + if ( pDot ) { - // under Unix files like .profile are treated in a special way - pDot = NULL; + if ( (pDot == pszFileName) || (*(pDot - 1) == wxFILE_SEP_PATH_UNIX) ) + { + // under Unix, dot may be (and commonly is) the first character of the + // filename, don't treat the entire filename as extension in this case + pDot = NULL; + } } #endif // MSW/Unix - if ( pDot < pLastSeparator ) + if ( pDot && (pDot < pLastSeparator) ) { // the dot is part of the path, not the start of the extension pDot = NULL; @@ -1800,6 +1868,17 @@ void WXDLLEXPORT wxSplitPath(const wxChar *pszFileName, } } + + +time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) +{ + struct stat buf; + + stat(filename.fn_str(), &buf); + return buf.st_mtime; +} + + //------------------------------------------------------------------------ // wild character routines //------------------------------------------------------------------------