]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/utilsunx.cpp
Fixed a confusion between window and client size that could lead to
[wxWidgets.git] / src / unix / utilsunx.cpp
index d14a33a5e6d73ac877a52dc06ef16b086889b368..c64721bafbd705b14368ae01e27ccc816f7b92ff 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
@@ -266,7 +262,8 @@ long wxMacExecute(wxChar **argv,
 long wxExecute( const wxString& command, int flags, wxProcess *process )
 {
     wxCHECK_MSG( !command.empty(), 0, wxT("can't exec empty command") );
-    wxLogDebug(wxString(wxT("Launching: ")) + command);
+
+    wxLogTrace(wxT("exec"), wxT("Executing \"%s\""), command.c_str());
 
 #if wxUSE_THREADS
     // fork() doesn't mix well with POSIX threads: on many systems the program
@@ -794,7 +791,13 @@ static bool wxGetHostNameInternal(wxChar *buf, int sz)
         buf[sz] = wxT('\0');
     }
 #elif defined(HAVE_GETHOSTNAME)
-    bool ok = gethostname(buf, sz) != -1;
+    char cbuf[sz];
+    bool ok = gethostname(cbuf, sz) != -1;
+    if ( ok )
+    {
+        wxStrncpy(buf, wxConvertMB2WX(cbuf), sz - 1);
+        buf[sz] = wxT('\0');
+    }
 #else // no uname, no gethostname
     wxFAIL_MSG(wxT("don't know host name for this machine"));
 
@@ -891,12 +894,29 @@ bool wxGetUserName(wxChar *buf, int sz)
     return false;
 }
 
+bool wxIsPlatform64Bit()
+{
+    wxString machine = wxGetCommandOutput(wxT("uname -m"));
+
+    // NOTE: these tests are not 100% reliable!
+    return machine.Contains(wxT("AMD64")) ||
+           machine.Contains(wxT("IA64")) ||
+           machine.Contains(wxT("x64")) ||
+           machine.Contains(wxT("X64")) ||
+           machine.Contains(wxT("alpha")) ||
+           machine.Contains(wxT("hppa64")) ||
+           machine.Contains(wxT("ppc64"));
+}
+
+// these functions are in mac/utils.cpp for wxMac
+#ifndef __WXMAC__
+
 wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
 {
     // get OS version
     int major, minor;
     wxString release = wxGetCommandOutput(wxT("uname -r"));
-    if ( !release.empty() && wxSscanf(release, "%d.%d", &major, &minor) != 2 )
+    if ( !release.empty() && wxSscanf(release, wxT("%d.%d"), &major, &minor) != 2 )
     {
         // unrecognized uname string format
         major =
@@ -919,23 +939,6 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
     return wxPlatformInfo::GetOperatingSystemId(kernel);
 }
 
-bool wxIsPlatform64Bit()
-{
-    wxString machine = wxGetCommandOutput(wxT("uname -m"));
-
-    // NOTE: these tests are not 100% reliable!
-    return machine.Contains(wxT("AMD64")) ||
-           machine.Contains(wxT("IA64")) ||
-           machine.Contains(wxT("x64")) ||
-           machine.Contains(wxT("X64")) ||
-           machine.Contains(wxT("alpha")) ||
-           machine.Contains(wxT("hppa64")) ||
-           machine.Contains(wxT("ppc64"));
-}
-
-// this function is in mac/utils.cpp for wxMac
-#ifndef __WXMAC__
-
 wxString wxGetOsDescription()
 {
     return wxGetCommandOutput(wxT("uname -s -r -m"));
@@ -960,8 +963,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);