From c065427ebe89dd2dc64938bc37edf43f18290ca1 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 11 Mar 2014 20:53:44 +0100 Subject: [PATCH] fixed bug #35928 BSD sockets functions must set errno for POSIX-compliance (patch by Mason) --- CHANGELOG | 4 ++++ src/api/sockets.c | 6 +++--- src/include/lwip/opt.h | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 61c5862a..c932ba07 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -96,6 +96,10 @@ HISTORY ++ Bugfixes: + 2014-03-11: Simon Goldschmidt (patch by Mason) + * opt.h, sockets.c: fixed bug #35928 BSD sockets functions must set errno for + POSIX-compliance + 2014-02-27: Simon Goldschmidt * dhcp.c: fixed bug #40303 DHCP xid renewed when sending a DHCPREQUEST diff --git a/src/api/sockets.c b/src/api/sockets.c index afa30f05..19edfc57 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -223,13 +223,13 @@ static const int err_to_errno_table[] = { ((unsigned)(-(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \ err_to_errno_table[-(err)] : EIO) -#ifdef ERRNO +#if LWIP_SOCKET_SET_ERRNO #ifndef set_errno #define set_errno(err) do { if (err) { errno = (err); } } while(0) #endif -#else /* ERRNO */ +#else /* LWIP_SOCKET_SET_ERRNO */ #define set_errno(err) -#endif /* ERRNO */ +#endif /* LWIP_SOCKET_SET_ERRNO */ #define sock_set_errno(sk, e) do { \ sk->err = (e); \ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index ccb0aa05..7db6b4ad 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -1493,6 +1493,13 @@ #define LWIP_SOCKET 1 #endif +/* LWIP_SOCKET_SET_ERRNO==1: Set errno when socket functions cannot complete + * successfully, as required by POSIX. Default is POSIX-compliant. + */ +#ifndef LWIP_SOCKET_SET_ERRNO +#define LWIP_SOCKET_SET_ERRNO 1 +#endif + /** * LWIP_COMPAT_SOCKETS==1: Enable BSD-style sockets functions names. * (only used if you use sockets.c)