annotate libaudacious/vfs_common.c @ 1692:2dd4cf103e1c trunk

[svn] Forgot to change .cpp -> .cxx in the Makefile.in. Shame on me...
author js
date Thu, 14 Sep 2006 13:38:05 -0700
parents e9c24e35bd76
children 8aaf0f145578
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
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
22 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
23 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
24 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
25
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
26 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
27 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
28 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
29
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
30 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
31 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
32
1617
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
33 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
34 {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
35 gint c;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
36 register gchar *p;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
37
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
38 if(n<=0) return NULL;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
39
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
40 p = s;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
41
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
42 while (--n) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
43 if ((c = vfs_getc(stream))== EOF) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
44 break;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
45 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
46 if ((*p++ = c) == '\n') {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
47 break;
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 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
50 if (p > s) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
51 *p = 0;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
52 return s;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
53 }
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 return NULL;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
56 }
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
57
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
58 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
59 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
60 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
61
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
62 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
63 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
64
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
65 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
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 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
68 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
69 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
70 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
71 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
72 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
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
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
75 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
76 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
77 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
78 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
79
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
80 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
81 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
82 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
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 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
85 }