]> git.saurik.com Git - wxWidgets.git/commitdiff
Move wxGetOSFHandle to include/wx/msw/private.h since it needs HANDLE anyway
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Sat, 26 Feb 2005 15:31:42 +0000 (15:31 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Sat, 26 Feb 2005 15:31:42 +0000 (15:31 +0000)
and make it a macro. Make the 'default' return value for wxGetFileKind
wxFILE_KIND_DISK and add a comment explaining what it's for.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32389 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/filefn.h
include/wx/msw/private.h
src/common/filefn.cpp

index 871ed8c932e9748ba78998207b9a8ce654d18534..c58e9e5acee9e9ee5a2b348a89855849e81e0ced 100644 (file)
@@ -148,7 +148,6 @@ enum wxFileKind
     int wxWrite(int fd, const void *buf, unsigned int count);
     int wxEof(int fd);
     wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin);
-    inline HANDLE wxGetOSFHandle(int fd) { return (HANDLE)fd; }
     #define wxLSeek wxSeek
     wxFileOffset wxTell(int fd);
     
@@ -352,20 +351,6 @@ enum wxFileKind
     #endif
 #endif // platforms
 
-#if defined(__WXMSW__) && !defined(__WXWINCE__)
-    // get the HANDLE associated with a file descriptor
-#   ifdef __CYGWIN__
-#       include "wx/msw/private.h" // for HANDLE
-#       include <io.h> // for get_osfhandle()
-        inline HANDLE wxGetOSFHandle(int fd) { return (HANDLE) get_osfhandle(fd); }
-#   else
-#       ifdef __BORLANDC__
-#           include "wx/msw/private.h" // for HANDLE
-#       endif
-        inline HANDLE wxGetOSFHandle(int fd) { return (HANDLE) _get_osfhandle(fd); }
-#   endif
-#endif
-
 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
 //
 // VisualAge C++ V4.0 cannot have any external linkage const decs
index ff47704cfa483db90dc17881120aac9c76aa0e77..f28a0fde02b2bcfdad3e521ed3e52d9e29664af3 100644 (file)
@@ -174,6 +174,24 @@ extern LONG APIENTRY _EXPORT
 #define wxZeroMemory(obj)   memset((void*) & obj, 0, sizeof(obj))
 #endif
 
+// This one is a macro so that it can be tested with #ifdef, it will be
+// undefined if it cannot be implemented for a given compiler.
+// Vc++, bcc, dmc, ow, mingw, codewarrior (and rsxnt) have _get_osfhandle.
+// Cygwin has get_osfhandle. Others are currently unknown, e.g. Salford,
+// Intel, Visual Age.
+#if defined(__WXWINCE__)
+    #define wxGetOSFHandle(fd) ((HANDLE)fd)
+#elif defined(__CYGWIN__)
+    #define wxGetOSFHandle(fd) ((HANDLE)get_osfhandle(fd))
+#elif defined(__VISUALC__) \
+   || defined(__BORLANDC__) \
+   || defined(__WATCOMC__) \
+   || defined(__DMC__) \
+   || (defined(__GNUWIN32__) || defined(__MINGW32__)) \
+   || (defined(__MWERKS__) && defined(__MSL__))
+    #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
+#endif
+
 #if wxUSE_GUI
 
 #include <wx/gdicmn.h>
index ae3ff0335ef86620150702d2eba7756559a412ff..fbb1a719bb2594a8d0890e4d55043b8e384cd263 100644 (file)
@@ -62,7 +62,7 @@
 #endif
 
 #ifdef __WINDOWS__
-    #include "wx/msw/wrapwin.h"
+    #include "wx/msw/private.h"
     #include "wx/msw/mslu.h"
 
     // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
             #include <sys/cygwin.h>
         #endif
     #endif // __GNUWIN32__
+
+    // io.h is needed for _get_osfhandle()
+    // Already included by filefn.h for many Windows compilers
+    #if defined __MWERKS__ || defined __CYGWIN__
+        #include <io.h>
+    #endif
 #endif // __WINDOWS__
 
 #if defined(__VMS__)
@@ -1879,20 +1885,29 @@ bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
 
 // Return the type of an open file
 //
+// Some file types on some platforms seem seekable but in fact are not.
+// The main use of this function is to allow such cases to be detected
+// (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
+//
+// This is important for the archive streams, which benefit greatly from
+// being able to seek on a stream, but which will produce corrupt archives
+// if they unknowingly seek on a non-seekable stream.
+// 
+// wxFILE_KIND_DISK is a good catch all return value, since other values
+// disable features of the archive streams. Some other value must be returned
+// for a file type that appears seekable but isn't.
+//
+// Known examples:
+//   *  Pipes on Windows
+//   *  Files on VMS with a record format other than StreamLF
+//
 wxFileKind wxGetFileKind(int fd)
 {
-#if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
-    if (isatty(fd))
-        return wxFILE_KIND_TERMINAL;
-#endif
-
-#if defined(__WXPALMOS__)
-    return wxFILE_KIND_UNKNOWN;
-#elif defined(__WXWINCE__)
-    return wxFILE_KIND_UNKNOWN;
-#elif defined(__WXMSW__)
+#if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
     switch (::GetFileType(wxGetOSFHandle(fd)) & ~FILE_TYPE_REMOTE)
     {
+        case FILE_TYPE_CHAR:
+            return wxFILE_KIND_TERMINAL;
         case FILE_TYPE_DISK:
             return wxFILE_KIND_DISK;
         case FILE_TYPE_PIPE:
@@ -1902,6 +1917,9 @@ wxFileKind wxGetFileKind(int fd)
     return wxFILE_KIND_UNKNOWN;
 
 #elif defined(__UNIX__)
+    if (isatty(fd))
+        return wxFILE_KIND_TERMINAL;
+
     struct stat st;
     fstat(fd, &st);
 
@@ -1918,10 +1936,8 @@ wxFileKind wxGetFileKind(int fd)
     return wxFILE_KIND_DISK;
 
 #else
-    if (lseek(fd, 0, SEEK_CUR) != -1)
-        return wxFILE_KIND_DISK;
-    else
-        return wxFILE_KIND_UNKNOWN;
+    (void)fd;
+    return wxFILE_KIND_DISK;
 #endif
 }