summaryrefslogtreecommitdiffstats
path: root/lib/libc/net
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2005-11-15 19:35:31 +0000
committerotto <otto@openbsd.org>2005-11-15 19:35:31 +0000
commitf8d15a223f9d9e38e91b06c288f507a98e7bd9e4 (patch)
treed310d93eee8b00360b757f6506fa3ca7e7aaf077 /lib/libc/net
parentadd IFQ_SET_MAXLEN(). (diff)
downloadwireguard-openbsd-f8d15a223f9d9e38e91b06c288f507a98e7bd9e4.tar.xz
wireguard-openbsd-f8d15a223f9d9e38e91b06c288f507a98e7bd9e4.zip
Do not clobber errno when calling close(2) in example code.
From form@ via mpech@
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/getaddrinfo.38
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3
index b7494be811c..12a0d8ce12b 100644
--- a/lib/libc/net/getaddrinfo.3
+++ b/lib/libc/net/getaddrinfo.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: getaddrinfo.3,v 1.42 2005/11/13 13:22:57 otto Exp $
+.\" $OpenBSD: getaddrinfo.3,v 1.43 2005/11/15 19:35:31 otto Exp $
.\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $
.\"
.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
@@ -304,7 +304,7 @@ returns addresses that are not IPv4/v6.
.Bd -literal -offset indent
struct addrinfo hints, *res, *res0;
int error;
-int save_errno = errno;
+int save_errno;
int s;
const char *cause = NULL;
@@ -327,6 +327,7 @@ for (res = res0; res; res = res->ai_next) {
if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
cause = "connect";
+ save_errno = errno;
close(s);
errno = save_errno;
s = -1;
@@ -348,6 +349,7 @@ for all the address families available.
.Bd -literal -offset indent
struct addrinfo hints, *res, *res0;
int error;
+int save_errno;
int s[MAXSOCK];
int nsock;
const char *cause = NULL;
@@ -372,7 +374,9 @@ for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) {
if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0) {
cause = "bind";
+ save_errno = errno;
close(s[nsock]);
+ errno = save_errno;
continue;
}
(void) listen(s[nsock], 5);