From 36b38bdfeadea1b46b8ee76c2207d4a46c1a626b Mon Sep 17 00:00:00 2001 From: jsing <> Date: Tue, 8 Jul 2014 09:06:49 +0000 Subject: Simplify various BIO_sock_* fuctions - less code, better variable names, correct types and fewer casts. ok deraadt@ miod@ --- src/lib/libcrypto/bio/b_sock.c | 39 +++++++++++----------------------- src/lib/libssl/src/crypto/bio/b_sock.c | 39 +++++++++++----------------------- 2 files changed, 24 insertions(+), 54 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index 5f8b1e052f..447f0febce 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_sock.c,v 1.43 2014/06/24 17:42:54 jsing Exp $ */ +/* $OpenBSD: b_sock.c,v 1.44 2014/07/08 09:06:49 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -173,20 +173,13 @@ BIO_get_port(const char *str, unsigned short *port_ptr) int BIO_sock_error(int sock) { - int j, i; - int size; - - size = sizeof(int); - /* Note: under Windows the third parameter is of type (char *) - * whereas under other systems it is (void *) if you don't have - * a cast it will choke the compiler: if you do have a cast then - * you can either go for (char *) or (void *). - */ - i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, (void *)&size); - if (i < 0) + socklen_t len; + int err; + + len = sizeof(err); + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) != 0) return (1); - else - return (j); + return (err); } struct hostent * @@ -209,14 +202,12 @@ BIO_sock_cleanup(void) int BIO_socket_ioctl(int fd, long type, void *arg) { - int i; - -# define ARG arg + int ret; - i = ioctl(fd, type, ARG); - if (i < 0) + ret = ioctl(fd, type, arg); + if (ret < 0) SYSerr(SYS_F_IOCTLSOCKET, errno); - return (i); + return (ret); } int @@ -471,11 +462,5 @@ BIO_set_tcp_ndelay(int s, int on) int BIO_socket_nbio(int s, int mode) { - int ret = -1; - int l; - - l = mode; - ret = BIO_socket_ioctl(s, FIONBIO, &l); - - return (ret == 0); + return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); } diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c index 5f8b1e052f..447f0febce 100644 --- a/src/lib/libssl/src/crypto/bio/b_sock.c +++ b/src/lib/libssl/src/crypto/bio/b_sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_sock.c,v 1.43 2014/06/24 17:42:54 jsing Exp $ */ +/* $OpenBSD: b_sock.c,v 1.44 2014/07/08 09:06:49 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -173,20 +173,13 @@ BIO_get_port(const char *str, unsigned short *port_ptr) int BIO_sock_error(int sock) { - int j, i; - int size; - - size = sizeof(int); - /* Note: under Windows the third parameter is of type (char *) - * whereas under other systems it is (void *) if you don't have - * a cast it will choke the compiler: if you do have a cast then - * you can either go for (char *) or (void *). - */ - i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, (void *)&size); - if (i < 0) + socklen_t len; + int err; + + len = sizeof(err); + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) != 0) return (1); - else - return (j); + return (err); } struct hostent * @@ -209,14 +202,12 @@ BIO_sock_cleanup(void) int BIO_socket_ioctl(int fd, long type, void *arg) { - int i; - -# define ARG arg + int ret; - i = ioctl(fd, type, ARG); - if (i < 0) + ret = ioctl(fd, type, arg); + if (ret < 0) SYSerr(SYS_F_IOCTLSOCKET, errno); - return (i); + return (ret); } int @@ -471,11 +462,5 @@ BIO_set_tcp_ndelay(int s, int on) int BIO_socket_nbio(int s, int mode) { - int ret = -1; - int l; - - l = mode; - ret = BIO_socket_ioctl(s, FIONBIO, &l); - - return (ret == 0); + return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); } -- cgit v1.2.3-55-g6feb