socket.c: unlimited size hostname
* ext/socket/socket.c (sock_gethostname): support unlimited size hostname. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c308fa680f
commit
173e287ff9
@ -1,3 +1,8 @@
|
|||||||
|
Thu Jan 28 17:31:43 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/socket/socket.c (sock_gethostname): support unlimited size
|
||||||
|
hostname.
|
||||||
|
|
||||||
Wed Jan 27 21:03:45 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
|
Wed Jan 27 21:03:45 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
|
||||||
|
|
||||||
* test/-ext-/string/test_capacity.rb: Added missing library.
|
* test/-ext-/string/test_capacity.rb: Added missing library.
|
||||||
|
@ -893,13 +893,27 @@ sock_gethostname(VALUE obj)
|
|||||||
# define RUBY_MAX_HOST_NAME_LEN 1024
|
# define RUBY_MAX_HOST_NAME_LEN 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char buf[RUBY_MAX_HOST_NAME_LEN+1];
|
long len = RUBY_MAX_HOST_NAME_LEN;
|
||||||
|
VALUE name;
|
||||||
|
|
||||||
if (gethostname(buf, (int)sizeof buf - 1) < 0)
|
name = rb_str_new(0, len);
|
||||||
rb_sys_fail("gethostname(3)");
|
while (gethostname(RSTRING_PTR(name), len) < 0) {
|
||||||
|
int e = errno;
|
||||||
buf[sizeof buf - 1] = '\0';
|
switch (e) {
|
||||||
return rb_str_new2(buf);
|
case ENAMETOOLONG:
|
||||||
|
#ifdef __linux__
|
||||||
|
case EINVAL:
|
||||||
|
/* glibc before version 2.1 uses EINVAL instead of ENAMETOOLONG */
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rb_syserr_fail(e, "gethostname(3)");
|
||||||
|
}
|
||||||
|
rb_str_modify_expand(name, len);
|
||||||
|
len += len;
|
||||||
|
}
|
||||||
|
rb_str_resize(name, strlen(RSTRING_PTR(name)));
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef HAVE_UNAME
|
#ifdef HAVE_UNAME
|
||||||
|
Loading…
x
Reference in New Issue
Block a user