annotate libaudacious/vfs_stdio.c @ 838:90a8a5e47d7f trunk

[svn] - equalizer improvements
author nenolod
date Fri, 17 Mar 2006 19:11:49 -0800
parents a17888ed66a8
children f12d7e208b43
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * it under the terms of the GNU General Public Licensse as published by
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 vfs_fseek(VFSFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 glong offset,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 gint whence)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
103 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
104 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
105
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 return fseek(file->handle, offset, whence);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 vfs_rewind(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
112 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
113 return;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
114
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 rewind(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 glong
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 vfs_ftell(VFSFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
121 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
122 return 0;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
123
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 return ftell(file->handle);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 gboolean
811
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
128 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
129 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
130 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
131 return FALSE;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
132
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
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
86ca43d8a845 [svn] - implement vfs_feof() and vfs_ftell() and update the scrobbler plugin to reflect that,
nenolod
parents: 550
diff changeset
136 gboolean
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 vfs_file_test(const gchar * path, GFileTest test)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 return g_file_test(path, test);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 /* NOTE: stat() is not part of stdio */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 vfs_is_writeable(const gchar * path)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 struct stat info;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 if (stat(path, &info) == -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 return (info.st_mode & S_IWUSR);
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 gint
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 vfs_truncate(VFSFile * file, glong size)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 {
821
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
157 if (file == NULL)
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
158 return -1;
a17888ed66a8 [svn] - safety checks
nenolod
parents: 811
diff changeset
159
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 return ftruncate(fileno(file->handle), size);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 }