diff options
author | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-08-08 22:24:40 +0000 |
---|---|---|
committer | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-08-08 22:24:40 +0000 |
commit | e0f06026a6ee5b85d0ca68e3061b92b98a53eb79 (patch) | |
tree | 3cf3732c466af176042003f31da6d1214c6a73c6 /libjava/java | |
parent | 7cfb6ab663e521a57c6fe684b28c4b84bb263175 (diff) | |
download | gcc-e0f06026a6ee5b85d0ca68e3061b92b98a53eb79.tar.gz |
2007-08-08 Samuel Thibault <samuel.thibault@ens-lyon.org>
* java/net/natVMInetAddressPosix.cc
(java::net::VMInetAddress::getLocalHostname) [!MAXHOSTNAMELEN]:
Allocate buffer dynamically.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127305 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/net/natVMInetAddressPosix.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libjava/java/net/natVMInetAddressPosix.cc b/libjava/java/net/natVMInetAddressPosix.cc index 7fbe1bb1ff0..bc25f3654aa 100644 --- a/libjava/java/net/natVMInetAddressPosix.cc +++ b/libjava/java/net/natVMInetAddressPosix.cc @@ -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) |