Commit 0697d812 authored by Martin Storsjö's avatar Martin Storsjö

file: Use a normal private context for storing the file descriptor

Previously the file descriptor was stored in the priv_data pointer.
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent 5fa22ae3
......@@ -36,21 +36,26 @@
/* 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)
......@@ -70,6 +75,7 @@ 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;
......@@ -88,26 +94,26 @@ static int file_open(URLContext *h, const char *filename, int flags)
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 = {
......@@ -119,6 +125,7 @@ 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 */
......@@ -127,6 +134,7 @@ URLProtocol ff_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);
......@@ -142,7 +150,7 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
#if HAVE_SETMODE
setmode(fd, O_BINARY);
#endif
h->priv_data = (void *) (intptr_t) fd;
c->fd = fd;
h->is_streamed = 1;
return 0;
}
......@@ -154,6 +162,7 @@ URLProtocol ff_pipe_protocol = {
.url_write = file_write,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
.priv_data_size = sizeof(FileContext),
};
#endif /* CONFIG_PIPE_PROTOCOL */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment