]> gcc.gnu.org Git - gcc.git/commitdiff
natVMInetAddressPosix.cc (java::net::VMInetAddress::getLocalHostname): Allocate buffe...
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 8 Aug 2007 22:24:40 +0000 (22:24 +0000)
committerMatthias Klose <doko@gcc.gnu.org>
Wed, 8 Aug 2007 22:24:40 +0000 (22:24 +0000)
2007-08-08  Samuel Thibault  <samuel.thibault@ens-lyon.org>

        * java/net/natVMInetAddressPosix.cc
        (java::net::VMInetAddress::getLocalHostname) [!MAXHOSTNAMELEN]:
        Allocate buffer dynamically.

From-SVN: r127305

libjava/ChangeLog
libjava/java/net/natVMInetAddressPosix.cc

index e9dbb5fb3bb27869d8e8c876ec639662052427c7..cbec57f311e606ec871a1e6032e336cd66e09507 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-08  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+       * java/net/natVMInetAddressPosix.cc
+       (java::net::VMInetAddress::getLocalHostname) [!MAXHOSTNAMELEN]:
+       Allocate buffer dynamically.
+
 2007-08-04  Alfred M. Szmidt  <ams@gnu.org>
 
        * java/io/natFilePosix.cc (init_native) [!MAXPATHLEN]: Define to 0.
index 7fbe1bb1ff0a220672ddc0098ae45ef7b6708c6d..bc25f3654aa0abb86ad828061441540165670b77 100644 (file)
@@ -47,10 +47,25 @@ java::net::VMInetAddress::getLocalHostname ()
 {
   char *chars;
 #ifdef HAVE_GETHOSTNAME
+#ifdef MAXHOSTNAMELEN
   char buffer[MAXHOSTNAMELEN];
   if (gethostname (buffer, MAXHOSTNAMELEN))
     return NULL;
   chars = buffer;
+#else
+  size_t size = 256;
+  while (1) {
+    char buffer[size];
+    if (!gethostname (buffer, size-1))
+      {
+       buffer[size-1] = 0;
+       return JvNewStringUTF (buffer);
+      }
+    else if (errno != ENAMETOOLONG)
+      return NULL;
+    size *= 2;
+  }
+#endif
 #elif HAVE_UNAME
   struct utsname stuff;
   if (uname (&stuff) != 0)
This page took 0.05586 seconds and 5 git commands to generate.