0
|
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
|
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
|
|
61 if (file->handle) {
|
|
62 if (fclose(file->handle) != 0)
|
|
63 ret = -1;
|
|
64 }
|
|
65
|
|
66 g_free(file);
|
|
67
|
|
68 return ret;
|
|
69 }
|
|
70
|
|
71 size_t
|
|
72 vfs_fread(gpointer ptr,
|
|
73 size_t size,
|
|
74 size_t nmemb,
|
|
75 VFSFile * file)
|
|
76 {
|
|
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 {
|
|
86 return fwrite(ptr, size, nmemb, file->handle);
|
|
87 }
|
|
88
|
|
89 gint
|
|
90 vfs_fseek(VFSFile * file,
|
|
91 glong offset,
|
|
92 gint whence)
|
|
93 {
|
|
94 return fseek(file->handle, offset, whence);
|
|
95 }
|
|
96
|
|
97 void
|
|
98 vfs_rewind(VFSFile * file)
|
|
99 {
|
|
100 rewind(file->handle);
|
|
101 }
|
|
102
|
|
103 glong
|
|
104 vfs_ftell(VFSFile * file)
|
|
105 {
|
|
106 return ftell(file->handle);
|
|
107 }
|
|
108
|
|
109 gboolean
|
|
110 vfs_file_test(const gchar * path, GFileTest test)
|
|
111 {
|
|
112 return g_file_test(path, test);
|
|
113 }
|
|
114
|
|
115 /* NOTE: stat() is not part of stdio */
|
|
116 gboolean
|
|
117 vfs_is_writeable(const gchar * path)
|
|
118 {
|
|
119 struct stat info;
|
|
120
|
|
121 if (stat(path, &info) == -1)
|
|
122 return FALSE;
|
|
123
|
|
124 return (info.st_mode & S_IWUSR);
|
|
125 }
|
|
126
|
|
127 gint
|
|
128 vfs_truncate(VFSFile * file, glong size)
|
|
129 {
|
|
130 return ftruncate(fileno(file->handle), size);
|
|
131 }
|