30 #if defined(_WIN32) && !defined(__MINGW32CE__)
36 int ff_win32_open(
const char *filename_utf8,
int oflag,
int pmode)
43 num_chars = MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1,
NULL, 0);
46 filename_w =
av_mallocz(
sizeof(
wchar_t) * num_chars);
47 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
49 fd = _wopen(filename_w, oflag, pmode);
53 if (fd == -1 && !(oflag & O_CREAT))
54 return open(filename_utf8, oflag, pmode);
68 #elif HAVE_SYS_SELECT_H
69 #include <sys/select.h>
80 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
82 if (sscanf(str,
"%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4)
85 if (!add1 || (add1 | add2 | add3 | add4) > 255)
88 add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4);
95 return inet_aton(str, add);
103 struct hostent *h =
NULL;
105 struct sockaddr_in *sin;
108 int (WSAAPI *win_getaddrinfo)(
const char *node,
const char *service,
111 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
112 win_getaddrinfo = GetProcAddress(ws2mod,
"getaddrinfo");
114 return win_getaddrinfo(node, service, hints, res);
121 sin->sin_family = AF_INET;
129 h = gethostbyname(node);
134 memcpy(&sin->sin_addr, h->h_addr_list[0],
sizeof(
struct in_addr));
138 sin->sin_addr.s_addr = INADDR_ANY;
146 sin->sin_port = htons(atoi(service));
169 ai->
ai_addr = (
struct sockaddr *)sin;
182 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
183 win_freeaddrinfo = (
void (WSAAPI *)(
struct addrinfo *res))
184 GetProcAddress(ws2mod,
"freeaddrinfo");
185 if (win_freeaddrinfo) {
186 win_freeaddrinfo(res);
197 char *host,
int hostlen,
198 char *serv,
int servlen,
int flags)
200 const struct sockaddr_in *sin = (
const struct sockaddr_in *)sa;
203 int (WSAAPI *win_getnameinfo)(
const struct sockaddr *sa, socklen_t salen,
204 char *host, DWORD hostlen,
205 char *serv, DWORD servlen,
int flags);
206 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
207 win_getnameinfo = GetProcAddress(ws2mod,
"getnameinfo");
209 return win_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
212 if (sa->sa_family != AF_INET)
217 if (host && hostlen > 0) {
218 struct hostent *ent =
NULL;
221 ent = gethostbyaddr((
const char *)&sin->sin_addr,
222 sizeof(sin->sin_addr), AF_INET);
225 snprintf(host, hostlen,
"%s", ent->h_name);
229 a = ntohl(sin->sin_addr.s_addr);
230 snprintf(host, hostlen,
"%d.%d.%d.%d",
231 ((a >> 24) & 0xff), ((a >> 16) & 0xff),
232 ((a >> 8) & 0xff), (a & 0xff));
236 if (serv && servlen > 0) {
237 struct servent *ent =
NULL;
238 #if HAVE_GETSERVBYPORT
240 ent = getservbyport(sin->sin_port, flags &
NI_DGRAM ?
"udp" :
"tcp");
244 snprintf(serv, servlen,
"%s", ent->s_name);
246 snprintf(serv, servlen,
"%d", ntohs(sin->sin_port));
253 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
258 return "Temporary failure in name resolution";
260 return "Invalid flags for ai_flags";
262 return "A non-recoverable error occurred";
264 return "The address family was not recognized or the address "
265 "length was invalid for the specified family";
267 return "Memory allocation failure";
268 #if EAI_NODATA != EAI_NONAME
270 return "No address associated with hostname";
273 return "The name does not resolve for the supplied parameters";
275 return "servname not supported for ai_socktype";
277 return "ai_socktype not supported";
280 return "Unknown error";
287 u_long param = enable;
288 return ioctlsocket(socket, FIONBIO, ¶m);
291 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
293 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
298 int ff_poll(
struct pollfd *fds, nfds_t numfds,
int timeout)
302 fd_set exception_set;
308 if (numfds >= FD_SETSIZE) {
316 FD_ZERO(&exception_set);
319 for (i = 0; i < numfds; i++) {
323 if (fds[i].fd >= FD_SETSIZE) {
329 if (fds[i].events & POLLIN)
330 FD_SET(fds[i].fd, &read_set);
331 if (fds[i].events & POLLOUT)
332 FD_SET(fds[i].fd, &write_set);
333 if (fds[i].events & POLLERR)
334 FD_SET(fds[i].fd, &exception_set);
345 rc = select(n, &read_set, &write_set, &exception_set,
NULL);
348 tv.tv_sec = timeout / 1000;
349 tv.tv_usec = 1000 * (timeout % 1000);
350 rc = select(n, &read_set, &write_set, &exception_set, &tv);
356 for (i = 0; i < numfds; i++) {
359 if (FD_ISSET(fds[i].fd, &read_set))
360 fds[i].revents |= POLLIN;
361 if (FD_ISSET(fds[i].fd, &write_set))
362 fds[i].revents |= POLLOUT;
363 if (FD_ISSET(fds[i].fd, &exception_set))
364 fds[i].revents |= POLLERR;