2 * Buffered file io for ffmpeg system
3 * Copyright (c) 2001 Gerard Lantau
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <sys/ioctl.h>
29 /* standard file protocol */
31 static int file_open(URLContext
*h
, const char *filename
, int flags
)
36 if (flags
& URL_WRONLY
) {
37 access
= O_CREAT
| O_TRUNC
| O_WRONLY
;
41 fd
= open(filename
, access
, 0666);
44 h
->priv_data
= (void *)fd
;
48 static int file_read(URLContext
*h
, unsigned char *buf
, int size
)
50 int fd
= (int)h
->priv_data
;
51 return read(fd
, buf
, size
);
54 static int file_write(URLContext
*h
, unsigned char *buf
, int size
)
56 int fd
= (int)h
->priv_data
;
57 return write(fd
, buf
, size
);
61 static offset_t
file_seek(URLContext
*h
, offset_t pos
, int whence
)
63 int fd
= (int)h
->priv_data
;
64 return lseek(fd
, pos
, whence
);
67 static int file_close(URLContext
*h
)
69 int fd
= (int)h
->priv_data
;
73 URLProtocol file_protocol
= {
84 static int pipe_open(URLContext
*h
, const char *filename
, int flags
)
88 if (flags
& URL_WRONLY
) {
93 h
->priv_data
= (void *)fd
;
97 static int pipe_read(URLContext
*h
, unsigned char *buf
, int size
)
99 int fd
= (int)h
->priv_data
;
100 return read(fd
, buf
, size
);
103 static int pipe_write(URLContext
*h
, unsigned char *buf
, int size
)
105 int fd
= (int)h
->priv_data
;
106 return write(fd
, buf
, size
);
109 static int pipe_close(URLContext
*h
)
114 URLProtocol pipe_protocol
= {