X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7bcb11d30764df47144189e164f53d8171ed4a63..ea18eed94c637bee3343b929e09cae78a1b80928:/src/unix/utilsunx.cpp diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 9a213ff4c0..f7b9b01140 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -96,7 +96,7 @@ void wxUsleep(unsigned long milliseconds) // 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 // documented as MT-Safe - #if defined(__SUN__) && defined(wxUSE_THREADS) + #if defined(__SUN__) && wxUSE_THREADS #error "usleep() cannot be used in MT programs under Solaris." #endif // Sun @@ -110,9 +110,9 @@ void wxUsleep(unsigned long milliseconds) // process management // ---------------------------------------------------------------------------- -int wxKill(long pid, int sig) +int wxKill(long pid, wxSignal sig) { - return kill(pid, sig); + return kill(pid, (int)sig); } #define WXEXECUTE_NARGS 127 @@ -265,7 +265,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process ) // These three lines close the open file descriptors to to avoid any // input/output which might block the process or irritate the user. If - // one wants proper IO for the subprocess, the "right thing to do is + // one wants proper IO for the subprocess, the right thing to do is // to start an xterm executing it. if (sync == 0) { @@ -350,7 +350,7 @@ char *wxGetUserHome( const wxString &user ) { struct passwd *who = (struct passwd *) NULL; - if (user.IsNull() || (user== "")) + if ( !user ) { register char *ptr; @@ -378,12 +378,15 @@ char *wxGetUserHome( const wxString &user ) } // ---------------------------------------------------------------------------- -// id routines +// network and user id routines // ---------------------------------------------------------------------------- -bool wxGetHostName(char *buf, int sz) +// retrieve either the hostname or FQDN depending on platform (caller must +// check whether it's one or the other, this is why this function is for +// private use only) +static bool wxGetHostNameInternal(char *buf, int sz) { - wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostName" ); + wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostNameInternal" ); *buf = '\0'; @@ -398,11 +401,11 @@ bool wxGetHostName(char *buf, int sz) } #elif defined(HAVE_GETHOSTNAME) bool ok = gethostname(buf, sz) != -1; -#else +#else // no uname, no gethostname wxFAIL_MSG("don't know host name for this machibe"); bool ok = FALSE; -#endif +#endif // uname/gethostname if ( !ok ) { @@ -412,6 +415,52 @@ bool wxGetHostName(char *buf, int sz) return ok; } +bool wxGetHostName(char *buf, int sz) +{ + bool ok = wxGetHostNameInternal(buf, sz); + + if ( ok ) + { + // BSD systems return the FQDN, we only want the hostname, so extract + // it (we consider that dots are domain separators) + char *dot = strchr(buf, '.'); + if ( dot ) + { + // nuke it + *dot = '\0'; + } + } + + return ok; +} + +bool wxGetFullHostName(char *buf, int sz) +{ + bool ok = wxGetHostNameInternal(buf, sz); + + if ( ok ) + { + if ( !strchr(buf, '.') ) + { + struct hostent *host = gethostbyname(buf); + if ( !host ) + { + wxLogSysError(_("Cannot get the official hostname")); + + ok = FALSE; + } + else + { + // the canonical name + strncpy(buf, host->h_name, sz); + } + } + //else: it's already a FQDN (BSD behaves this way) + } + + return ok; +} + bool wxGetUserId(char *buf, int sz) { struct passwd *who; @@ -473,14 +522,3 @@ void wxFatalError( const wxString &msg, const wxString &title ) exit(3); // the same exit code as for abort() } -//------------------------------------------------------------------------ -// directory routines -//------------------------------------------------------------------------ - -bool wxDirExists( const wxString& dir ) -{ - char buf[500]; - strcpy( buf, WXSTRINGCAST(dir) ); - struct stat sbuf; - return ((stat(buf, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE); -}