aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/ipc.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-02-17 19:39:26 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-02-17 20:15:49 +0100
commitb0257234608d765c92530d73b096d5a83dbc40d8 (patch)
tree107d3fed3908c61d15f86a0d704fcdd097388a98 /src/tools/ipc.c
parenttools: FreeBSD doesn't have EAI_NODATA (diff)
downloadwireguard-monolithic-historical-b0257234608d765c92530d73b096d5a83dbc40d8.tar.xz
wireguard-monolithic-historical-b0257234608d765c92530d73b096d5a83dbc40d8.zip
tools: fixup errno handling
Diffstat (limited to 'src/tools/ipc.c')
-rw-r--r--src/tools/ipc.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/tools/ipc.c b/src/tools/ipc.c
index edc8e8f..3f23d1d 100644
--- a/src/tools/ipc.c
+++ b/src/tools/ipc.c
@@ -48,7 +48,6 @@
#define SOCKET_BUFFER_SIZE 8192
#endif
-
struct inflatable_buffer {
char *buffer;
char *next;
@@ -57,6 +56,7 @@ struct inflatable_buffer {
size_t pos;
};
+#define max(a, b) ((a) > (b) ? (a) : (b))
static int add_next_to_inflatable_buffer(struct inflatable_buffer *buffer)
{
size_t len, expand_to;
@@ -111,7 +111,7 @@ static FILE *userspace_interface_file(const char *interface)
int fd = -1, ret;
FILE *f = NULL;
- ret = -EINVAL;
+ errno = EINVAL;
if (strchr(interface, '/'))
goto out;
ret = snprintf(addr.sun_path, sizeof(addr.sun_path), SOCK_PATH "%s" SOCK_SUFFIX, interface);
@@ -120,7 +120,7 @@ static FILE *userspace_interface_file(const char *interface)
ret = stat(addr.sun_path, &sbuf);
if (ret < 0)
goto out;
- ret = -EBADF;
+ errno = EBADF;
if (!S_ISSOCK(sbuf.st_mode))
goto out;
@@ -135,12 +135,13 @@ static FILE *userspace_interface_file(const char *interface)
goto out;
}
f = fdopen(fd, "r+");
- if (!f)
- ret = -errno;
+ if (f)
+ errno = 0;
out:
- if (ret && fd >= 0)
- close(fd);
+ ret = -errno;
if (ret) {
+ if (fd >= 0)
+ close(fd);
errno = -ret;
return NULL;
}