Mercurial > audlegacy
annotate src/audacious/vfs_buffered_file.c @ 2608:f4fa6b295b43 trunk
[svn] - Remove even more duplicate code
author | mf0102 |
---|---|
date | Mon, 05 Mar 2007 13:50:32 -0800 |
parents | ea470384e752 |
children | 06e4bbdb6c45 |
rev | line source |
---|---|
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
1 /* Audacious |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
2 * Copyright (c) 2006-2007 William Pitcock |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
3 * |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
6 * the Free Software Foundation; under version 2 of the License. |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
7 * |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
12 * |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
13 * You should have received a copy of the GNU General Public License |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
14 * along with this program; if not, write to the Free Software |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
16 * 02110-1301, USA. |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
17 */ |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
18 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
19 #include <glib.h> |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
20 #include <string.h> |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
21 #include "vfs.h" |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
22 #include "vfs_buffer.h" |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
23 #include "vfs_buffered_file.h" |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
24 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
25 VFSFile * |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
26 buffered_file_vfs_fopen_impl(const gchar * path, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
27 const gchar * mode) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
28 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
29 return NULL; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
30 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
31 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
32 gint |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
33 buffered_file_vfs_fclose_impl(VFSFile * file) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
34 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
35 g_return_val_if_fail(file != NULL, -1); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
36 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
37 if (file->handle) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
38 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
39 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
40 |
2589 | 41 if (handle->fd != NULL) |
42 vfs_fclose(handle->fd); | |
43 | |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
44 vfs_fclose(handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
45 g_free(handle->mem); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
46 g_free(handle); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
47 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
48 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
49 return 0; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
50 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
51 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
52 size_t |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
53 buffered_file_vfs_fread_impl(gpointer i_ptr, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
54 size_t size, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
55 size_t nmemb, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
56 VFSFile * file) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
57 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
58 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
59 |
2372 | 60 /* is this request within the buffered area, or should we switch to |
61 * an FD? --nenolod | |
62 */ | |
2382
d41965d1806a
[svn] - in vfs_buffered_file, we should only switch to live FD after 32768,
nenolod
parents:
2379
diff
changeset
|
63 if ((vfs_ftell(handle->buffer)) + (size * nmemb) > |
2372 | 64 ((VFSBuffer *) handle->buffer->handle)->size) |
2429
ca5b5523cc2d
[svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents:
2382
diff
changeset
|
65 { |
ca5b5523cc2d
[svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents:
2382
diff
changeset
|
66 vfs_fseek(handle->fd, vfs_ftell(handle->buffer), SEEK_SET); |
2372 | 67 handle->which = TRUE; |
2429
ca5b5523cc2d
[svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents:
2382
diff
changeset
|
68 } |
2372 | 69 |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
70 return vfs_fread(i_ptr, size, nmemb, handle->which == TRUE ? handle->fd : handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
71 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
72 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
73 size_t |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
74 buffered_file_vfs_fwrite_impl(gconstpointer i_ptr, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
75 size_t size, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
76 size_t nmemb, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
77 VFSFile * file) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
78 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
79 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
80 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
81 return vfs_fwrite(i_ptr, size, nmemb, handle->fd); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
82 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
83 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
84 gint |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
85 buffered_file_vfs_getc_impl(VFSFile *stream) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
86 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
87 VFSBufferedFile *handle = (VFSBufferedFile *) stream->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
88 |
2371 | 89 /* is this request within the buffered area, or should we switch to |
90 * an FD? --nenolod | |
91 */ | |
2382
d41965d1806a
[svn] - in vfs_buffered_file, we should only switch to live FD after 32768,
nenolod
parents:
2379
diff
changeset
|
92 if ((vfs_ftell(handle->buffer)) + 1 > |
2371 | 93 ((VFSBuffer *) handle->buffer->handle)->size) |
2429
ca5b5523cc2d
[svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents:
2382
diff
changeset
|
94 { |
ca5b5523cc2d
[svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents:
2382
diff
changeset
|
95 vfs_fseek(handle->fd, vfs_ftell(handle->buffer), SEEK_SET); |
2371 | 96 handle->which = TRUE; |
2429
ca5b5523cc2d
[svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents:
2382
diff
changeset
|
97 } |
2371 | 98 |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
99 return vfs_getc(handle->which == TRUE ? handle->fd : handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
100 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
101 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
102 gint |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
103 buffered_file_vfs_ungetc_impl(gint c, VFSFile *stream) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
104 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
105 return -1; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
106 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
107 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
108 gint |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
109 buffered_file_vfs_fseek_impl(VFSFile * file, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
110 glong offset, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
111 gint whence) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
112 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
113 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
114 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
115 vfs_fseek(handle->buffer, offset, whence); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
116 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
117 /* if we go OOB, switch to live FD */ |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
118 if (vfs_ftell(handle->buffer) > ((VFSBuffer *) handle->buffer->handle)->size) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
119 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
120 vfs_rewind(handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
121 handle->which = TRUE; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
122 vfs_fseek(handle->buffer, offset, whence); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
123 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
124 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
125 return 0; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
126 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
127 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
128 void |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
129 buffered_file_vfs_rewind_impl(VFSFile * file) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
130 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
131 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
132 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
133 vfs_rewind(handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
134 handle->which = FALSE; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
135 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
136 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
137 glong |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
138 buffered_file_vfs_ftell_impl(VFSFile * file) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
139 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
140 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
141 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
142 return vfs_ftell(handle->which == TRUE ? handle->fd : handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
143 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
144 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
145 gboolean |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
146 buffered_file_vfs_feof_impl(VFSFile * file) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
147 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
148 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
149 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
150 return vfs_feof(handle->which == TRUE ? handle->fd : handle->buffer); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
151 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
152 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
153 gint |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
154 buffered_file_vfs_truncate_impl(VFSFile * file, glong size) |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
155 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
156 return 0; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
157 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
158 |
2588
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
159 gchar * |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
160 buffered_file_vfs_metadata_impl(VFSFile * file, const gchar * field) |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
161 { |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
162 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle; |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
163 |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
164 return vfs_get_metadata(handle->fd, field); |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
165 } |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
166 |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
167 VFSConstructor buffered_file_const = { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
168 NULL, // not a normal VFS class |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
169 buffered_file_vfs_fopen_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
170 buffered_file_vfs_fclose_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
171 buffered_file_vfs_fread_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
172 buffered_file_vfs_fwrite_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
173 buffered_file_vfs_getc_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
174 buffered_file_vfs_ungetc_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
175 buffered_file_vfs_fseek_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
176 buffered_file_vfs_rewind_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
177 buffered_file_vfs_ftell_impl, |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
178 buffered_file_vfs_feof_impl, |
2588
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
179 buffered_file_vfs_truncate_impl, |
c51a5a735f65
[svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents:
2562
diff
changeset
|
180 buffered_file_vfs_metadata_impl |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
181 }; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
182 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
183 VFSFile * |
2430
4e2fc64d95ef
[svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents:
2429
diff
changeset
|
184 vfs_buffered_file_new_from_uri(const gchar *uri) |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
185 { |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
186 VFSFile *handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
187 VFSBufferedFile *fd; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
188 gsize sz; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
189 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
190 g_return_val_if_fail(uri != NULL, NULL); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
191 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
192 handle = g_new0(VFSFile, 1); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
193 fd = g_new0(VFSBufferedFile, 1); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
194 fd->mem = g_malloc0(32768); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
195 fd->fd = vfs_fopen(uri, "rb"); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
196 |
2374 | 197 if (fd->fd == NULL) |
198 { | |
199 g_free(fd->mem); | |
200 g_free(fd); | |
201 g_free(handle); | |
202 | |
203 return NULL; | |
204 } | |
205 | |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
206 sz = vfs_fread(fd->mem, 1, 32768, fd->fd); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
207 |
2379
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
208 if (!sz) |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
209 { |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
210 g_free(fd->mem); |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
211 g_free(fd); |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
212 g_free(handle); |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
213 |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
214 return NULL; |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
215 } |
e146debd1393
[svn] Check for sz == 0 in vfs_buffered_file_new_from_uri(), return NULL if it's the case.
hansmi
parents:
2374
diff
changeset
|
216 |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
217 fd->buffer = vfs_buffer_new(fd->mem, sz); |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
218 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
219 handle->handle = fd; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
220 handle->base = &buffered_file_const; |
2561 | 221 handle->uri = g_strdup(uri); |
2562
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2561
diff
changeset
|
222 handle->ref = 1; |
2341
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
223 |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
224 return handle; |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
225 } |
02a850a2533b
[svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff
changeset
|
226 |
2589 | 227 VFSFile * |
228 vfs_buffered_file_release_live_fd(VFSFile *fd) | |
229 { | |
230 VFSBufferedFile *file = (VFSBufferedFile *) fd; | |
231 VFSFile *out; | |
232 | |
233 g_return_val_if_fail(file != NULL, NULL); | |
234 | |
235 out = file->fd; | |
236 file->fd = NULL; | |
237 | |
238 vfs_fclose(fd); | |
239 | |
240 return out; | |
241 } |