22#ifndef AVFORMAT_OS_SUPPORT_H
23#define AVFORMAT_OS_SUPPORT_H
50# include <sys/types.h>
58# define lseek(f,p,w) _lseeki64((f), (p), (w))
63# define stat win32_stat
79 unsigned short st_mode;
93# define fstat win32_fstat
104# define lseek(f,p,w) lseek64((f), (p), (w))
110 if (path[0] && path[1] ==
':')
118#define S_IRUSR S_IREAD
121#define S_IWUSR S_IWRITE
127#define SHUT_RD SD_RECEIVE
128#define SHUT_WR SD_SEND
129#define SHUT_RDWR SD_BOTH
131#include <sys/socket.h>
140typedef int socklen_t;
145#define closesocket close
149typedef unsigned long nfds_t;
154#if !HAVE_STRUCT_POLLFD
163#define POLLOUT 0x0002
164#define POLLRDNORM POLLIN
165#define POLLWRNORM POLLOUT
166#define POLLRDBAND 0x0008
167#define POLLWRBAND 0x0010
168#define POLLPRI 0x0020
171#define POLLERR 0x0004
172#define POLLHUP 0x0080
173#define POLLNVAL 0x1000
177int ff_poll(
struct pollfd *fds, nfds_t numfds,
int timeout);
190#ifndef _SSIZE_T_DEFINED
191#define _SSIZE_T_DEFINED
192typedef SSIZE_T ssize_t;
195#define DEF_FS_FUNCTION(name, wfunc, afunc) \
196static inline int win32_##name(const char *filename_utf8) \
198 wchar_t *filename_w; \
201 if (get_extended_win32_path(filename_utf8, &filename_w)) \
206 ret = wfunc(filename_w); \
207 av_free(filename_w); \
212 return afunc(filename_utf8); \
215DEF_FS_FUNCTION(unlink, _wunlink, _unlink)
216DEF_FS_FUNCTION(mkdir, _wmkdir, _mkdir)
217DEF_FS_FUNCTION(rmdir, _wrmdir , _rmdir)
219static inline int win32_access(
const char *filename_utf8,
int mode)
223 if (get_extended_win32_path(filename_utf8, &filename_w))
227 ret = _waccess(filename_w,
mode);
231 return _access(filename_utf8,
mode);
234static inline void copy_stat(
struct _stat64 *crtstat,
struct win32_stat *buf)
236 buf->st_dev = crtstat->st_dev;
237 buf->st_ino = crtstat->st_ino;
238 buf->st_mode = crtstat->st_mode;
239 buf->st_nlink = crtstat->st_nlink;
240 buf->st_uid = crtstat->st_uid;
241 buf->st_gid = crtstat->st_gid;
242 buf->st_rdev = crtstat->st_rdev;
243 buf->st_size = crtstat->st_size;
244 buf->st_atime = crtstat->st_atime;
245 buf->st_mtime = crtstat->st_mtime;
246 buf->st_ctime = crtstat->st_ctime;
249static inline int win32_stat(
const char *filename_utf8,
struct win32_stat *buf)
251 struct _stat64 crtstat = { 0 };
255 if (get_extended_win32_path(filename_utf8, &filename_w))
259 ret = _wstat64(filename_w, &crtstat);
262 ret = _stat64(filename_utf8, &crtstat);
264 copy_stat(&crtstat, buf);
269static inline int win32_fstat(
int fd,
struct win32_stat *buf)
271 struct _stat64 crtstat = { 0 };
274 ret = _fstat64(fd, &crtstat);
276 copy_stat(&crtstat, buf);
281static inline int win32_rename(
const char *src_utf8,
const char *dest_utf8)
283 wchar_t *src_w, *dest_w;
286 if (get_extended_win32_path(src_utf8, &src_w))
288 if (get_extended_win32_path(dest_utf8, &dest_w)) {
292 if (!src_w || !dest_w) {
298 ret = (MoveFileExW(src_w, dest_w, MOVEFILE_REPLACE_EXISTING) == 0) ? -1 : 0;
309 ret = (MoveFileExA(src_utf8, dest_utf8, MOVEFILE_REPLACE_EXISTING) == 0) ? -1 : 0;
321 ret = rename(src_utf8, dest_utf8);
340static inline ssize_t win32_pread(
int fd,
void *buf,
size_t size, off_t
offset)
342 HANDLE fh = (HANDLE)_get_osfhandle(fd);
343 OVERLAPPED ov = { .Offset =
offset, .OffsetHigh =
offset >> 32 };
346 if (fh == INVALID_HANDLE_VALUE)
350 if (!ReadFile(fh, buf,
size, &n, &ov)) {
351 if (GetLastError() == ERROR_HANDLE_EOF)
359static inline ssize_t win32_pwrite(
int fd,
const void *buf,
size_t size, off_t
offset)
361 HANDLE fh = (HANDLE)_get_osfhandle(fd);
362 OVERLAPPED ov = { .Offset =
offset, .OffsetHigh =
offset >> 32 };
365 if (fh == INVALID_HANDLE_VALUE)
369 if (!WriteFile(fh, buf,
size, &n, &ov)) {
370 errno = GetLastError() == ERROR_DISK_FULL ? ENOSPC : EIO;
376static inline int win32_flock(
int fd,
int op)
378 HANDLE fh = (HANDLE)_get_osfhandle(fd);
379 OVERLAPPED ov = { 0 };
382 if (fh == INVALID_HANDLE_VALUE)
385 ok = UnlockFileEx(fh, 0, 1, 0, &ov);
389 flags |= LOCKFILE_EXCLUSIVE_LOCK;
391 flags |= LOCKFILE_FAIL_IMMEDIATELY;
392 ok = LockFileEx(fh,
flags, 0, 1, 0, &ov);
395 errno = GetLastError() == ERROR_LOCK_VIOLATION ? EWOULDBLOCK : EIO;
401#define mkdir(a, b) win32_mkdir(a)
402#define rename win32_rename
403#define rmdir win32_rmdir
404#define unlink win32_unlink
405#define access win32_access
406#define pread win32_pread
407#define pwrite win32_pwrite
408#define flock win32_flock
#define flags(name, subs,...)
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Memory handling functions.
static int is_dos_path(const char *path)