X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a6f4dbbd86b54c720bdeab1aea1fad5eb3f030e6..9e8e867ff99be2e9d02e4e94766d27068ae66f57:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 9ba4a565c0..b780caad9a 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -75,6 +75,10 @@ #endif // __GNUWIN32__ #endif // __WINDOWS__ +#if defined __VMS__ + #include +#endif + // TODO: Borland probably has _wgetcwd as well? #ifdef _MSC_VER #define HAVE_WGETCWD @@ -309,7 +313,7 @@ wxFileExists (const wxString& filename) bool wxIsAbsolutePath (const wxString& filename) { - if (filename != wxT("")) + if (!filename.empty()) { #if defined(__WXMAC__) && !defined(__DARWIN__) // Classic or Carbon CodeWarrior like @@ -432,7 +436,7 @@ wxChar *wxRealPath (wxChar *path) // Must be destroyed wxChar *wxCopyAbsolutePath(const wxString& filename) { - if (filename == wxT("")) + if (filename.empty()) return (wxChar *) NULL; if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer, filename))) { @@ -588,7 +592,7 @@ wxChar *wxExpandPath(wxChar *buf, const wxChar *name) if (nm[1] == SEP || nm[1] == 0) { /* ~/filename */ // FIXME: wxGetUserHome could return temporary storage in Unicode mode - if ((s = WXSTRINGCAST wxGetUserHome(wxT(""))) != NULL) { + if ((s = WXSTRINGCAST wxGetUserHome(wxEmptyString)) != NULL) { if (*++nm) nm++; } @@ -647,7 +651,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin { static wxChar dest[_MAXPATHLEN]; - if (filename == wxT("")) + if (filename.empty()) return (wxChar *) NULL; wxStrcpy (dest, WXSTRINGCAST filename); @@ -683,7 +687,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin if (wxStrncmp(dest, val, len) == 0) { wxStrcpy(wxFileFunctionsBuffer, wxT("~")); - if (user != wxT("")) + if (!user.empty()) wxStrcat(wxFileFunctionsBuffer, (const wxChar*) user); wxStrcat(wxFileFunctionsBuffer, dest + len); wxStrcpy (dest, wxFileFunctionsBuffer); @@ -775,7 +779,7 @@ wxPathOnly (wxChar *path) // Return just the directory, or NULL if no directory wxString wxPathOnly (const wxString& path) { - if (path != wxT("")) + if (!path.empty()) { wxChar buf[_MAXPATHLEN]; @@ -828,7 +832,7 @@ wxString wxPathOnly (const wxString& path) } #endif } - return wxString(wxT("")); + return wxEmptyString; } // Utility for converting delimiters in DOS filenames to UNIX style @@ -951,9 +955,9 @@ wxConcatFiles (const wxString& file1, const wxString& file2, const wxString& fil FILE *fp2 = NULL; FILE *fp3 = NULL; // Open the inputs and outputs - if ((fp1 = wxFopen ( file1.fn_str(), wxT("rb"))) == NULL || - (fp2 = wxFopen ( file2.fn_str(), wxT("rb"))) == NULL || - (fp3 = wxFopen ( outfile.fn_str(), 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); @@ -1852,6 +1856,47 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special ) } } +// Return the type of an open file +// +wxFileTypeEnum wxGetFileType(int fd) +{ + if (isatty(fd)) + return wxFILE_TYPE_TERMINAL; + +#if defined __WXMSW__ + switch (::GetFileType(wxGetOSFHandle(fd)) & ~FILE_TYPE_REMOTE) + { + case FILE_TYPE_DISK: + return wxFILE_TYPE_DISK; + case FILE_TYPE_PIPE: + return wxFILE_TYPE_PIPE; + } + + return wxFILE_TYPE_UNKNOWN; + +#elif defined __UNIX__ + struct stat st; + fstat(fd, &st); + + if (S_ISFIFO(st.st_mode)) + return wxFILE_TYPE_PIPE; + if (!S_ISREG(st.st_mode)) + return wxFILE_TYPE_UNKNOWN; + + #if defined __VMS__ + if (st.st_fab_rfm != FAB$C_STMLF) + return wxFILE_TYPE_UNKNOWN; + #endif + + return wxFILE_TYPE_DISK; + +#else + if (lseek(fd, 0, SEEK_CUR) != -1) + return wxFILE_TYPE_DISK; + else + return wxFILE_TYPE_UNKNOWN; +#endif +} #ifdef __VISUALC__ #pragma warning(default:4706) // assignment within conditional expression