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