annotate src/audacious/vfs_buffered_file.c @ 3583:d3ba8bcf9fd6 trunk

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 19 Sep 2007 17:47:18 +0300
parents 732abc5c1714
children 2cc7e450e08e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2896
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
1 /* Audacious
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
2 * Copyright (c) 2006-2007 William Pitcock
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
3 *
2896
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
4 * This program is free software; you can redistribute it and/or modify
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
5 * it under the terms of the GNU General Public License as published by
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 2896
diff changeset
6 * the Free Software Foundation; under version 3 of the License.
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
7 *
2896
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
8 * This program is distributed in the hope that it will be useful,
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
11 * GNU General Public License for more details.
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
12 *
2896
51dda959be4d Backed out changeset 7d3beedf1db8677dab2327bc8d85af4746344f6e
William Pitcock <nenolod@atheme.org>
parents: 2861
diff changeset
13 * You should have received a copy of the GNU General Public License
3121
3b6d316f8b09 GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents: 2896
diff changeset
14 * along with this program. If not, see <http://www.gnu.org/licenses>.
3123
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
15 *
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
16 * The Audacious team does not consider modular code linking to
f1c756f39e6c Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents: 3121
diff changeset
17 * Audacious or using our public API to be a derived work.
2341
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
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
20 #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
21 #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
22 #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
23 #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
24 #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
25
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
26 VFSFile *
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
27 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
28 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
29 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
30 return NULL;
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
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
33 gint
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
34 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
35 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
36 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
37
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
38 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
39 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
40 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
41
2589
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
42 if (handle->fd != NULL)
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
43 vfs_fclose(handle->fd);
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
44
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
45 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
46 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
47 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
48 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
49
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
50 return 0;
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
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
53 size_t
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
54 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
55 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
56 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
57 VFSFile * file)
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
58 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
59 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
60
2372
d68e6f302855 [svn] - that should have been in vfs_fread
nenolod
parents: 2371
diff changeset
61 /* is this request within the buffered area, or should we switch to
d68e6f302855 [svn] - that should have been in vfs_fread
nenolod
parents: 2371
diff changeset
62 * an FD? --nenolod
d68e6f302855 [svn] - that should have been in vfs_fread
nenolod
parents: 2371
diff changeset
63 */
2647
2afc8e31a378 [svn] - this probably fixes bug #858
nenolod
parents: 2622
diff changeset
64 if (handle->which == FALSE &&
2afc8e31a378 [svn] - this probably fixes bug #858
nenolod
parents: 2622
diff changeset
65 (vfs_ftell(handle->buffer)) + (size * nmemb) >
2372
d68e6f302855 [svn] - that should have been in vfs_fread
nenolod
parents: 2371
diff changeset
66 ((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
67 {
ca5b5523cc2d [svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents: 2382
diff changeset
68 vfs_fseek(handle->fd, vfs_ftell(handle->buffer), SEEK_SET);
2372
d68e6f302855 [svn] - that should have been in vfs_fread
nenolod
parents: 2371
diff changeset
69 handle->which = TRUE;
2429
ca5b5523cc2d [svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents: 2382
diff changeset
70 }
2372
d68e6f302855 [svn] - that should have been in vfs_fread
nenolod
parents: 2371
diff changeset
71
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
72 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
73 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
74
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
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
76 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
77 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
78 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
79 VFSFile * file)
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 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
82
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
83 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
84 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
85
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
86 gint
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
87 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
88 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
89 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
90
2371
3b8b7d4dc10b [svn] - possible fix for VFSBufferedFile crash
nenolod
parents: 2341
diff changeset
91 /* is this request within the buffered area, or should we switch to
3b8b7d4dc10b [svn] - possible fix for VFSBufferedFile crash
nenolod
parents: 2341
diff changeset
92 * an FD? --nenolod
3b8b7d4dc10b [svn] - possible fix for VFSBufferedFile crash
nenolod
parents: 2341
diff changeset
93 */
2382
d41965d1806a [svn] - in vfs_buffered_file, we should only switch to live FD after 32768,
nenolod
parents: 2379
diff changeset
94 if ((vfs_ftell(handle->buffer)) + 1 >
2371
3b8b7d4dc10b [svn] - possible fix for VFSBufferedFile crash
nenolod
parents: 2341
diff changeset
95 ((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
96 {
ca5b5523cc2d [svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents: 2382
diff changeset
97 vfs_fseek(handle->fd, vfs_ftell(handle->buffer), SEEK_SET);
2371
3b8b7d4dc10b [svn] - possible fix for VFSBufferedFile crash
nenolod
parents: 2341
diff changeset
98 handle->which = TRUE;
2429
ca5b5523cc2d [svn] - fix an offset error in the vfs_buffered_file wraparound implementation sections
nenolod
parents: 2382
diff changeset
99 }
2371
3b8b7d4dc10b [svn] - possible fix for VFSBufferedFile crash
nenolod
parents: 2341
diff changeset
100
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
101 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
102 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
103
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
104 gint
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
105 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
106 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
107 return -1;
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
108 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
109
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
110 gint
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
111 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
112 glong offset,
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
113 gint whence)
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 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
116
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
117 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
118
3138
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
119 switch(whence)
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
120 {
3138
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
121 case SEEK_END:
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
122 handle->which = TRUE;
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
123 vfs_fseek(handle->fd, offset, whence);
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
124 break;
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
125 case SEEK_CUR:
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
126 if (vfs_ftell(handle->buffer) + offset > ((VFSBuffer *) handle->buffer->handle)->size)
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
127 {
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
128 handle->which = TRUE;
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
129 vfs_fseek(handle->fd, offset, whence);
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
130 }
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
131 break;
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
132 case SEEK_SET:
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
133 default:
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
134 if (offset > ((VFSBuffer *) handle->buffer->handle)->size)
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
135 {
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
136 handle->which = TRUE;
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
137 vfs_fseek(handle->fd, offset, whence);
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
138 }
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
139 else
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
140 {
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
141 handle->which = FALSE;
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
142 vfs_fseek(handle->buffer, offset, whence);
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
143 }
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
144 break;
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
145 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
146 return 0;
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
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
149 void
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
150 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
151 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
152 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
153
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
154 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
155 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
156 }
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 glong
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
159 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
160 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
161 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
162
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
163 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
164 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
165
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
166 gboolean
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
167 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
168 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
169 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
170
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
171 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
172 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
173
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
174 gint
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_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
176 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
177 return 0;
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
178 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
179
2688
ertzing
parents: 2647
diff changeset
180 off_t
ertzing
parents: 2647
diff changeset
181 buffered_file_vfs_fsize_impl(VFSFile * file)
ertzing
parents: 2647
diff changeset
182 {
ertzing
parents: 2647
diff changeset
183 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle;
ertzing
parents: 2647
diff changeset
184
3140
732abc5c1714 Fix VFSBufferedFile::fsize().
William Pitcock <nenolod@atheme-project.org>
parents: 3138
diff changeset
185 return vfs_fsize(handle->fd);
2688
ertzing
parents: 2647
diff changeset
186 }
ertzing
parents: 2647
diff changeset
187
2588
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
188 gchar *
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
189 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
190 {
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
191 VFSBufferedFile *handle = (VFSBufferedFile *) file->handle;
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
192
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
193 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
194 }
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
195
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
196 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 buffered_file_vfs_feof_impl,
2588
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
208 buffered_file_vfs_truncate_impl,
2688
ertzing
parents: 2647
diff changeset
209 buffered_file_vfs_fsize_impl,
2588
c51a5a735f65 [svn] - proxy requests for metadata attached to a VFSBufferedFile to the live
nenolod
parents: 2562
diff changeset
210 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
211 };
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
212
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
213 VFSFile *
2430
4e2fc64d95ef [svn] - make vfs_buffered_file_new_from_uri declaration const
nenolod
parents: 2429
diff changeset
214 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
215 {
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
216 VFSFile *handle;
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
217 VFSBufferedFile *fd;
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
218 gsize sz;
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
219
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
220 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
221
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
222 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
223 fd = g_new0(VFSBufferedFile, 1);
2622
06e4bbdb6c45 [svn] - due to some bug in buffer management, bump the buffer side of things up to ~40kb instead of 32kb for now.
nenolod
parents: 2589
diff changeset
224 fd->mem = g_malloc0(40000);
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
225 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
226
2374
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
227 if (fd->fd == NULL)
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
228 {
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
229 g_free(fd->mem);
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
230 g_free(fd);
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
231 g_free(handle);
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
232
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
233 return NULL;
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
234 }
6c5d4d28cc6b [svn] - return NULL if vfs_fopen request failed
nenolod
parents: 2372
diff changeset
235
2622
06e4bbdb6c45 [svn] - due to some bug in buffer management, bump the buffer side of things up to ~40kb instead of 32kb for now.
nenolod
parents: 2589
diff changeset
236 sz = vfs_fread(fd->mem, 1, 40000, fd->fd);
3138
3eca96f6a73f Rewrite VFSBufferedFile::fseek(), now far less buggy!
William Pitcock <nenolod@atheme-project.org>
parents: 3123
diff changeset
237 vfs_rewind(fd->fd);
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
238
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
239 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
240 {
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
241 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
242 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
243 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
244
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
245 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
246 }
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
247
2341
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
248 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
249
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
250 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
251 handle->base = &buffered_file_const;
2561
5b761b745289 [svn] - provide fd->uri for buffered files
nenolod
parents: 2430
diff changeset
252 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
253 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
254
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
255 return handle;
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
256 }
02a850a2533b [svn] - automatically buffering deriv-class of VFSFile. will be used to speed up probing of network sources.
nenolod
parents:
diff changeset
257
2589
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
258 VFSFile *
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
259 vfs_buffered_file_release_live_fd(VFSFile *fd)
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
260 {
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
261 VFSBufferedFile *file = (VFSBufferedFile *) fd;
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
262 VFSFile *out;
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
263
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
264 g_return_val_if_fail(file != NULL, NULL);
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
265
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
266 out = file->fd;
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
267 file->fd = NULL;
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
268
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
269 vfs_fclose(fd);
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
270
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
271 return out;
ea470384e752 [svn] - add vfs_buffered_file_release_live_fd().
nenolod
parents: 2588
diff changeset
272 }