Mercurial > audlegacy
annotate Plugins/Input/wma/libffwma/file.c @ 926:3d4af4890339 trunk
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
author | chainsaw |
---|---|
date | Wed, 12 Apr 2006 13:35:24 -0700 |
parents | d539e5c5f730 |
children | a63e0fdb3d1e |
rev | line source |
---|---|
137 | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
255
ad1e65c6a854
[svn] Create some proper headers and include them. No more implicit declarations.
chainsaw
parents:
218
diff
changeset
|
20 #include "cutils.h" |
137 | 21 #include <fcntl.h> |
22 #include <unistd.h> | |
23 #include <sys/ioctl.h> | |
24 #include <sys/time.h> | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
25 #include "libaudacious/vfs.h" |
137 | 26 |
27 /* standard file protocol */ | |
28 | |
29 static int file_open(URLContext *h, const char *filename, int flags) | |
30 { | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
31 VFSFile *file; |
137 | 32 |
33 strstart(filename, "file:", &filename); | |
34 | |
35 if (flags & URL_WRONLY) { | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
36 file = vfs_fopen(filename, "wb"); |
137 | 37 } else { |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
38 file = vfs_fopen(filename, "rb"); |
137 | 39 } |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
40 |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
41 if (file == NULL) |
137 | 42 return -ENOENT; |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
43 h->priv_data = file; |
137 | 44 return 0; |
45 } | |
46 | |
47 static int file_read(URLContext *h, unsigned char *buf, int size) | |
48 { | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
49 VFSFile *file; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
50 file = h->priv_data; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
51 return vfs_fread(buf, 1, size, file); |
137 | 52 } |
53 | |
54 static int file_write(URLContext *h, unsigned char *buf, int size) | |
55 { | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
56 VFSFile *file; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
57 file = h->priv_data; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
58 return vfs_fwrite(buf, 1, size, file); |
137 | 59 } |
60 | |
61 /* XXX: use llseek */ | |
62 static offset_t file_seek(URLContext *h, offset_t pos, int whence) | |
63 { | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
64 int result = 0; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
65 VFSFile *file; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
66 file = h->priv_data; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
67 result = vfs_fseek(file, pos, whence); |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
68 if (result == 0) |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
69 result = vfs_ftell(file); |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
70 else |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
71 result = -1; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
72 return result; |
137 | 73 } |
74 | |
75 static int file_close(URLContext *h) | |
76 { | |
926
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
77 VFSFile *file; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
78 file = h->priv_data; |
3d4af4890339
[svn] Conversion of file operations to VFS. Needs stress testing, especially on Gnome-VFS.
chainsaw
parents:
701
diff
changeset
|
79 return vfs_fclose(file); |
137 | 80 } |
81 | |
82 URLProtocol file_protocol = { | |
83 "file", | |
84 file_open, | |
85 file_read, | |
86 file_write, | |
87 file_seek, | |
88 file_close, | |
701
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
258
diff
changeset
|
89 NULL |
137 | 90 }; |
91 | |
92 /* pipe protocol */ | |
93 | |
94 static int pipe_open(URLContext *h, const char *filename, int flags) | |
95 { | |
96 int fd; | |
97 | |
98 if (flags & URL_WRONLY) { | |
99 fd = 1; | |
100 } else { | |
101 fd = 0; | |
102 } | |
258 | 103 h->priv_data = (void *)(long)fd; |
137 | 104 return 0; |
105 } | |
106 | |
107 static int pipe_read(URLContext *h, unsigned char *buf, int size) | |
108 { | |
258 | 109 int fd = (int)(long)h->priv_data; |
137 | 110 return read(fd, buf, size); |
111 } | |
112 | |
113 static int pipe_write(URLContext *h, unsigned char *buf, int size) | |
114 { | |
258 | 115 int fd = (int)(long)h->priv_data; |
137 | 116 return write(fd, buf, size); |
117 } | |
118 | |
119 static int pipe_close(URLContext *h) | |
120 { | |
121 return 0; | |
122 } | |
123 | |
124 URLProtocol pipe_protocol = { | |
125 "pipe", | |
126 pipe_open, | |
127 pipe_read, | |
128 pipe_write, | |
129 NULL, | |
130 pipe_close, | |
701
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
258
diff
changeset
|
131 NULL |
137 | 132 }; |