Mercurial > audlegacy
comparison libaudacious/vfs_stdio.c @ 0:cb178e5ad177 trunk
[svn] Import audacious source.
author | nenolod |
---|---|
date | Mon, 24 Oct 2005 03:06:47 -0700 |
parents | |
children | adee87ebe853 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb178e5ad177 |
---|---|
1 /* This program is free software; you can redistribute it and/or modify | |
2 * it under the terms of the GNU General Public Licensse as published by | |
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 | |
13 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
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 | |
41 file = g_new(VFSFile, 1); | |
42 | |
43 file->handle = fopen(path, mode); | |
44 | |
45 if (file->handle == NULL) { | |
46 g_free(file); | |
47 file = NULL; | |
48 } | |
49 | |
50 return file; | |
51 } | |
52 | |
53 gint | |
54 vfs_fclose(VFSFile * file) | |
55 { | |
56 gint ret = 0; | |
57 | |
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 { | |
74 return fread(ptr, size, nmemb, file->handle); | |
75 } | |
76 | |
77 size_t | |
78 vfs_fwrite(gconstpointer ptr, | |
79 size_t size, | |
80 size_t nmemb, | |
81 VFSFile * file) | |
82 { | |
83 return fwrite(ptr, size, nmemb, file->handle); | |
84 } | |
85 | |
86 gint | |
87 vfs_fseek(VFSFile * file, | |
88 glong offset, | |
89 gint whence) | |
90 { | |
91 return fseek(file->handle, offset, whence); | |
92 } | |
93 | |
94 void | |
95 vfs_rewind(VFSFile * file) | |
96 { | |
97 rewind(file->handle); | |
98 } | |
99 | |
100 glong | |
101 vfs_ftell(VFSFile * file) | |
102 { | |
103 return ftell(file->handle); | |
104 } | |
105 | |
106 gboolean | |
107 vfs_file_test(const gchar * path, GFileTest test) | |
108 { | |
109 return g_file_test(path, test); | |
110 } | |
111 | |
112 /* NOTE: stat() is not part of stdio */ | |
113 gboolean | |
114 vfs_is_writeable(const gchar * path) | |
115 { | |
116 struct stat info; | |
117 | |
118 if (stat(path, &info) == -1) | |
119 return FALSE; | |
120 | |
121 return (info.st_mode & S_IWUSR); | |
122 } | |
123 | |
124 gint | |
125 vfs_truncate(VFSFile * file, glong size) | |
126 { | |
127 return ftruncate(fileno(file->handle), size); | |
128 } |