From e7943f56e2433ce205a429f01b30d55fc5594fe2 Mon Sep 17 00:00:00 2001
From: Axel Lin <axel.lin@ingics.com>
Date: Wed, 1 May 2019 11:00:59 +0800
Subject: [PATCH] sockets: Get rid of sock_set_errno

The err field is removed from struct lwip_sock since commit e0a2472706ee
("netconn/sockets: remove fatal error handling, fix asynchronous error handling, ensure data before RST can be received")
sock_set_errno() simply calls set_errno() now, so use set_errno() instead.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 src/api/sockets.c | 139 ++++++++++++++++++++++------------------------
 1 file changed, 67 insertions(+), 72 deletions(-)

diff --git a/src/api/sockets.c b/src/api/sockets.c
index 05951ffdcabd..78e0f883667a 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -178,7 +178,7 @@ static void sockaddr_to_ipaddr_port(const struct sockaddr *sockaddr, ip_addr_t *
 #define LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(name, sock) do { \
   name = (struct lwip_setgetsockopt_data *)memp_malloc(MEMP_SOCKET_SETGETSOCKOPT_DATA); \
   if (name == NULL) { \
-    sock_set_errno(sock, ENOMEM); \
+    set_errno(ENOMEM); \
     done_socket(sock); \
     return -1; \
   } }while(0)
@@ -278,11 +278,6 @@ static volatile int select_cb_ctr;
 static struct lwip_select_cb *select_cb_list;
 #endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */
 
-#define sock_set_errno(sk, e) do { \
-  const int sockerr = (e); \
-  set_errno(sockerr); \
-} while (0)
-
 /* Forward declaration of some functions */
 #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL
 static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len);
@@ -639,11 +634,11 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
   if (err != ERR_OK) {
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_acept failed, err=%d\n", s, err));
     if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) {
-      sock_set_errno(sock, EOPNOTSUPP);
+      set_errno(EOPNOTSUPP);
     } else if (err == ERR_CLSD) {
-      sock_set_errno(sock, EINVAL);
+      set_errno(EINVAL);
     } else {
-      sock_set_errno(sock, err_to_errno(err));
+      set_errno(err_to_errno(err));
     }
     done_socket(sock);
     return -1;
@@ -653,7 +648,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
   newsock = alloc_socket(newconn, 1);
   if (newsock == -1) {
     netconn_delete(newconn);
-    sock_set_errno(sock, ENFILE);
+    set_errno(ENFILE);
     done_socket(sock);
     return -1;
   }
@@ -689,7 +684,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
     if (err != ERR_OK) {
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
       free_socket(nsock, 1);
-      sock_set_errno(sock, err_to_errno(err));
+      set_errno(err_to_errno(err));
       done_socket(sock);
       return -1;
     }
@@ -707,7 +702,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d", s, newsock));
   }
 
-  sock_set_errno(sock, 0);
+  set_errno(0);
   done_socket(sock);
   done_socket(nsock);
   return newsock;
@@ -728,7 +723,7 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
 
   if (!SOCK_ADDR_TYPE_MATCH(name, sock)) {
     /* sockaddr does not match socket type (IPv4/IPv6) */
-    sock_set_errno(sock, err_to_errno(ERR_VAL));
+    set_errno(err_to_errno(ERR_VAL));
     done_socket(sock);
     return -1;
   }
@@ -736,7 +731,7 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
   /* check size, family and alignment of 'name' */
   LWIP_ERROR("lwip_bind: invalid address", (IS_SOCK_ADDR_LEN_VALID(namelen) &&
              IS_SOCK_ADDR_TYPE_VALID(name) && IS_SOCK_ADDR_ALIGNED(name)),
-             sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
+             set_errno(err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
   LWIP_UNUSED_ARG(namelen);
 
   SOCKADDR_TO_IPADDR_PORT(name, &local_addr, local_port);
@@ -756,13 +751,13 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
 
   if (err != ERR_OK) {
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err));
-    sock_set_errno(sock, err_to_errno(err));
+    set_errno(err_to_errno(err));
     done_socket(sock);
     return -1;
   }
 
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) succeeded\n", s));
-  sock_set_errno(sock, 0);
+  set_errno(0);
   done_socket(sock);
   return 0;
 }
@@ -798,7 +793,7 @@ lwip_close(int s)
 
   err = netconn_prepare_delete(sock->conn);
   if (err != ERR_OK) {
-    sock_set_errno(sock, err_to_errno(err));
+    set_errno(err_to_errno(err));
     done_socket(sock);
     return -1;
   }
@@ -821,7 +816,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
 
   if (!SOCK_ADDR_TYPE_MATCH_OR_UNSPEC(name, sock)) {
     /* sockaddr does not match socket type (IPv4/IPv6) */
-    sock_set_errno(sock, err_to_errno(ERR_VAL));
+    set_errno(err_to_errno(ERR_VAL));
     done_socket(sock);
     return -1;
   }
@@ -837,7 +832,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
     /* check size, family and alignment of 'name' */
     LWIP_ERROR("lwip_connect: invalid address", IS_SOCK_ADDR_LEN_VALID(namelen) &&
                IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC(name) && IS_SOCK_ADDR_ALIGNED(name),
-               sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
+               set_errno(err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
 
     SOCKADDR_TO_IPADDR_PORT(name, &remote_addr, remote_port);
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
@@ -857,13 +852,13 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
 
   if (err != ERR_OK) {
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err));
-    sock_set_errno(sock, err_to_errno(err));
+    set_errno(err_to_errno(err));
     done_socket(sock);
     return -1;
   }
 
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) succeeded\n", s));
-  sock_set_errno(sock, 0);
+  set_errno(0);
   done_socket(sock);
   return 0;
 }
@@ -897,15 +892,15 @@ lwip_listen(int s, int backlog)
   if (err != ERR_OK) {
     LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err));
     if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) {
-      sock_set_errno(sock, EOPNOTSUPP);
+      set_errno(EOPNOTSUPP);
     } else {
-      sock_set_errno(sock, err_to_errno(err));
+      set_errno(err_to_errno(err));
     }
     done_socket(sock);
     return -1;
   }
 
-  sock_set_errno(sock, 0);
+  set_errno(0);
   done_socket(sock);
   return 0;
 }
@@ -954,7 +949,7 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags)
         /* We should really do some error checking here. */
         LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: p == NULL, error is \"%s\"!\n",
                                     lwip_strerr(err)));
-        sock_set_errno(sock, err_to_errno(err));
+        set_errno(err_to_errno(err));
         if (err == ERR_CLSD) {
           return 0;
         } else {
@@ -1012,7 +1007,7 @@ lwip_recv_tcp_done:
     /* ensure window update after copying all data */
     netconn_tcp_recvd(sock->conn, (size_t)recvd);
   }
-  sock_set_errno(sock, 0);
+  set_errno(0);
   return recvd;
 }
 #endif
@@ -1232,7 +1227,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
     if (err != ERR_OK) {
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n",
                                   s, lwip_strerr(err)));
-      sock_set_errno(sock, err_to_errno(err));
+      set_errno(err_to_errno(err));
       done_socket(sock);
       return -1;
     }
@@ -1242,7 +1237,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
     }
   }
 
-  sock_set_errno(sock, 0);
+  set_errno(0);
   done_socket(sock);
   return ret;
 }
@@ -1304,7 +1299,7 @@ lwip_recvmsg(int s, struct msghdr *message, int flags)
     if ((message->msg_iov[i].iov_base == NULL) || ((ssize_t)message->msg_iov[i].iov_len <= 0) ||
         ((size_t)(ssize_t)message->msg_iov[i].iov_len != message->msg_iov[i].iov_len) ||
         ((ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len) <= 0)) {
-      sock_set_errno(sock, err_to_errno(ERR_VAL));
+      set_errno(err_to_errno(ERR_VAL));
       done_socket(sock);
       return -1;
     }
@@ -1338,13 +1333,13 @@ lwip_recvmsg(int s, struct msghdr *message, int flags)
     }
     if (buflen > 0) {
       /* reset socket error since we have received something */
-      sock_set_errno(sock, 0);
+      set_errno(0);
     }
     /* " If the socket is connected, the msg_name and msg_namelen members shall be ignored." */
     done_socket(sock);
     return buflen;
 #else /* LWIP_TCP */
-    sock_set_errno(sock, err_to_errno(ERR_ARG));
+    set_errno(err_to_errno(ERR_ARG));
     done_socket(sock);
     return -1;
 #endif /* LWIP_TCP */
@@ -1358,7 +1353,7 @@ lwip_recvmsg(int s, struct msghdr *message, int flags)
     if (err != ERR_OK) {
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvmsg[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n",
                                   s, lwip_strerr(err)));
-      sock_set_errno(sock, err_to_errno(err));
+      set_errno(err_to_errno(err));
       done_socket(sock);
       return -1;
     }
@@ -1366,12 +1361,12 @@ lwip_recvmsg(int s, struct msghdr *message, int flags)
       message->msg_flags |= MSG_TRUNC;
     }
 
-    sock_set_errno(sock, 0);
+    set_errno(0);
     done_socket(sock);
     return (int)datagram_len;
   }
 #else /* LWIP_UDP || LWIP_RAW */
-  sock_set_errno(sock, err_to_errno(ERR_ARG));
+  set_errno(err_to_errno(ERR_ARG));
   done_socket(sock);
   return -1;
 #endif /* LWIP_UDP || LWIP_RAW */
@@ -1398,7 +1393,7 @@ lwip_send(int s, const void *data, size_t size, int flags)
     done_socket(sock);
     return lwip_sendto(s, data, size, flags, NULL, 0);
 #else /* (LWIP_UDP || LWIP_RAW) */
-    sock_set_errno(sock, err_to_errno(ERR_ARG));
+    set_errno(err_to_errno(ERR_ARG));
     done_socket(sock);
     return -1;
 #endif /* (LWIP_UDP || LWIP_RAW) */
@@ -1411,7 +1406,7 @@ lwip_send(int s, const void *data, size_t size, int flags)
   err = netconn_write_partly(sock->conn, data, size, write_flags, &written);
 
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d written=%"SZT_F"\n", s, err, written));
-  sock_set_errno(sock, err_to_errno(err));
+  set_errno(err_to_errno(err));
   done_socket(sock);
   /* casting 'written' to ssize_t is OK here since the netconn API limits it to SSIZE_MAX */
   return (err == ERR_OK ? (ssize_t)written : -1);
@@ -1433,13 +1428,13 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
   }
 
   LWIP_ERROR("lwip_sendmsg: invalid msghdr", msg != NULL,
-             sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
+             set_errno(err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
   LWIP_ERROR("lwip_sendmsg: invalid msghdr iov", msg->msg_iov != NULL,
-             sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
+             set_errno(err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
   LWIP_ERROR("lwip_sendmsg: maximum iovs exceeded", (msg->msg_iovlen > 0) && (msg->msg_iovlen <= IOV_MAX),
-             sock_set_errno(sock, EMSGSIZE); done_socket(sock); return -1;);
+             set_errno(EMSGSIZE); done_socket(sock); return -1;);
   LWIP_ERROR("lwip_sendmsg: unsupported flags", (flags & ~(MSG_DONTWAIT | MSG_MORE)) == 0,
-             sock_set_errno(sock, EOPNOTSUPP); done_socket(sock); return -1;);
+             set_errno(EOPNOTSUPP); done_socket(sock); return -1;);
 
   LWIP_UNUSED_ARG(msg->msg_control);
   LWIP_UNUSED_ARG(msg->msg_controllen);
@@ -1453,12 +1448,12 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
 
     written = 0;
     err = netconn_write_vectors_partly(sock->conn, (struct netvector *)msg->msg_iov, (u16_t)msg->msg_iovlen, write_flags, &written);
-    sock_set_errno(sock, err_to_errno(err));
+    set_errno(err_to_errno(err));
     done_socket(sock);
     /* casting 'written' to ssize_t is OK here since the netconn API limits it to SSIZE_MAX */
     return (err == ERR_OK ? (ssize_t)written : -1);
 #else /* LWIP_TCP */
-    sock_set_errno(sock, err_to_errno(ERR_ARG));
+    set_errno(err_to_errno(ERR_ARG));
     done_socket(sock);
     return -1;
 #endif /* LWIP_TCP */
@@ -1473,7 +1468,7 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
     LWIP_UNUSED_ARG(flags);
     LWIP_ERROR("lwip_sendmsg: invalid msghdr name", (((msg->msg_name == NULL) && (msg->msg_namelen == 0)) ||
                IS_SOCK_ADDR_LEN_VALID(msg->msg_namelen)),
-               sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
+               set_errno(err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
 
     /* initialize chain buffer with destination */
     memset(&chain_buf, 0, sizeof(struct netbuf));
@@ -1564,17 +1559,17 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
     /* deallocated the buffer */
     netbuf_free(&chain_buf);
 
-    sock_set_errno(sock, err_to_errno(err));
+    set_errno(err_to_errno(err));
     done_socket(sock);
     return (err == ERR_OK ? size : -1);
 sendmsg_emsgsize:
-    sock_set_errno(sock, EMSGSIZE);
+    set_errno(EMSGSIZE);
     netbuf_free(&chain_buf);
     done_socket(sock);
     return -1;
   }
 #else /* LWIP_UDP || LWIP_RAW */
-  sock_set_errno(sock, err_to_errno(ERR_ARG));
+  set_errno(err_to_errno(ERR_ARG));
   done_socket(sock);
   return -1;
 #endif /* LWIP_UDP || LWIP_RAW */
@@ -1601,7 +1596,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
     return lwip_send(s, data, size, flags);
 #else /* LWIP_TCP */
     LWIP_UNUSED_ARG(flags);
-    sock_set_errno(sock, err_to_errno(ERR_ARG));
+    set_errno(err_to_errno(ERR_ARG));
     done_socket(sock);
     return -1;
 #endif /* LWIP_TCP */
@@ -1609,7 +1604,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
 
   if (size > LWIP_MIN(0xFFFF, SSIZE_MAX)) {
     /* cannot fit into one datagram (at least for us) */
-    sock_set_errno(sock, EMSGSIZE);
+    set_errno(EMSGSIZE);
     done_socket(sock);
     return -1;
   }
@@ -1617,7 +1612,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
   LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
              (IS_SOCK_ADDR_LEN_VALID(tolen) &&
               ((to != NULL) && (IS_SOCK_ADDR_TYPE_VALID(to) && IS_SOCK_ADDR_ALIGNED(to))))),
-             sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
+             set_errno(err_to_errno(ERR_ARG)); done_socket(sock); return -1;);
   LWIP_UNUSED_ARG(tolen);
 
   /* initialize a buffer */
@@ -1675,7 +1670,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
   /* deallocated the buffer */
   netbuf_free(&buf);
 
-  sock_set_errno(sock, err_to_errno(err));
+  set_errno(err_to_errno(err));
   done_socket(sock);
   return (err == ERR_OK ? short_size : -1);
 }
@@ -2666,12 +2661,12 @@ lwip_shutdown(int s, int how)
 
   if (sock->conn != NULL) {
     if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) {
-      sock_set_errno(sock, EOPNOTSUPP);
+      set_errno(EOPNOTSUPP);
       done_socket(sock);
       return -1;
     }
   } else {
-    sock_set_errno(sock, ENOTCONN);
+    set_errno(ENOTCONN);
     done_socket(sock);
     return -1;
   }
@@ -2684,13 +2679,13 @@ lwip_shutdown(int s, int how)
     shut_rx = 1;
     shut_tx = 1;
   } else {
-    sock_set_errno(sock, EINVAL);
+    set_errno(EINVAL);
     done_socket(sock);
     return -1;
   }
   err = netconn_shutdown(sock->conn, shut_rx, shut_tx);
 
-  sock_set_errno(sock, err_to_errno(err));
+  set_errno(err_to_errno(err));
   done_socket(sock);
   return (err == ERR_OK ? 0 : -1);
 }
@@ -2712,7 +2707,7 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
   /* get the IP address and port */
   err = netconn_getaddr(sock->conn, &naddr, &port, local);
   if (err != ERR_OK) {
-    sock_set_errno(sock, err_to_errno(err));
+    set_errno(err_to_errno(err));
     done_socket(sock);
     return -1;
   }
@@ -2737,7 +2732,7 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
   }
   MEMCPY(name, &saddr, *namelen);
 
-  sock_set_errno(sock, 0);
+  set_errno(0);
   done_socket(sock);
   return 0;
 }
@@ -2769,7 +2764,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
   }
 
   if ((NULL == optval) || (NULL == optlen)) {
-    sock_set_errno(sock, EFAULT);
+    set_errno(EFAULT);
     done_socket(sock);
     return -1;
   }
@@ -2785,7 +2780,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
 #if LWIP_MPU_COMPATIBLE
   /* MPU_COMPATIBLE copies the optval data, so check for max size here */
   if (*optlen > LWIP_SETGETSOCKOPT_MAXOPTLEN) {
-    sock_set_errno(sock, ENOBUFS);
+    set_errno(ENOBUFS);
     done_socket(sock);
     return -1;
   }
@@ -2808,7 +2803,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
   cberr = tcpip_callback(lwip_getsockopt_callback, &LWIP_SETGETSOCKOPT_DATA_VAR_REF(data));
   if (cberr != ERR_OK) {
     LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data);
-    sock_set_errno(sock, err_to_errno(cberr));
+    set_errno(err_to_errno(cberr));
     done_socket(sock);
     return -1;
   }
@@ -2826,7 +2821,7 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
   LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data);
 #endif /* LWIP_TCPIP_CORE_LOCKING */
 
-  sock_set_errno(sock, err);
+  set_errno(err);
   done_socket(sock);
   return err ? -1 : 0;
 }
@@ -3215,7 +3210,7 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt
   }
 
   if (NULL == optval) {
-    sock_set_errno(sock, EFAULT);
+    set_errno(EFAULT);
     done_socket(sock);
     return -1;
   }
@@ -3231,7 +3226,7 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt
 #if LWIP_MPU_COMPATIBLE
   /* MPU_COMPATIBLE copies the optval data, so check for max size here */
   if (optlen > LWIP_SETGETSOCKOPT_MAXOPTLEN) {
-    sock_set_errno(sock, ENOBUFS);
+    set_errno(ENOBUFS);
     done_socket(sock);
     return -1;
   }
@@ -3256,7 +3251,7 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt
   cberr = tcpip_callback(lwip_setsockopt_callback, &LWIP_SETGETSOCKOPT_DATA_VAR_REF(data));
   if (cberr != ERR_OK) {
     LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data);
-    sock_set_errno(sock, err_to_errno(cberr));
+    set_errno(err_to_errno(cberr));
     done_socket(sock);
     return -1;
   }
@@ -3267,7 +3262,7 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt
   LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data);
 #endif  /* LWIP_TCPIP_CORE_LOCKING */
 
-  sock_set_errno(sock, err);
+  set_errno(err);
   done_socket(sock);
   return err ? -1 : 0;
 }
@@ -3755,7 +3750,7 @@ lwip_ioctl(int s, long cmd, void *argp)
 #if LWIP_SO_RCVBUF || LWIP_FIONREAD_LINUXMODE
     case FIONREAD:
       if (!argp) {
-        sock_set_errno(sock, EINVAL);
+        set_errno(EINVAL);
         done_socket(sock);
         return -1;
       }
@@ -3798,7 +3793,7 @@ lwip_ioctl(int s, long cmd, void *argp)
       *((int *)argp) = recv_avail;
 
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONREAD, %p) = %"U16_F"\n", s, argp, *((u16_t *)argp)));
-      sock_set_errno(sock, 0);
+      set_errno(0);
       done_socket(sock);
       return 0;
 #else /* LWIP_SO_RCVBUF */
@@ -3813,7 +3808,7 @@ lwip_ioctl(int s, long cmd, void *argp)
       }
       netconn_set_nonblocking(sock->conn, val);
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONBIO, %d)\n", s, val));
-      sock_set_errno(sock, 0);
+      set_errno(0);
       done_socket(sock);
       return 0;
 
@@ -3821,7 +3816,7 @@ lwip_ioctl(int s, long cmd, void *argp)
       break;
   } /* switch (cmd) */
   LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp));
-  sock_set_errno(sock, ENOSYS); /* not yet implemented */
+  set_errno(ENOSYS); /* not yet implemented */
   done_socket(sock);
   return -1;
 }
@@ -3845,7 +3840,7 @@ lwip_fcntl(int s, int cmd, int val)
   switch (cmd) {
     case F_GETFL:
       ret = netconn_is_nonblocking(sock->conn) ? O_NONBLOCK : 0;
-      sock_set_errno(sock, 0);
+      set_errno(0);
 
       if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) {
 #if LWIP_TCPIP_CORE_LOCKING
@@ -3886,14 +3881,14 @@ lwip_fcntl(int s, int cmd, int val)
         /* only O_NONBLOCK, all other bits are zero */
         netconn_set_nonblocking(sock->conn, val & O_NONBLOCK);
         ret = 0;
-        sock_set_errno(sock, 0);
+        set_errno(0);
       } else {
-        sock_set_errno(sock, ENOSYS); /* not yet implemented */
+        set_errno(ENOSYS); /* not yet implemented */
       }
       break;
     default:
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_fcntl(%d, UNIMPL: %d, %d)\n", s, cmd, val));
-      sock_set_errno(sock, ENOSYS); /* not yet implemented */
+      set_errno(ENOSYS); /* not yet implemented */
       break;
   }
   done_socket(sock);
-- 
2.20.1

