30 #if defined(_WIN32) && !defined(__MINGW32CE__)
41 int ff_win32_open(
const char *filename_utf8,
int oflag,
int pmode)
48 num_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename_utf8, -1, NULL, 0);
51 filename_w =
av_mallocz(
sizeof(
wchar_t) * num_chars);
56 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars);
58 fd = _wsopen(filename_w, oflag, SH_DENYNO, pmode);
61 if (fd != -1 || (oflag & O_CREAT))
66 return _sopen(filename_utf8, oflag, SH_DENYNO, pmode);
78 #elif HAVE_SYS_SELECT_H
79 #include <sys/select.h>
90 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
92 if (sscanf(str,
"%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4)
95 if (!add1 || (add1 | add2 | add3 | add4) > 255)
98 add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4);
105 return inet_aton(str, add);
109 #if !HAVE_GETADDRINFO
113 struct hostent *h = NULL;
115 struct sockaddr_in *sin;
118 int (WSAAPI *win_getaddrinfo)(
const char *node,
const char *service,
121 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
124 return win_getaddrinfo(node, service, hints, res);
131 sin->sin_family = AF_INET;
139 h = gethostbyname(node);
144 memcpy(&sin->sin_addr, h->h_addr_list[0],
sizeof(
struct in_addr));
148 sin->sin_addr.s_addr = INADDR_ANY;
156 sin->sin_port = htons(atoi(service));
179 ai->
ai_addr = (
struct sockaddr *)sin;
192 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
195 if (win_freeaddrinfo) {
196 win_freeaddrinfo(res);
207 char *host,
int hostlen,
208 char *serv,
int servlen,
int flags)
210 const struct sockaddr_in *sin = (
const struct sockaddr_in *)sa;
213 int (WSAAPI *win_getnameinfo)(
const struct sockaddr *sa, socklen_t salen,
214 char *host,
DWORD hostlen,
216 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
219 return win_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
222 if (sa->sa_family != AF_INET)
227 if (host && hostlen > 0) {
228 struct hostent *ent = NULL;
231 ent = gethostbyaddr((
const char *)&sin->sin_addr,
232 sizeof(sin->sin_addr), AF_INET);
235 snprintf(host, hostlen,
"%s", ent->h_name);
239 a = ntohl(sin->sin_addr.s_addr);
240 snprintf(host, hostlen,
"%d.%d.%d.%d",
241 ((a >> 24) & 0xff), ((a >> 16) & 0xff),
242 ((a >> 8) & 0xff), (a & 0xff));
246 if (serv && servlen > 0) {
247 struct servent *ent = NULL;
248 #if HAVE_GETSERVBYPORT
250 ent = getservbyport(sin->sin_port, flags &
NI_DGRAM ?
"udp" :
"tcp");
254 snprintf(serv, servlen,
"%s", ent->s_name);
256 snprintf(serv, servlen,
"%d", ntohs(sin->sin_port));
263 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
268 return "Temporary failure in name resolution";
270 return "Invalid flags for ai_flags";
272 return "A non-recoverable error occurred";
274 return "The address family was not recognized or the address "
275 "length was invalid for the specified family";
277 return "Memory allocation failure";
278 #if EAI_NODATA != EAI_NONAME
280 return "No address associated with hostname";
283 return "The name does not resolve for the supplied parameters";
285 return "servname not supported for ai_socktype";
287 return "ai_socktype not supported";
290 return "Unknown error";
297 u_long param = enable;
298 return ioctlsocket(socket, FIONBIO, ¶m);
301 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
303 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
308 int ff_poll(
struct pollfd *fds, nfds_t numfds,
int timeout)
312 fd_set exception_set;
318 if (numfds >= FD_SETSIZE) {
326 FD_ZERO(&exception_set);
329 for (i = 0; i < numfds; i++) {
333 if (fds[i].fd >= FD_SETSIZE) {
339 if (fds[i].events & POLLIN)
340 FD_SET(fds[i].fd, &read_set);
341 if (fds[i].events & POLLOUT)
342 FD_SET(fds[i].fd, &write_set);
343 if (fds[i].events & POLLERR)
344 FD_SET(fds[i].fd, &exception_set);
355 rc = select(n, &read_set, &write_set, &exception_set, NULL);
358 tv.tv_sec = timeout / 1000;
359 tv.tv_usec = 1000 * (timeout % 1000);
360 rc = select(n, &read_set, &write_set, &exception_set, &tv);
366 for (i = 0; i < numfds; i++) {
369 if (FD_ISSET(fds[i].fd, &read_set))
370 fds[i].revents |= POLLIN;
371 if (FD_ISSET(fds[i].fd, &write_set))
372 fds[i].revents |= POLLOUT;
373 if (FD_ISSET(fds[i].fd, &exception_set))
374 fds[i].revents |= POLLERR;