Mercurial > audlegacy
annotate libaudacious/vfs.c @ 1976:8045625b45d3 trunk
[svn] - remove shadowed struct _VFSFile.
author | nenolod |
---|---|
date | Thu, 16 Nov 2006 11:21:05 -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 gboolean | |
24 vfs_init(void) | |
25 { | |
26 return TRUE; | |
27 } | |
28 | |
29 VFSFile * | |
30 vfs_fopen(const gchar * path, | |
31 const gchar * mode) | |
32 { | |
33 VFSFile *file; | |
34 | |
550 | 35 if (!path || !mode) |
36 return NULL; | |
37 | |
0 | 38 file = g_new(VFSFile, 1); |
39 | |
40 file->handle = fopen(path, mode); | |
41 | |
42 if (file->handle == NULL) { | |
43 g_free(file); | |
44 file = NULL; | |
45 } | |
46 | |
47 return file; | |
48 } | |
49 | |
50 gint | |
51 vfs_fclose(VFSFile * file) | |
52 { | |
53 gint ret = 0; | |
54 | |
821 | 55 if (file == NULL) |
56 return -1; | |
57 | |
0 | 58 if (file->handle) { |
59 if (fclose(file->handle) != 0) | |
60 ret = -1; | |
61 } | |
62 | |
63 g_free(file); | |
64 | |
65 return ret; | |
66 } | |
67 | |
68 size_t | |
69 vfs_fread(gpointer ptr, | |
70 size_t size, | |
71 size_t nmemb, | |
72 VFSFile * file) | |
73 { | |
821 | 74 if (file == NULL) |
75 return 0; | |
76 | |
0 | 77 return fread(ptr, size, nmemb, file->handle); |
78 } | |
79 | |
80 size_t | |
81 vfs_fwrite(gconstpointer ptr, | |
82 size_t size, | |
83 size_t nmemb, | |
84 VFSFile * file) | |
85 { | |
821 | 86 if (file == NULL) |
87 return 0; | |
88 | |
0 | 89 return fwrite(ptr, size, nmemb, file->handle); |
90 } | |
91 | |
92 gint | |
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
|
93 vfs_getc(VFSFile *stream) |
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 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
|
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 |
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
|
99 vfs_ungetc(gint c, VFSFile *stream) |
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
|
100 { |
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
|
101 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
|
102 } |
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
|
103 |
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
|
104 gint |
0 | 105 vfs_fseek(VFSFile * file, |
106 glong offset, | |
107 gint whence) | |
108 { | |
821 | 109 if (file == NULL) |
110 return 0; | |
111 | |
0 | 112 return fseek(file->handle, offset, whence); |
113 } | |
114 | |
115 void | |
116 vfs_rewind(VFSFile * file) | |
117 { | |
821 | 118 if (file == NULL) |
119 return; | |
120 | |
0 | 121 rewind(file->handle); |
122 } | |
123 | |
124 glong | |
125 vfs_ftell(VFSFile * file) | |
126 { | |
821 | 127 if (file == NULL) |
128 return 0; | |
129 | |
0 | 130 return ftell(file->handle); |
131 } | |
132 | |
133 gboolean | |
811
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
134 vfs_feof(VFSFile * file) |
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
135 { |
821 | 136 if (file == NULL) |
137 return FALSE; | |
138 | |
139 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
|
140 } |
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
141 |
86ca43d8a845
[svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents:
550
diff
changeset
|
142 gboolean |
0 | 143 vfs_file_test(const gchar * path, GFileTest test) |
144 { | |
145 return g_file_test(path, test); | |
146 } | |
147 | |
148 /* NOTE: stat() is not part of stdio */ | |
149 gboolean | |
150 vfs_is_writeable(const gchar * path) | |
151 { | |
152 struct stat info; | |
153 | |
154 if (stat(path, &info) == -1) | |
155 return FALSE; | |
156 | |
157 return (info.st_mode & S_IWUSR); | |
158 } | |
159 | |
160 gint | |
161 vfs_truncate(VFSFile * file, glong size) | |
162 { | |
821 | 163 if (file == NULL) |
164 return -1; | |
165 | |
0 | 166 return ftruncate(fileno(file->handle), size); |
167 } |