]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/utilsunx.cpp
non-PCH build fix (according to Tinderbox).
[wxWidgets.git] / src / unix / utilsunx.cpp
index b26b8df3f5671750ed99d859f1912ab09488bdbd..66068411bebc02b89c219ba63dae9abd0bc8b737 100644 (file)
      defined(__osf__) || defined(__EMX__))
     extern "C"
     {
-        #ifdef __SUN__
+        #ifdef __EMX__
+            /* I copied this from the XFree86 diffs. AV. */
+            #define INCL_DOSPROCESS
+            #include <os2.h>
+            inline void usleep(unsigned long delay)
+            {
+                DosSleep(delay ? (delay/1000l) : 1l);
+            }
+        #else // Unix
             int usleep(unsigned int usec);
-        #else // !Sun
-            #ifdef __EMX__
-                /* I copied this from the XFree86 diffs. AV. */
-                #define INCL_DOSPROCESS
-                #include <os2.h>
-                inline void usleep(unsigned long delay)
-                {
-                    DosSleep(delay ? (delay/1000l) : 1l);
-                }
-            #else // !Sun && !EMX
-                void usleep(unsigned long usec);
-            #endif
-        #endif // Sun/EMX/Something else
+        #endif // __EMX__/Unix
     };
 
     #define HAVE_USLEEP 1
@@ -960,8 +956,31 @@ wxMemorySize wxGetFreeMemory()
         char buf[1024];
         if ( fgets(buf, WXSIZEOF(buf), fp) && fgets(buf, WXSIZEOF(buf), fp) )
         {
-            long memTotal, memUsed;
-            sscanf(buf, "Mem: %ld %ld %ld", &memTotal, &memUsed, &memFree);
+            // /proc/meminfo changed its format in kernel 2.6
+            if ( wxPlatformInfo().CheckOSVersion(2, 6) )
+            {
+                unsigned long cached, buffers;
+                sscanf(buf, "MemFree: %ld", &memFree);
+
+                fgets(buf, WXSIZEOF(buf), fp);
+                sscanf(buf, "Buffers: %lu", &buffers);
+
+                fgets(buf, WXSIZEOF(buf), fp);
+                sscanf(buf, "Cached: %lu", &cached);
+
+                // add to "MemFree" also the "Buffers" and "Cached" values as
+                // free(1) does as otherwise the value never makes sense: for
+                // kernel 2.6 it's always almost 0
+                memFree += buffers + cached;
+
+                // values here are always expressed in kB and we want bytes
+                memFree *= 1024;
+            }
+            else // Linux 2.4 (or < 2.6, anyhow)
+            {
+                long memTotal, memUsed;
+                sscanf(buf, "Mem: %ld %ld %ld", &memTotal, &memUsed, &memFree);
+            }
         }
 
         fclose(fp);