annotate libaudacious/vfs_common.c @ 1669:07143b97314d trunk

[svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
author chainsaw
date Mon, 11 Sep 2006 15:24:52 -0700
parents 3de4bd38fe4f
children e9c24e35bd76
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1617
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
1 /* This program is free software; you can redistribute it and/or modify
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
2 * it under the terms of the GNU General Public License as published by
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
3 * the Free Software Foundation; either version 2 of the License, or
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
4 * (at your option) any later version.
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
5 *
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
6 * This program is distributed in the hope that it will be useful,
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
9 * GNU General Public License for more details.
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
10 *
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
11 * You should have received a copy of the GNU General Public License
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
12 * along with this program; if not, write to the Free Software Foundation,
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
13 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
14 */
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
15
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
16 #include "vfs.h"
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
17 #include <string.h>
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
18 #include <stdlib.h>
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
19 #include <glib/gprintf.h>
1617
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
20
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
21 /* FIXME low performance vfs_getc */
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
22 gint vfs_getc(VFSFile *stream)
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
23 {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
24 guchar uc;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
25 if (vfs_fread(&uc, 1, 1, stream))
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
26 return uc;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
27 return EOF;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
28 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
29
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
30
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
31 gint vfs_fputc(gint c, VFSFile *stream)
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
32 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
33 guchar uc = (guchar) c;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
34
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
35 if (! vfs_fwrite(&uc, 1, 1, stream)) {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
36 return EOF;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
37 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
38
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
39 return uc;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
40 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
41
1617
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
42 gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream)
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
43 {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
44 gint c;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
45 register gchar *p;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
46
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
47 if(n<=0) return NULL;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
48
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
49 p = s;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
50
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
51 while (--n) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
52 if ((c = vfs_getc(stream))== EOF) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
53 break;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
54 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
55 if ((*p++ = c) == '\n') {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
56 break;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
57 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
58 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
59 if (p > s) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
60 *p = 0;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
61 return s;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
62 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
63
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
64 return NULL;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
65 }
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
66
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
67 int vfs_fputs(const gchar *s, VFSFile *stream)
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
68 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
69 size_t n = strlen(s);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
70
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
71 return ((vfs_fwrite(s, 1, n, stream) == n) ? n : EOF);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
72 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
73
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
74 int vfs_vfprintf(VFSFile *stream, gchar const *format, va_list args)
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
75 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
76 gchar *string;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
77 gint rv = g_vasprintf(&string, format, args);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
78 if (rv<0) return rv;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
79 rv = vfs_fputs(string, stream);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
80 free (string);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
81 return rv;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
82 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
83
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
84 int vfs_fprintf(VFSFile *stream, gchar const *format, ...)
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
85 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
86 va_list arg;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
87 gint rv;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
88
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
89 va_start(arg, format);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
90 rv = vfs_vfprintf(stream, format, arg);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
91 va_end(arg);
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
92
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
93 return rv;
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
94 }