diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-23 05:08:10 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-23 05:08:10 +0000 |
commit | 472156c236c0b086bde6b26703f2f02d1be5f730 (patch) | |
tree | 32dffdae92cb0c9ba724c7786087b6232baa0e72 | |
parent | a5ea0e8c3209343063ff5943b76e8243edaa7914 (diff) | |
download | ruby-472156c236c0b086bde6b26703f2f02d1be5f730.tar.gz |
* ext/socket/socket.c (sock_s_getservbyname): unuse unnecessary
object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ext/socket/socket.c | 14 |
2 files changed, 11 insertions, 8 deletions
@@ -1,4 +1,7 @@ -Thu Oct 23 11:17:58 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> +Thu Oct 23 14:08:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/socket/socket.c (sock_s_getservbyname): unuse unnecessary + object. * ext/socket/socket.c (sock_s_getservbyport): the port should be converted before the proto so that the #to_int of the former cannot diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 5788632f8a..a47c6d47df 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -3222,23 +3222,23 @@ sock_s_getservbyname(int argc, VALUE *argv) VALUE service, proto; struct servent *sp; int port; + const char *servicename, *protoname = "tcp"; rb_scan_args(argc, argv, "11", &service, &proto); - if (NIL_P(proto)) proto = rb_str_new2("tcp"); StringValue(service); - StringValue(proto); - - sp = getservbyname(StringValueCStr(service), StringValueCStr(proto)); + if (!NIL_P(proto)) StringValue(proto); + servicename = StringValueCStr(service); + if (!NIL_P(proto)) protoname = StringValueCStr(proto); + sp = getservbyname(servicename, protoname); if (sp) { port = ntohs(sp->s_port); } else { - char *s = RSTRING_PTR(service); char *end; - port = STRTOUL(s, &end, 0); + port = STRTOUL(servicename, &end, 0); if (*end != '\0') { - rb_raise(rb_eSocket, "no such service %s/%s", s, RSTRING_PTR(proto)); + rb_raise(rb_eSocket, "no such service %s/%s", servicename, protoname); } } return INT2FIX(port); |