+ return wxString::FromAscii( WXWIN_OS_DESCRIPTION );
+#endif
+}
+#endif
+
+// this function returns the GUI toolkit version in GUI programs, but OS
+// version in non-GUI ones
+#if !wxUSE_GUI
+
+int wxGetOsVersion(int *majorVsn, int *minorVsn)
+{
+ int major, minor;
+ char name[256];
+
+ if ( sscanf(WXWIN_OS_DESCRIPTION, "%s %d.%d", name, &major, &minor) != 3 )
+ {
+ // unreckognized uname string format
+ major = minor = -1;
+ }
+
+ if ( majorVsn )
+ *majorVsn = major;
+ if ( minorVsn )
+ *minorVsn = minor;
+
+ return wxUNIX;
+}
+
+#endif // !wxUSE_GUI
+
+unsigned long wxGetProcessId()
+{
+ return (unsigned long)getpid();
+}
+
+long wxGetFreeMemory()
+{
+#if defined(__LINUX__)
+ // get it from /proc/meminfo
+ FILE *fp = fopen("/proc/meminfo", "r");
+ if ( fp )
+ {
+ long memFree = -1;
+
+ 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);
+ }
+
+ fclose(fp);
+
+ return memFree;
+ }
+#elif defined(__SUN__) && defined(_SC_AVPHYS_PAGES)
+ return sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+//#elif defined(__FREEBSD__) -- might use sysctl() to find it out, probably
+#endif
+
+ // can't find it out
+ return -1;
+}
+
+bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
+{
+#if defined(HAVE_STATFS) || defined(HAVE_STATVFS)
+ // the case to "char *" is needed for AIX 4.3
+ wxStatfs_t fs;
+ if ( wxStatfs((char *)(const char*)path.fn_str(), &fs) != 0 )
+ {
+ wxLogSysError( wxT("Failed to get file system statistics") );
+
+ return FALSE;
+ }
+
+ // under Solaris we also have to use f_frsize field instead of f_bsize
+ // which is in general a multiple of f_frsize
+#ifdef HAVE_STATVFS
+ wxLongLong blockSize = fs.f_frsize;
+#else // HAVE_STATFS
+ wxLongLong blockSize = fs.f_bsize;
+#endif // HAVE_STATVFS/HAVE_STATFS
+
+ if ( pTotal )
+ {
+ *pTotal = wxLongLong(fs.f_blocks) * blockSize;
+ }
+
+ if ( pFree )
+ {
+ *pFree = wxLongLong(fs.f_bavail) * blockSize;
+ }
+
+ return TRUE;
+#else // !HAVE_STATFS && !HAVE_STATVFS
+ return FALSE;
+#endif // HAVE_STATFS
+}
+
+// ----------------------------------------------------------------------------
+// env vars
+// ----------------------------------------------------------------------------
+
+bool wxGetEnv(const wxString& var, wxString *value)
+{
+ // wxGetenv is defined as getenv()
+ wxChar *p = wxGetenv(var);
+ if ( !p )
+ return FALSE;
+
+ if ( value )
+ {
+ *value = p;
+ }
+
+ return TRUE;
+}
+
+bool wxSetEnv(const wxString& variable, const wxChar *value)
+{
+#if defined(HAVE_SETENV)
+ return setenv(variable.mb_str(),
+ value ? (const char *)wxString(value).mb_str()
+ : NULL,
+ 1 /* overwrite */) == 0;
+#elif defined(HAVE_PUTENV)
+ wxString s = variable;
+ if ( value )
+ s << _T('=') << value;
+
+ // transform to ANSI
+ const char *p = s.mb_str();
+
+ // the string will be free()d by libc
+ char *buf = (char *)malloc(strlen(p) + 1);
+ strcpy(buf, p);
+
+ return putenv(buf) == 0;
+#else // no way to set an env var
+ return FALSE;