]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/os_support.c
simplify and use version instead
[ffmpeg] / libavformat / os_support.c
index f1d0e0a8f16301b2f62557800b02cd4c762846b2..cc109d596759bade308d61d24d0a5f901d8c7dc3 100644 (file)
 #include "avformat.h"
 #include <unistd.h>
 #include <fcntl.h>
+#include "os_support.h"
 
-#ifndef HAVE_SYS_POLL_H
-#if defined(__MINGW32__)
+#ifdef CONFIG_NETWORK
+#ifndef HAVE_POLL_H
+#ifdef HAVE_WINSOCK2_H
 #include <winsock2.h>
-#else
+#elif defined (HAVE_SYS_SELECT_H)
 #include <sys/select.h>
 #endif
 #endif
 
-#ifdef CONFIG_NETWORK
 #include "network.h"
 
 #if !defined(HAVE_INET_ATON)
 
 int inet_aton (const char * str, struct in_addr * add)
 {
-    const char * pch = str;
     unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
 
-    add1 = atoi(pch);
-    pch = strpbrk(pch,".");
-    if (!pch) return 0;
-    add2 = atoi(pch);
-    pch = strpbrk(pch,".");
-    if (!pch) return 0;
-    add3 = atoi(pch);
-    pch = strpbrk(pch,".");
-    if (!pch) return 0;
-    add4 = atoi(pch);
+    if (sscanf(str, "%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4)
+        return 0;
 
     if (!add1 || (add1|add2|add3|add4) > 255) return 0;
 
@@ -79,7 +71,7 @@ int resolve_host(struct in_addr *sin_addr, const char *hostname)
 
 int ff_socket_nonblock(int socket, int enable)
 {
-#ifdef __MINGW32__
+#ifdef HAVE_WINSOCK2_H
    return ioctlsocket(socket, FIONBIO, &enable);
 #else
    if (enable)
@@ -91,7 +83,7 @@ int ff_socket_nonblock(int socket, int enable)
 #endif /* CONFIG_NETWORK */
 
 #ifdef CONFIG_FFSERVER
-#ifndef HAVE_SYS_POLL_H
+#ifndef HAVE_POLL_H
 int poll(struct pollfd *fds, nfds_t numfds, int timeout)
 {
     fd_set read_set;
@@ -101,7 +93,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     int n;
     int rc;
 
-#ifdef __MINGW32__
+#ifdef HAVE_WINSOCK2_H
     if (numfds >= FD_SETSIZE) {
         errno = EINVAL;
         return -1;
@@ -116,7 +108,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     for(i = 0; i < numfds; i++) {
         if (fds[i].fd < 0)
             continue;
-#ifndef __MINGW32__
+#ifndef HAVE_WINSOCK2_H
         if (fds[i].fd >= FD_SETSIZE) {
             errno = EINVAL;
             return -1;
@@ -158,6 +150,6 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
 
     return rc;
 }
-#endif /* HAVE_SYS_POLL_H */
+#endif /* HAVE_POLL_H */
 #endif /* CONFIG_FFSERVER */