[FFmpeg-devel] [PATCH v5 3/6] avformat/network: add ff_neterror2() for cases that don't use WSAGetLastError

Andrew Sayers ffmpeg-devel at pileofstuff.org
Thu May 16 14:59:08 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 | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index 5d0d05c5f1..351dc34bb6 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -123,7 +123,10 @@ void ff_network_close(void)
 #if HAVE_WINSOCK2_H
 int ff_neterror(void)
 {
-    int err = WSAGetLastError();
+    return ff_neterror2(WSAGetLastError());
+}
+int ff_neterror2(int err)
+{
     switch (err) {
     case WSAEWOULDBLOCK:
         return AVERROR(EAGAIN);
diff --git a/libavformat/network.h b/libavformat/network.h
index f338694212..1ac067f09f 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -63,6 +63,12 @@
  * @note Error is based on WSAGetLastError() (Windows) or `errno` (otherwise)
  */
 int ff_neterror(void);
+/*
+ * @brief ff_neterror()-style AVERROR
+ * @param err error code (usually an errno or Windows Sockets Error Code)
+ * @note Windows Sockets Error Codes are only supported in Windows
+ */
+int ff_neterror2(int err);
 #else
 #include <sys/types.h>
 #include <sys/socket.h>
-- 
2.43.0



More information about the ffmpeg-devel mailing list