Mercurial > audlegacy
annotate src/audacious/vfs_buffer.c @ 2574:40407b7363f3 trunk
[svn] - enforce playback stop when clearing the playlist to load new files in. closes #808.
| author | nenolod |
|---|---|
| date | Sun, 25 Feb 2007 00:53:19 -0800 |
| parents | 07b990906823 |
| children | ac22b2cb6013 |
| rev | line source |
|---|---|
| 2313 | 1 /* Audacious |
| 2 * Copyright (c) 2006-2007 William Pitcock | |
| 3 * | |
| 4 * This program is free software; you can redistribute it and/or modify | |
| 5 * it under the terms of the GNU General Public License as published by | |
| 6 * the Free Software Foundation; under version 2 of the License. | |
| 7 * | |
| 8 * This program is distributed in the hope that it will be useful, | |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 * GNU General Public License for more details. | |
| 12 * | |
| 13 * You should have received a copy of the GNU General Public License | |
| 14 * along with this program; if not, write to the Free Software | |
| 15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
| 16 * 02110-1301, USA. | |
| 17 */ | |
| 18 | |
| 19 #include <glib.h> | |
| 20 #include <string.h> | |
| 21 #include "vfs.h" | |
| 22 #include "vfs_buffer.h" | |
| 23 | |
| 24 VFSFile * | |
| 25 buffer_vfs_fopen_impl(const gchar * path, | |
| 26 const gchar * mode) | |
| 27 { | |
| 28 return NULL; | |
| 29 } | |
| 30 | |
| 31 gint | |
| 32 buffer_vfs_fclose_impl(VFSFile * file) | |
| 33 { | |
| 34 g_return_val_if_fail(file != NULL, -1); | |
| 35 | |
| 36 if (file->handle) | |
| 37 g_free(file->handle); | |
| 38 | |
| 39 return 0; | |
| 40 } | |
| 41 | |
| 42 size_t | |
| 43 buffer_vfs_fread_impl(gpointer i_ptr, | |
| 44 size_t size, | |
| 45 size_t nmemb, | |
| 46 VFSFile * file) | |
| 47 { | |
| 48 VFSBuffer *handle; | |
| 49 guchar *i; | |
| 50 size_t read = 0; | |
| 51 guchar *ptr = (guchar *) i_ptr; | |
| 52 | |
| 53 if (file == NULL) | |
| 54 return 0; | |
| 55 | |
| 56 handle = (VFSBuffer *) file->handle; | |
| 57 | |
|
2518
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
58 for (i = ptr; (gsize) (i - ptr) < nmemb * size && |
|
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
59 (gsize) (i - ptr) <= handle->size; |
|
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
60 i++, handle->iter++) |
| 2313 | 61 { |
| 62 *i = *handle->iter; | |
| 63 read++; | |
| 64 } | |
| 65 | |
|
2342
f140d0a27093
[svn] - use vfs_rewind() instead of vfs_fseek(fd, 0, seek_set) which was wrong
nenolod
parents:
2332
diff
changeset
|
66 return (read / size); |
| 2313 | 67 } |
| 68 | |
| 69 size_t | |
| 70 buffer_vfs_fwrite_impl(gconstpointer i_ptr, | |
| 71 size_t size, | |
| 72 size_t nmemb, | |
| 73 VFSFile * file) | |
| 74 { | |
| 75 VFSBuffer *handle; | |
| 76 const guchar *i; | |
| 77 size_t written = 0; | |
| 78 const guchar *ptr = (const guchar *) i_ptr; | |
| 79 | |
| 80 if (file == NULL) | |
| 81 return 0; | |
| 82 | |
| 83 handle = (VFSBuffer *) file->handle; | |
| 84 | |
|
2518
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
85 for (i = ptr; (gsize) (i - ptr) < nmemb * size && |
|
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
86 (gsize) (i - ptr) <= handle->size; |
|
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
87 i++, handle->iter++) |
| 2313 | 88 { |
| 89 *handle->iter = *i; | |
| 90 written++; | |
| 91 } | |
| 92 | |
|
2342
f140d0a27093
[svn] - use vfs_rewind() instead of vfs_fseek(fd, 0, seek_set) which was wrong
nenolod
parents:
2332
diff
changeset
|
93 return (written / size); |
| 2313 | 94 } |
| 95 | |
| 96 gint | |
| 97 buffer_vfs_getc_impl(VFSFile *stream) | |
| 98 { | |
| 99 VFSBuffer *handle = (VFSBuffer *) stream->handle; | |
| 100 gint c; | |
| 101 | |
| 102 c = *handle->iter; | |
| 103 handle->iter++; | |
| 104 | |
| 105 return c; | |
| 106 } | |
| 107 | |
| 108 gint | |
| 109 buffer_vfs_ungetc_impl(gint c, VFSFile *stream) | |
| 110 { | |
| 111 return -1; | |
| 112 } | |
| 113 | |
| 114 gint | |
| 115 buffer_vfs_fseek_impl(VFSFile * file, | |
| 116 glong offset, | |
| 117 gint whence) | |
| 118 { | |
| 119 VFSBuffer *handle; | |
| 120 | |
| 121 if (file == NULL) | |
| 122 return 0; | |
| 123 | |
| 124 handle = (VFSBuffer *) file->handle; | |
| 125 | |
| 126 switch(whence) | |
| 127 { | |
| 128 case SEEK_CUR: | |
| 129 handle->iter = handle->iter + offset; | |
| 130 break; | |
| 131 case SEEK_END: | |
| 132 handle->iter = handle->end; | |
| 133 break; | |
| 134 case SEEK_SET: | |
| 135 default: | |
| 136 handle->iter = handle->data + offset; | |
| 137 break; | |
| 138 } | |
| 139 | |
| 140 return 0; | |
| 141 } | |
| 142 | |
| 143 void | |
| 144 buffer_vfs_rewind_impl(VFSFile * file) | |
| 145 { | |
| 146 VFSBuffer *handle; | |
| 147 | |
| 148 if (file == NULL) | |
| 149 return; | |
| 150 | |
| 151 handle = (VFSBuffer *) file->handle; | |
| 152 | |
| 153 handle->iter = handle->data; | |
| 154 } | |
| 155 | |
| 156 glong | |
| 157 buffer_vfs_ftell_impl(VFSFile * file) | |
| 158 { | |
| 159 VFSBuffer *handle; | |
| 160 | |
| 161 if (file == NULL) | |
| 162 return 0; | |
| 163 | |
| 164 handle = (VFSBuffer *) file->handle; | |
| 165 | |
| 166 return handle->iter - handle->data; | |
| 167 } | |
| 168 | |
| 169 gboolean | |
| 170 buffer_vfs_feof_impl(VFSFile * file) | |
| 171 { | |
| 172 VFSBuffer *handle; | |
| 173 | |
| 174 if (file == NULL) | |
| 175 return FALSE; | |
| 176 | |
| 177 handle = (VFSBuffer *) file->handle; | |
| 178 | |
| 179 return (gboolean) (handle->iter == handle->end); | |
| 180 } | |
| 181 | |
| 182 gint | |
| 183 buffer_vfs_truncate_impl(VFSFile * file, glong size) | |
| 184 { | |
| 185 return 0; | |
| 186 } | |
| 187 | |
| 188 VFSConstructor buffer_const = { | |
| 189 NULL, // not a normal VFS class | |
| 190 buffer_vfs_fopen_impl, | |
| 191 buffer_vfs_fclose_impl, | |
| 192 buffer_vfs_fread_impl, | |
| 193 buffer_vfs_fwrite_impl, | |
| 194 buffer_vfs_getc_impl, | |
| 195 buffer_vfs_ungetc_impl, | |
| 196 buffer_vfs_fseek_impl, | |
| 197 buffer_vfs_rewind_impl, | |
| 198 buffer_vfs_ftell_impl, | |
| 199 buffer_vfs_feof_impl, | |
|
2518
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
200 buffer_vfs_truncate_impl, |
|
4c9910af4cc5
[svn] - fix signed vs unsigned comparisons and missing initializer warnings
nenolod
parents:
2344
diff
changeset
|
201 NULL |
| 2313 | 202 }; |
| 203 | |
| 204 VFSFile * | |
| 205 vfs_buffer_new(gpointer data, gsize size) | |
| 206 { | |
| 207 VFSFile *handle; | |
| 208 VFSBuffer *buffer; | |
| 209 | |
| 210 g_return_val_if_fail(data != NULL, NULL); | |
| 211 g_return_val_if_fail(size > 0, NULL); | |
| 212 | |
| 213 handle = g_new0(VFSFile, 1); | |
| 214 | |
| 215 buffer = g_new0(VFSBuffer, 1); | |
| 216 buffer->data = data; | |
| 217 buffer->iter = data; | |
|
2519
793ede082399
[svn] - fix: vfs_buffer.c:218: warning: pointer of type 'void *' used in arithmetic
nenolod
parents:
2518
diff
changeset
|
218 buffer->end = (guchar *) data + size; |
| 2313 | 219 buffer->size = size; |
| 220 | |
| 221 handle->handle = buffer; | |
| 222 handle->base = &buffer_const; | |
|
2562
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2519
diff
changeset
|
223 handle->ref = 1; |
| 2313 | 224 |
| 225 return handle; | |
| 226 } | |
| 227 | |
| 228 VFSFile * | |
| 229 vfs_buffer_new_from_string(gchar *str) | |
| 230 { | |
| 231 g_return_val_if_fail(str != NULL, NULL); | |
| 232 | |
| 233 return vfs_buffer_new(str, strlen(str)); | |
| 234 } |
