annotate libaudacious/vfs_common.c @ 2087:bc47a2129067 trunk

[svn] - update these files
author nenolod
date Mon, 11 Dec 2006 04:30:50 -0800
parents 53a3d5db6b58
children
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
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
21 /**
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
22 * vfs_fputc:
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
23 * @c: A character to write to the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
24 * @stream: A #VFSFile object representing the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
25 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
26 * Writes a character to a stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
27 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
28 * Return value: The character on success, or EOF.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
29 **/
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
30 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
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 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
33
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
34 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
35 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
36 }
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 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
39 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
40
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
41 /**
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
42 * vfs_fgets:
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
43 * @s: A buffer to put the string in.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
44 * @n: The amount of characters to read.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
45 * @stream: A #VFSFile object representing the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
46 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
47 * Reads a set of characters from a stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
48 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
49 * Return value: The string on success, or NULL.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
50 **/
1617
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
51 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
52 {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
53 gint c;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
54 register gchar *p;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
55
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
56 if(n<=0) return NULL;
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 p = s;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
59
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
60 while (--n) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
61 if ((c = vfs_getc(stream))== EOF) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
62 break;
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 if ((*p++ = c) == '\n') {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
65 break;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
66 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
67 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
68 if (p > s) {
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
69 *p = 0;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
70 return s;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
71 }
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
72
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
73 return NULL;
3de4bd38fe4f [svn] generic vfs_gets and m3u updated to use vfs
lu_zero
parents:
diff changeset
74 }
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
75
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
76 /**
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
77 * vfs_fputc:
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
78 * @s: A string to write to the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
79 * @stream: A #VFSFile object representing the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
80 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
81 * Writes a string to a VFS stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
82 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
83 * Return value: The amount of bytes written.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
84 **/
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
85 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
86 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
87 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
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 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
90 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
91
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
92 /**
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
93 * vfs_vfprintf:
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
94 * @stream: A #VFSFile object representing the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
95 * @format: A printf-style format string.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
96 * @args: A va_list of args to use.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
97 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
98 * Writes a formatted string to a VFS stream via a va_list of args.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
99 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
100 * Return value: The amount of bytes written.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
101 **/
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
102 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
103 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
104 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
105 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
106 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
107 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
108 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
109 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
110 }
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
111
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
112 /**
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
113 * vfs_fprintf:
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
114 * @stream: A #VFSFile object representing the stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
115 * @format: A printf-style format string.
2060
53a3d5db6b58 [svn] - finish documenting the libaudacious API
nenolod
parents: 2059
diff changeset
116 * @...: A list of args to use.
2059
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
117 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
118 * Writes a formatted string to a VFS stream.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
119 *
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
120 * Return value: The amount of bytes written.
8aaf0f145578 [svn] - documentation fixups
nenolod
parents: 1683
diff changeset
121 **/
1669
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
122 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
123 {
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
124 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
125 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
126
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
127 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
128 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
129 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
130
07143b97314d [svn] fprintf implementation in the VFS common layer by Luca Barbato. Use it in the Container plugins.
chainsaw
parents: 1617
diff changeset
131 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
132 }