Mercurial > audlegacy
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 |
rev | line source |
---|---|
1617 | 1 /* This program is free software; you can redistribute it and/or modify |
2 * it under the terms of the GNU General Public License as published by | |
3 * the Free Software Foundation; either version 2 of the License, or | |
4 * (at your option) any later version. | |
5 * | |
6 * This program is distributed in the hope that it will be useful, | |
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 * GNU General Public License for more details. | |
10 * | |
11 * You should have received a copy of the GNU General Public License | |
12 * along with this program; if not, write to the Free Software Foundation, | |
13 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
14 */ | |
15 | |
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 | 20 |
21 /* FIXME low performance vfs_getc */ | |
22 gint vfs_getc(VFSFile *stream) | |
23 { | |
24 guchar uc; | |
25 if (vfs_fread(&uc, 1, 1, stream)) | |
26 return uc; | |
27 return EOF; | |
28 } | |
29 | |
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 | 42 gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream) |
43 { | |
44 gint c; | |
45 register gchar *p; | |
46 | |
47 if(n<=0) return NULL; | |
48 | |
49 p = s; | |
50 | |
51 while (--n) { | |
52 if ((c = vfs_getc(stream))== EOF) { | |
53 break; | |
54 } | |
55 if ((*p++ = c) == '\n') { | |
56 break; | |
57 } | |
58 } | |
59 if (p > s) { | |
60 *p = 0; | |
61 return s; | |
62 } | |
63 | |
64 return NULL; | |
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 } |