X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9b4da62701dbe8ccfbe447ce8d1bc77fcb40e9e5..28f12ffb86b5a32c7eaa596a095f4b01890c9f46:/src/common/file.cpp

diff --git a/src/common/file.cpp b/src/common/file.cpp
index a6d96d6a8e..58e36f2218 100644
--- a/src/common/file.cpp
+++ b/src/common/file.cpp
@@ -393,6 +393,21 @@ wxFileOffset wxFile::Length() const
 {
     wxASSERT( IsOpened() );
 
+    // we use a special method for Linux systems where files in sysfs (i.e.
+    // those under /sys typically) return length of 4096 bytes even when
+    // they're much smaller -- this is a problem as it results in errors later
+    // when we try reading 4KB from them
+#ifdef __LINUX__
+    struct stat st;
+    if ( fstat(m_fd, &st) == 0 )
+    {
+        // returning 0 for the special files indicates to the caller that they
+        // are not seekable
+        return st.st_blocks ? st.st_size : 0;
+    }
+    //else: failed to stat, try the normal method
+#endif // __LINUX__
+
     wxFileOffset iRc = Tell();
     if ( iRc != wxInvalidOffset ) {
         // have to use const_cast :-(