diff options
author | jsing <> | 2014-07-08 09:06:49 +0000 |
---|---|---|
committer | jsing <> | 2014-07-08 09:06:49 +0000 |
commit | 36b38bdfeadea1b46b8ee76c2207d4a46c1a626b (patch) | |
tree | e5d9d78ff96270185a639cdfd478e33c81860bb1 /src | |
parent | 797b1803e50d563fc36daa7a32d7fac6551c1019 (diff) | |
download | openbsd-36b38bdfeadea1b46b8ee76c2207d4a46c1a626b.tar.gz openbsd-36b38bdfeadea1b46b8ee76c2207d4a46c1a626b.tar.bz2 openbsd-36b38bdfeadea1b46b8ee76c2207d4a46c1a626b.zip |
Simplify various BIO_sock_* fuctions - less code, better variable names,
correct types and fewer casts.
ok deraadt@ miod@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 39 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bio/b_sock.c | 39 |
2 files changed, 24 insertions, 54 deletions
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 @@ | |||
1 | /* $OpenBSD: b_sock.c,v 1.43 2014/06/24 17:42:54 jsing Exp $ */ | 1 | /* $OpenBSD: b_sock.c,v 1.44 2014/07/08 09:06:49 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -173,20 +173,13 @@ BIO_get_port(const char *str, unsigned short *port_ptr) | |||
173 | int | 173 | int |
174 | BIO_sock_error(int sock) | 174 | BIO_sock_error(int sock) |
175 | { | 175 | { |
176 | int j, i; | 176 | socklen_t len; |
177 | int size; | 177 | int err; |
178 | 178 | ||
179 | size = sizeof(int); | 179 | len = sizeof(err); |
180 | /* Note: under Windows the third parameter is of type (char *) | 180 | if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) != 0) |
181 | * whereas under other systems it is (void *) if you don't have | ||
182 | * a cast it will choke the compiler: if you do have a cast then | ||
183 | * you can either go for (char *) or (void *). | ||
184 | */ | ||
185 | i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, (void *)&size); | ||
186 | if (i < 0) | ||
187 | return (1); | 181 | return (1); |
188 | else | 182 | return (err); |
189 | return (j); | ||
190 | } | 183 | } |
191 | 184 | ||
192 | struct hostent * | 185 | struct hostent * |
@@ -209,14 +202,12 @@ BIO_sock_cleanup(void) | |||
209 | int | 202 | int |
210 | BIO_socket_ioctl(int fd, long type, void *arg) | 203 | BIO_socket_ioctl(int fd, long type, void *arg) |
211 | { | 204 | { |
212 | int i; | 205 | int ret; |
213 | |||
214 | # define ARG arg | ||
215 | 206 | ||
216 | i = ioctl(fd, type, ARG); | 207 | ret = ioctl(fd, type, arg); |
217 | if (i < 0) | 208 | if (ret < 0) |
218 | SYSerr(SYS_F_IOCTLSOCKET, errno); | 209 | SYSerr(SYS_F_IOCTLSOCKET, errno); |
219 | return (i); | 210 | return (ret); |
220 | } | 211 | } |
221 | 212 | ||
222 | int | 213 | int |
@@ -471,11 +462,5 @@ BIO_set_tcp_ndelay(int s, int on) | |||
471 | int | 462 | int |
472 | BIO_socket_nbio(int s, int mode) | 463 | BIO_socket_nbio(int s, int mode) |
473 | { | 464 | { |
474 | int ret = -1; | 465 | return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); |
475 | int l; | ||
476 | |||
477 | l = mode; | ||
478 | ret = BIO_socket_ioctl(s, FIONBIO, &l); | ||
479 | |||
480 | return (ret == 0); | ||
481 | } | 466 | } |
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 @@ | |||
1 | /* $OpenBSD: b_sock.c,v 1.43 2014/06/24 17:42:54 jsing Exp $ */ | 1 | /* $OpenBSD: b_sock.c,v 1.44 2014/07/08 09:06:49 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -173,20 +173,13 @@ BIO_get_port(const char *str, unsigned short *port_ptr) | |||
173 | int | 173 | int |
174 | BIO_sock_error(int sock) | 174 | BIO_sock_error(int sock) |
175 | { | 175 | { |
176 | int j, i; | 176 | socklen_t len; |
177 | int size; | 177 | int err; |
178 | 178 | ||
179 | size = sizeof(int); | 179 | len = sizeof(err); |
180 | /* Note: under Windows the third parameter is of type (char *) | 180 | if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) != 0) |
181 | * whereas under other systems it is (void *) if you don't have | ||
182 | * a cast it will choke the compiler: if you do have a cast then | ||
183 | * you can either go for (char *) or (void *). | ||
184 | */ | ||
185 | i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, (void *)&size); | ||
186 | if (i < 0) | ||
187 | return (1); | 181 | return (1); |
188 | else | 182 | return (err); |
189 | return (j); | ||
190 | } | 183 | } |
191 | 184 | ||
192 | struct hostent * | 185 | struct hostent * |
@@ -209,14 +202,12 @@ BIO_sock_cleanup(void) | |||
209 | int | 202 | int |
210 | BIO_socket_ioctl(int fd, long type, void *arg) | 203 | BIO_socket_ioctl(int fd, long type, void *arg) |
211 | { | 204 | { |
212 | int i; | 205 | int ret; |
213 | |||
214 | # define ARG arg | ||
215 | 206 | ||
216 | i = ioctl(fd, type, ARG); | 207 | ret = ioctl(fd, type, arg); |
217 | if (i < 0) | 208 | if (ret < 0) |
218 | SYSerr(SYS_F_IOCTLSOCKET, errno); | 209 | SYSerr(SYS_F_IOCTLSOCKET, errno); |
219 | return (i); | 210 | return (ret); |
220 | } | 211 | } |
221 | 212 | ||
222 | int | 213 | int |
@@ -471,11 +462,5 @@ BIO_set_tcp_ndelay(int s, int on) | |||
471 | int | 462 | int |
472 | BIO_socket_nbio(int s, int mode) | 463 | BIO_socket_nbio(int s, int mode) |
473 | { | 464 | { |
474 | int ret = -1; | 465 | return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); |
475 | int l; | ||
476 | |||
477 | l = mode; | ||
478 | ret = BIO_socket_ioctl(s, FIONBIO, &l); | ||
479 | |||
480 | return (ret == 0); | ||
481 | } | 466 | } |