Mercurial > audlegacy
annotate libaudacious/vfs_stdio.c @ 1982:cf33371e7ac3 trunk
[svn] - enhancements to the NewVFS probing layer.
author | nenolod |
---|---|
date | Sat, 18 Nov 2006 19:44:58 -0800 |
parents | 976da06332df |
children | 93c59698f5fd |
rev | line source |
---|---|
0 | 1 /* This program is free software; you can redistribute it and/or modify |
1460 | 2 * it under the terms of the GNU General Public License as published by |
0 | 3 * the Free Software Foundation; either version 2 of the License, or |
4 * (at your option) any later version. | |
5 * | |
6 * This program is distributed in the hope that it will be useful, | |
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 * GNU General Public License for more details. | |
10 * | |
11 * You should have received a copy of the GNU General Public License | |
12 * along with this program; if not, write to the Free Software | |
1459 | 13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 14 */ |
15 | |
16 #include "vfs.h" | |
17 #include <stdio.h> | |
18 | |
19 #include <unistd.h> | |
20 #include <sys/stat.h> | |
21 #include <sys/types.h> | |
22 | |
23 VFSFile * | |
1975 | 24 stdio_vfs_fopen_impl(const gchar * path, |
0 | 25 const gchar * mode) |
26 { | |
27 VFSFile *file; | |
28 | |
550 | 29 if (!path || !mode) |
30 return NULL; | |
31 | |
0 | 32 file = g_new(VFSFile, 1); |
33 | |
34 file->handle = fopen(path, mode); | |
35 | |
36 if (file->handle == NULL) { | |
37 g_free(file); | |
38 file = NULL; | |
39 } | |
40 | |
41 return file; | |
42 } | |
43 | |
44 gint | |
1975 | 45 stdio_vfs_fclose_impl(VFSFile * file) |
0 | 46 { |
47 gint ret = 0; | |
48 | |
821 | 49 if (file == NULL) |
50 return -1; | |
51 | |
0 | 52 if (file->handle) { |
53 if (fclose(file->handle) != 0) | |
54 ret = -1; | |
55 } | |
56 | |
57 g_free(file); | |
58 | |
59 return ret; | |
60 } | |
61 | |
62 size_t | |
1975 | 63 stdio_vfs_fread_impl(gpointer ptr, |
0 | 64 size_t size, |
65 size_t nmemb, | |
66 VFSFile * file) | |
67 { | |
821 | 68 if (file == NULL) |
69 return 0; | |
70 | |
0 | 71 return fread(ptr, size, nmemb, file->handle); |
72 } | |
73 | |
74 size_t | |
1975 | 75 stdio_vfs_fwrite_impl(gconstpointer ptr, |
0 | 76 size_t size, |
77 size_t nmemb, | |
78 VFSFile * file) | |
79 { | |
821 | 80 if (file == NULL) |
81 return 0; | |
82 | |
0 | 83 return fwrite(ptr, size, nmemb, file->handle); |
84 } | |
85 | |
86 gint | |
1975 | 87 stdio_vfs_getc_impl(VFSFile *stream) |
1683
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
88 { |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
89 return getc( stream->handle ); |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
90 } |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
91 |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
92 gint |
1975 | 93 stdio_vfs_ungetc_impl(gint c, VFSFile *stream) |
1683
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
94 { |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
95 return ungetc( c , stream->handle ); |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
96 } |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
97 |
e9c24e35bd76
[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
giacomo
parents:
1460
diff
changeset
|
98 gint |
1975 | 99 stdio_vfs_fseek_impl(VFSFile * file, |
0 | 100 glong offset, |
101 gint whence) | |
102 { | |
821 | 103 if (file == NULL) |
104 return 0; | |
105 | |
0 | 106 return fseek(file->handle, offset, whence); |
107 } | |
108 | |
109 void | |
1975 | 110 stdio_vfs_rewind_impl(VFSFile * file) |
0 | 111 { |
821 | 112 if (file == NULL) |
113 return; | |
114 | |
0 | 115 rewind(file->handle); |
116 } | |
117 | |
118 glong | |
1975 | 119 stdio_vfs_ftell_impl(VFSFile * file) |
0 | 120 { |
821 | 121 if (file == NULL) |
122 return 0; | |
123 | |
0 | 124 return ftell(file->handle); |
125 } | |
126 | |
127 gboolean | |
1975 | 128 stdio_vfs_feof_impl(VFSFile * file) |
811
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
129 { |
821 | 130 if (file == NULL) |
131 return FALSE; | |
132 | |
133 return (gboolean) feof(file->handle); | |
811
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
134 } |
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
135 |
0 | 136 gint |
1975 | 137 stdio_vfs_truncate_impl(VFSFile * file, glong size) |
0 | 138 { |
821 | 139 if (file == NULL) |
140 return -1; | |
141 | |
0 | 142 return ftruncate(fileno(file->handle), size); |
143 } | |
1975 | 144 |
145 VFSConstructor file_const = { | |
146 "file://", | |
147 stdio_vfs_fopen_impl, | |
148 stdio_vfs_fclose_impl, | |
149 stdio_vfs_fread_impl, | |
150 stdio_vfs_fwrite_impl, | |
151 stdio_vfs_getc_impl, | |
152 stdio_vfs_ungetc_impl, | |
153 stdio_vfs_fseek_impl, | |
154 stdio_vfs_rewind_impl, | |
155 stdio_vfs_ftell_impl, | |
156 stdio_vfs_feof_impl, | |
157 stdio_vfs_truncate_impl | |
158 }; | |
159 | |
160 VFSConstructor default_const = { | |
161 "/", | |
162 stdio_vfs_fopen_impl, | |
163 stdio_vfs_fclose_impl, | |
164 stdio_vfs_fread_impl, | |
165 stdio_vfs_fwrite_impl, | |
166 stdio_vfs_getc_impl, | |
167 stdio_vfs_ungetc_impl, | |
168 stdio_vfs_fseek_impl, | |
169 stdio_vfs_rewind_impl, | |
170 stdio_vfs_ftell_impl, | |
171 stdio_vfs_feof_impl, | |
172 stdio_vfs_truncate_impl | |
173 }; | |
174 | |
175 #if 0 | |
176 gboolean | |
177 vfs_init(void) | |
178 { | |
179 vfs_register_transport(&default_const); | |
180 vfs_register_transport(&file_const); | |
181 return TRUE; | |
182 } | |
183 #endif |