]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filefn.cpp
Rename wxUSE_ARCSTREAM to wxUSE_ARCHIVE_STREAMS
[wxWidgets.git] / src / common / filefn.cpp
index 62dfb206d2a79315c17d284bcd93375d8db48024..b780caad9a53fc0cfa39595a6ad601eaed3c036e 100644 (file)
     #endif // __GNUWIN32__
 #endif // __WINDOWS__
 
+#if defined __VMS__
+    #include <fab.h>
+#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
@@ -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