diff options
author | Martin Storsjö <martin@martin.st> | 2012-09-09 22:35:50 +0300 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2012-09-10 19:49:41 +0300 |
commit | 0697d81269ab07d91b3303923a4751c21c675439 (patch) | |
tree | 87bda7ba6a5ed3ee3e016308d89a1bb38c9c089a /libavformat/file.c | |
parent | 5fa22ae34684b800b133a89dffca18b5d3334381 (diff) | |
download | ffmpeg-0697d81269ab07d91b3303923a4751c21c675439.tar.gz |
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: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/file.c')
-rw-r--r-- | libavformat/file.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/libavformat/file.c b/libavformat/file.c index 0e3577d070..3cfd28c2a4 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -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 */ |