X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ab857a4ed6687929e308ea606f65ceedc43d1319..9b1801c19c82340be79810c8b7617b05caa0cd59:/src/unix/utilsunx.cpp diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index c8bdafd3bf..3b09340bec 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -23,8 +23,11 @@ #include "wx/utils.h" #include "wx/process.h" +#include "wx/thread.h" -#include "wx/unix/execute.h" +#if wxUSE_GUI + #include "wx/unix/execute.h" +#endif #include #include @@ -40,9 +43,7 @@ #include // for O_WRONLY and friends #include // nanosleep() and/or usleep() #include // isspace() - -// JACS: needed for FD_SETSIZE -#include +#include // needed for FD_SETSIZE #ifdef HAVE_UNAME #include // for uname() @@ -64,20 +65,21 @@ #ifdef __SUN__ int usleep(unsigned int usec); #else // !Sun - #ifdef __EMX__ - /* I copied this from the XFree86 diffs. AV. */ - #define INCL_DOSPROCESS - #include - void usleep(unsigned long delay) - { - DosSleep(delay ? (delay/1000l) : 1l); - } - #else - void usleep(unsigned long usec); - #endif + #ifdef __EMX__ + /* I copied this from the XFree86 diffs. AV. */ + #define INCL_DOSPROCESS + #include + 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 }; -#define HAVE_USLEEP 1 + + #define HAVE_USLEEP 1 #endif // Unices without usleep() // ============================================================================ @@ -95,14 +97,14 @@ void wxSleep(int nSecs) void wxUsleep(unsigned long milliseconds) { -#ifdef HAVE_NANOSLEEP +#if defined(HAVE_NANOSLEEP) timespec tmReq; - tmReq.tv_sec = milliseconds / 1000; + tmReq.tv_sec = (time_t)(milliseconds / 1000); tmReq.tv_nsec = (milliseconds % 1000) * 1000 * 1000; // we're not interested in remaining time nor in return value (void)nanosleep(&tmReq, (timespec *)NULL); -#elif defined( HAVE_USLEEP ) +#elif defined(HAVE_USLEEP) // uncomment this if you feel brave or if you are sure that your version // of Solaris has a safe usleep() function but please notice that usleep() // is known to lead to crashes in MT programs in Solaris 2.[67] and is not @@ -112,6 +114,9 @@ void wxUsleep(unsigned long milliseconds) #endif // Sun usleep(milliseconds * 1000); // usleep(3) wants microseconds +#elif defined(HAVE_SLEEP) + // under BeOS sleep() takes seconds (what about other platforms, if any?) + sleep(milliseconds * 1000); #else // !sleep function #error "usleep() or nanosleep() function required for wxUsleep" #endif // sleep function @@ -123,7 +128,7 @@ void wxUsleep(unsigned long milliseconds) int wxKill(long pid, wxSignal sig) { - return kill(pid, (int)sig); + return kill((pid_t)pid, (int)sig); } #define WXEXECUTE_NARGS 127 @@ -209,6 +214,8 @@ bool wxShell(const wxString& command) return wxExecute(cmd) != 0; } +#if wxUSE_GUI + void wxHandleProcessTermination(wxEndProcessData *proc_data) { int pid = (proc_data->pid > 0) ? proc_data->pid : -(proc_data->pid); @@ -219,17 +226,19 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data) int status = 0; int rc; + // wait for child termination and if waitpid() was interrupted, try again do + { rc = waitpid(pid, &status, 0); - while(rc == -1 && ( /* errno == ERESTARTSYS || */ errno == EINTR) ); - // waitpid() was interrupted, try again + } + while ( rc == -1 && errno == EINTR ); + - if( rc == -1 || ! (WIFEXITED(status) || WIFSIGNALED(status)) ) { wxLogSysError(_("Waiting for subprocess termination failed")); /* AFAIK, this can only happen if something went wrong within - wxGTK, i.e. due to a racecondition or some serious bug. + wxGTK, i.e. due to a race condition or some serious bug. After having fixed the order of statements in GTK_EndProcessDetector(). (KB) */ @@ -251,13 +260,23 @@ void wxHandleProcessTermination(wxEndProcessData *proc_data) { // wxExecute() will know about it proc_data->exitcode = status; - + proc_data->pid = 0; } } } -long wxExecute( wxChar **argv, bool sync, wxProcess *process ) +#endif // wxUSE_GUI + +#if wxUSE_GUI + #define WXUNUSED_UNLESS_GUI(p) p +#else + #define WXUNUSED_UNLESS_GUI(p) +#endif + +long wxExecute(wxChar **argv, + bool sync, + wxProcess * WXUNUSED_UNLESS_GUI(process)) { wxCHECK_MSG( *argv, 0, wxT("can't exec empty command") ); @@ -359,7 +378,6 @@ long wxExecute( wxChar **argv, bool sync, wxProcess *process ) #if wxUSE_GUI wxEndProcessData *data = new wxEndProcessData; - ARGS_CLEANUP; if ( sync ) @@ -562,24 +580,34 @@ bool wxGetUserId(wxChar *buf, int sz) bool wxGetUserName(wxChar *buf, int sz) { struct passwd *who; - char *comma; *buf = wxT('\0'); - if ((who = getpwuid (getuid ())) != NULL) { -#ifndef __VMS__ - comma = strchr(who->pw_gecos, ','); + if ((who = getpwuid (getuid ())) != NULL) + { + // pw_gecos field in struct passwd is not standard +#if HAVE_PW_GECOS + char *comma = strchr(who->pw_gecos, ','); if (comma) *comma = '\0'; // cut off non-name comment fields wxStrncpy (buf, wxConvertMB2WX(who->pw_gecos), sz - 1); -#else +#else // !HAVE_PW_GECOS wxStrncpy (buf, wxConvertMB2WX(who->pw_name), sz - 1); -#endif +#endif // HAVE_PW_GECOS/!HAVE_PW_GECOS return TRUE; } return FALSE; } +wxString wxGetOsDescription() +{ +#ifndef WXWIN_OS_DESCRIPTION + #error WXWIN_OS_DESCRIPTION should be defined in config.h by configure +#else + return WXWIN_OS_DESCRIPTION; +#endif +} + // ---------------------------------------------------------------------------- // error and debug output routines (deprecated, use wxLog) // ----------------------------------------------------------------------------