/* standard file protocol */
+typedef struct FileContext {
+ int fd;
+} FileContext;
+
static int file_read(URLContext *h, unsigned char *buf, int size)
{
- int fd = (intptr_t) h->priv_data;
- return read(fd, buf, size);
+ FileContext *c = h->priv_data;
+ return read(c->fd, buf, size);
}
static int file_write(URLContext *h, const unsigned char *buf, int size)
{
- int fd = (intptr_t) h->priv_data;
- return write(fd, buf, size);
+ FileContext *c = h->priv_data;
+ return write(c->fd, buf, size);
}
static int file_get_handle(URLContext *h)
{
- return (intptr_t) h->priv_data;
+ FileContext *c = h->priv_data;
+ return c->fd;
}
static int file_check(URLContext *h, int mask)
static int file_open(URLContext *h, const char *filename, int flags)
{
+ FileContext *c = h->priv_data;
int access;
int fd;
fd = open(filename, access, 0666);
if (fd == -1)
return AVERROR(errno);
- h->priv_data = (void *) (intptr_t) fd;
+ c->fd = fd;
return 0;
}
/* XXX: use llseek */
static int64_t file_seek(URLContext *h, int64_t pos, int whence)
{
- int fd = (intptr_t) h->priv_data;
+ FileContext *c = h->priv_data;
if (whence == AVSEEK_SIZE) {
struct stat st;
- int ret = fstat(fd, &st);
+ int ret = fstat(c->fd, &st);
return ret < 0 ? AVERROR(errno) : st.st_size;
}
- return lseek(fd, pos, whence);
+ return lseek(c->fd, pos, whence);
}
static int file_close(URLContext *h)
{
- int fd = (intptr_t) h->priv_data;
- return close(fd);
+ FileContext *c = h->priv_data;
+ return close(c->fd);
}
URLProtocol ff_file_protocol = {
.url_close = file_close,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
+ .priv_data_size = sizeof(FileContext),
};
#endif /* CONFIG_FILE_PROTOCOL */
static int pipe_open(URLContext *h, const char *filename, int flags)
{
+ FileContext *c = h->priv_data;
int fd;
char *final;
av_strstart(filename, "pipe:", &filename);
#if HAVE_SETMODE
setmode(fd, O_BINARY);
#endif
- h->priv_data = (void *) (intptr_t) fd;
+ c->fd = fd;
h->is_streamed = 1;
return 0;
}
.url_write = file_write,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
+ .priv_data_size = sizeof(FileContext),
};
#endif /* CONFIG_PIPE_PROTOCOL */