From 5aff37d28d6a140f70f6cae996e6f55b21b1106d Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sun, 24 Jun 2012 21:29:14 +0300 Subject: os_support: Include all the necessary headers for the win32 open function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit io.h is required for open and _wopen, and fcntl.h is required for the O_CREAT flag. On mingw, fcntl.h is included by os_support.h (and the mingw fcntl.h includes io.h), but include it explicitly here since this implementation requires it. Also move the #undef open up. open must not be defined to ff_win32_open while including the headers that declare the open function. On mingw, this happened in os_support.h before open was redirected. Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libavformat/os_support.c') diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 0cbaf453db..8054ba6bbb 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -28,9 +28,11 @@ #include "os_support.h" #if defined(_WIN32) && !defined(__MINGW32CE__) +#undef open +#include +#include #include -#undef open int ff_win32_open(const char *filename_utf8, int oflag, int pmode) { int fd; -- cgit v1.2.3 From 71078ad3338d850a24071e93b69d2109a943f73e Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sun, 24 Jun 2012 22:36:37 +0300 Subject: os_support: Don't compare a negative number against socket descriptors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fds are unsigned integers in the windows definition of struct sockfds. Due to this, the comparison if (fds[i].fd > n) was always false. Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libavformat/os_support.c') diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 8054ba6bbb..49ec0c60d1 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -286,7 +286,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) FD_ZERO(&write_set); FD_ZERO(&exception_set); - n = -1; + n = 0; for(i = 0; i < numfds; i++) { if (fds[i].fd < 0) continue; @@ -301,22 +301,22 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set); - if (fds[i].fd > n) - n = fds[i].fd; + if (fds[i].fd >= n) + n = fds[i].fd + 1; }; - if (n == -1) + if (n == 0) /* Hey!? Nothing to poll, in fact!!! */ return 0; if (timeout < 0) - rc = select(n+1, &read_set, &write_set, &exception_set, NULL); + rc = select(n, &read_set, &write_set, &exception_set, NULL); else { struct timeval tv; tv.tv_sec = timeout / 1000; tv.tv_usec = 1000 * (timeout % 1000); - rc = select(n+1, &read_set, &write_set, &exception_set, &tv); + rc = select(n, &read_set, &write_set, &exception_set, &tv); }; if (rc < 0) -- cgit v1.2.3 From cab2eb87f9d692f543d11057dbfac4e590570b18 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Mon, 25 Jun 2012 12:27:37 +0300 Subject: os_support: Rename the poll fallback function to ff_poll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fallback function is a non-static function, we shouldn't be defining non-static functions outside of the proper ff/av prefix namespaces. This is especially important for a function like poll, which other parties (other libraries, or executables linking these libraries) also might provide similar but incompatible fallbacks for. Signed-off-by: Martin Storsjö --- libavformat/os_support.c | 2 +- libavformat/os_support.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'libavformat/os_support.c') diff --git a/libavformat/os_support.c b/libavformat/os_support.c index 49ec0c60d1..6d8c8ac6a3 100644 --- a/libavformat/os_support.c +++ b/libavformat/os_support.c @@ -266,7 +266,7 @@ int ff_socket_nonblock(int socket, int enable) } #if !HAVE_POLL_H -int poll(struct pollfd *fds, nfds_t numfds, int timeout) +int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout) { fd_set read_set; fd_set write_set; diff --git a/libavformat/os_support.h b/libavformat/os_support.h index cda84b0296..dfb87ef43a 100644 --- a/libavformat/os_support.h +++ b/libavformat/os_support.h @@ -101,7 +101,8 @@ struct pollfd { #endif -int poll(struct pollfd *fds, nfds_t numfds, int timeout); +int ff_poll(struct pollfd *fds, nfds_t numfds, int timeout); +#define poll ff_poll #endif /* HAVE_POLL_H */ #endif /* CONFIG_NETWORK */ -- cgit v1.2.3