comparison src/ffmpeg/libffwma/file.c @ 806:74abcb9cafae trunk

[svn] - fork wma plugin
author nenolod
date Mon, 12 Mar 2007 10:59:21 -0700
parents src/wma/libffwma/file.c@4ddafd821a25
children
comparison
equal deleted inserted replaced
805:1ba5f86aeac9 806:74abcb9cafae
1 /*
2 * Buffered file io for ffmpeg system
3 * Copyright (c) 2001 Fabrice Bellard
4 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 #include "avformat.h"
20 #include "cutils.h"
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <sys/ioctl.h>
24 #include <sys/time.h>
25 #include "audacious/vfs.h"
26
27 /* standard file protocol */
28
29 static int file_open(URLContext *h, const char *filename, int flags)
30 {
31 VFSFile *file;
32
33 strstart(filename, "file:", &filename);
34
35 if (flags & URL_WRONLY) {
36 file = vfs_fopen(filename, "wb");
37 } else {
38 file = vfs_fopen(filename, "rb");
39 }
40
41 if (file == NULL)
42 return -ENOENT;
43 h->priv_data = file;
44 return 0;
45 }
46
47 static int file_read(URLContext *h, unsigned char *buf, int size)
48 {
49 VFSFile *file;
50 file = h->priv_data;
51 return vfs_fread(buf, 1, size, file);
52 }
53
54 static int file_write(URLContext *h, unsigned char *buf, int size)
55 {
56 VFSFile *file;
57 file = h->priv_data;
58 return vfs_fwrite(buf, 1, size, file);
59 }
60
61 /* XXX: use llseek */
62 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
63 {
64 int result = 0;
65 VFSFile *file;
66 file = h->priv_data;
67 result = vfs_fseek(file, pos, whence);
68 if (result == 0)
69 result = vfs_ftell(file);
70 else
71 result = -1;
72 return result;
73 }
74
75 static int file_close(URLContext *h)
76 {
77 VFSFile *file;
78 file = h->priv_data;
79 return vfs_fclose(file);
80 }
81
82 URLProtocol file_protocol = {
83 "file",
84 file_open,
85 file_read,
86 file_write,
87 file_seek,
88 file_close,
89 NULL
90 };
91