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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* This program is free software; you can redistribute it and/or modify
1460
411b4aaf928b [svn] fine
nemo
parents: 1459
diff changeset
2 * it under the terms of the GNU General Public License as published by
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
13 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 #include "vfs.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #include <sys/types.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 struct _VFSFile {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 FILE *handle;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 vfs_init(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 VFSFile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 vfs_fopen(const gchar * path,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 const gchar * mode)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 VFSFile *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40
550
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
41 if (!path || !mode)
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
42 return NULL;
adee87ebe853 [svn] Sanity checking inside vfs_() functions.
nenolod
parents: 0
diff changeset
43
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 file = g_new(VFSFile, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 file->handle = fopen(path, mode);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 if (file->handle == NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 file = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 vfs_fclose(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 gint ret = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
61 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
62 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
63
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 if (file->handle) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 if (fclose(file->handle) != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 ret = -1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 vfs_fread(gpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
80 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
81 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
82
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 return fread(ptr, size, nmemb, file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 size_t
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 vfs_fwrite(gconstpointer ptr,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 size_t size,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 size_t nmemb,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
92 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
93 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
94
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 return fwrite(ptr, size, nmemb, file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 vfs_fseek(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
115 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
116 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
117
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 return fseek(file->handle, offset, whence);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 vfs_rewind(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
124 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
125 return;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
126
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 rewind(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 glong
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 vfs_ftell(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
133 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
134 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
135
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 return ftell(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
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
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
142 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
143 return FALSE;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
144
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 vfs_file_test(const gchar * path, GFileTest test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 return g_file_test(path, test);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 /* NOTE: stat() is not part of stdio */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 vfs_is_writeable(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 struct stat info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 if (stat(path, &info) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 return (info.st_mode & S_IWUSR);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 vfs_truncate(VFSFile * file, glong size)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
169 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
170 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
171
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 return ftruncate(fileno(file->handle), size);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 }