[FFmpeg-devel] [PATCH v4 1/3] avformat/network: add ff_neterrno2() for cases where we already have an errno

Andrew Sayers ffmpeg-devel at pileofstuff.org
Sat Apr 20 16:24:59 EEST 2024


For example, WSAStartup()'s documentation says:

    "A call to the WSAGetLastError function is not needed and should not be used"
---
 libavformat/network.c | 5 ++++-
 libavformat/network.h | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index f752efc411..f295957aa5 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -123,7 +123,10 @@ void ff_network_close(void)
 #if HAVE_WINSOCK2_H
 int ff_neterrno(void)
 {
-    int err = WSAGetLastError();
+    return ff_neterrno2(WSAGetLastError());
+}
+int ff_neterrno2(int err)
+{
     switch (err) {
     case WSAEWOULDBLOCK:
         return AVERROR(EAGAIN);
diff --git a/libavformat/network.h b/libavformat/network.h
index ca214087fc..84348f52a4 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -58,6 +58,7 @@
 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*) d, e)
 
 int ff_neterrno(void);
+int ff_neterrno2(int err);
 #else
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -66,6 +67,7 @@ int ff_neterrno(void);
 #include <netdb.h>
 
 #define ff_neterrno() AVERROR(errno)
+#define ff_neterrno2(ERRNO) AVERROR(ERRNO)
 #endif /* HAVE_WINSOCK2_H */
 
 #if HAVE_ARPA_INET_H
-- 
2.43.0



More information about the ffmpeg-devel mailing list