]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/utilsunx.cpp
unitialized var initialized (mainly to reduce Purify warnings)
[wxWidgets.git] / src / unix / utilsunx.cpp
index 9e8865a5ecb9a790d5f9914b6dd951712bc82522..e2696eee7b45697625cc4fa1057230149b2a1c07 100644 (file)
 #include <time.h>           // nanosleep() and/or usleep()
 #include <ctype.h>          // isspace()
 
-#ifdef HAVE_UNAME
+// JACS: needed for FD_SETSIZE
+#include <sys/time.h>
+
+#if HAVE_UNAME
     #include <sys/utsname.h> // for uname()
 #endif // HAVE_UNAME
 
@@ -81,14 +84,14 @@ void wxSleep(int nSecs)
 
 void wxUsleep(unsigned long milliseconds)
 {
-#if defined(HAVE_NANOSLEEP)
+#if HAVE_NANOSLEEP
     timespec tmReq;
     tmReq.tv_sec = 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 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
@@ -107,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
@@ -262,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)
         {
@@ -347,7 +350,7 @@ char *wxGetUserHome( const wxString &user )
 {
     struct passwd *who = (struct passwd *) NULL;
 
-    if (user.IsNull() || (user== ""))
+    if ( !user )
     {
         register char *ptr;
 
@@ -375,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';
 
@@ -395,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 )
     {
@@ -409,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;
@@ -470,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);
-}