2 * Buffered file io for ffmpeg system
3 * Copyright (c) 2001 Fabrice Bellard
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sys/ioctl.h>
27 #define open(fname,oflag,pmode) _open(fname,oflag,pmode)
28 #endif /* CONFIG_WIN32 */
31 /* standard file protocol */
33 static int file_open(URLContext *h, const char *filename, int flags)
38 strstart(filename, "file:", &filename);
40 if (flags & URL_RDWR) {
41 access = O_CREAT | O_TRUNC | O_RDWR;
42 } else if (flags & URL_WRONLY) {
43 access = O_CREAT | O_TRUNC | O_WRONLY;
47 #if defined(CONFIG_WIN32) || defined(CONFIG_OS2) || defined(__CYGWIN__)
50 fd = open(filename, access, 0666);
53 h->priv_data = (void *)(size_t)fd;
57 static int file_read(URLContext *h, unsigned char *buf, int size)
59 int fd = (size_t)h->priv_data;
60 return read(fd, buf, size);
63 static int file_write(URLContext *h, unsigned char *buf, int size)
65 int fd = (size_t)h->priv_data;
66 return write(fd, buf, size);
70 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
72 int fd = (size_t)h->priv_data;
74 return _lseeki64(fd, pos, whence);
76 return lseek(fd, pos, whence);
80 static int file_close(URLContext *h)
82 int fd = (size_t)h->priv_data;
86 URLProtocol file_protocol = {
97 static int pipe_open(URLContext *h, const char *filename, int flags)
101 if (flags & URL_WRONLY) {
106 #if defined(CONFIG_WIN32) || defined(CONFIG_OS2) || defined(__CYGWIN__)
107 setmode(fd, O_BINARY);
109 h->priv_data = (void *)(size_t)fd;
113 static int pipe_read(URLContext *h, unsigned char *buf, int size)
115 int fd = (size_t)h->priv_data;
116 return read(fd, buf, size);
119 static int pipe_write(URLContext *h, unsigned char *buf, int size)
121 int fd = (size_t)h->priv_data;
122 return write(fd, buf, size);
125 static int pipe_close(URLContext *h)
130 URLProtocol pipe_protocol = {