Mercurial > audlegacy
annotate src/audacious/vfs_common.c @ 3421:9d6f17ceebb3 trunk
ui_skinselector: don't call gtk_main_iteration() here, as it's unsafe to do so from within the main loop.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 02 Sep 2007 23:44:59 -0500 |
parents | f1c756f39e6c |
children | d9870d3e9550 |
rev | line source |
---|---|
2313 | 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 | |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
2424
diff
changeset
|
3 * the Free Software Foundation; under version 3 of the License. |
2313 | 4 * |
5 * This program is distributed in the hope that it will be useful, | |
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8 * GNU General Public License for more details. | |
9 * | |
10 * You should have received a copy of the GNU General Public License | |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
2424
diff
changeset
|
11 * along with this program. If not, see <http://www.gnu.org/licenses>. |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
2424
diff
changeset
|
12 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
2424
diff
changeset
|
13 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
2424
diff
changeset
|
14 * Audacious or using our public API to be a derived work. |
2313 | 15 */ |
16 | |
17 #include "vfs.h" | |
18 #include <string.h> | |
19 #include <stdlib.h> | |
20 #include <glib/gprintf.h> | |
21 | |
22 /** | |
23 * vfs_fputc: | |
24 * @c: A character to write to the stream. | |
25 * @stream: A #VFSFile object representing the stream. | |
26 * | |
27 * Writes a character to a stream. | |
28 * | |
29 * Return value: The character on success, or EOF. | |
30 **/ | |
31 gint vfs_fputc(gint c, VFSFile *stream) | |
32 { | |
33 guchar uc = (guchar) c; | |
34 | |
35 if (! vfs_fwrite(&uc, 1, 1, stream)) { | |
36 return EOF; | |
37 } | |
38 | |
39 return uc; | |
40 } | |
41 | |
42 /** | |
43 * vfs_fgets: | |
44 * @s: A buffer to put the string in. | |
45 * @n: The amount of characters to read. | |
46 * @stream: A #VFSFile object representing the stream. | |
47 * | |
48 * Reads a set of characters from a stream. | |
49 * | |
50 * Return value: The string on success, or NULL. | |
51 **/ | |
52 gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream) | |
53 { | |
54 gint c; | |
55 register gchar *p; | |
56 | |
57 if(n<=0) return NULL; | |
58 | |
59 p = s; | |
60 | |
61 while (--n) { | |
62 if ((c = vfs_getc(stream))== EOF) { | |
63 break; | |
64 } | |
65 if ((*p++ = c) == '\n') { | |
66 break; | |
67 } | |
68 } | |
69 if (p > s) { | |
70 *p = 0; | |
71 return s; | |
72 } | |
73 | |
74 return NULL; | |
75 } | |
76 | |
77 /** | |
78 * vfs_fputc: | |
79 * @s: A string to write to the stream. | |
80 * @stream: A #VFSFile object representing the stream. | |
81 * | |
82 * Writes a string to a VFS stream. | |
83 * | |
84 * Return value: The amount of bytes written. | |
85 **/ | |
86 int vfs_fputs(const gchar *s, VFSFile *stream) | |
87 { | |
88 size_t n = strlen(s); | |
89 | |
90 return ((vfs_fwrite(s, 1, n, stream) == n) ? n : EOF); | |
91 } | |
92 | |
93 /** | |
94 * vfs_vfprintf: | |
95 * @stream: A #VFSFile object representing the stream. | |
96 * @format: A printf-style format string. | |
97 * @args: A va_list of args to use. | |
98 * | |
99 * Writes a formatted string to a VFS stream via a va_list of args. | |
100 * | |
101 * Return value: The amount of bytes written. | |
102 **/ | |
103 int vfs_vfprintf(VFSFile *stream, gchar const *format, va_list args) | |
104 { | |
105 gchar *string; | |
106 gint rv = g_vasprintf(&string, format, args); | |
107 if (rv<0) return rv; | |
108 rv = vfs_fputs(string, stream); | |
109 free (string); | |
110 return rv; | |
111 } | |
112 | |
113 /** | |
114 * vfs_fprintf: | |
115 * @stream: A #VFSFile object representing the stream. | |
116 * @format: A printf-style format string. | |
117 * @...: A list of args to use. | |
118 * | |
119 * Writes a formatted string to a VFS stream. | |
120 * | |
121 * Return value: The amount of bytes written. | |
122 **/ | |
123 int vfs_fprintf(VFSFile *stream, gchar const *format, ...) | |
124 { | |
125 va_list arg; | |
126 gint rv; | |
127 | |
128 va_start(arg, format); | |
129 rv = vfs_vfprintf(stream, format, arg); | |
130 va_end(arg); | |
131 | |
132 return rv; | |
133 } | |
2424 | 134 |
135 /** | |
136 * vfs_file_get_contents | |
137 * @filename: the filename to read in | |
138 * @buf: pointer to pointer of buffer | |
139 * @sz: pointer to integer that is the size | |
140 **/ | |
141 void | |
142 vfs_file_get_contents(const gchar *filename, gchar **buf, gsize *size) | |
143 { | |
144 VFSFile *fd; | |
145 | |
146 fd = vfs_fopen(filename, "rb"); | |
147 | |
148 if (fd == NULL) | |
149 return; | |
150 | |
151 vfs_fseek(fd, 0, SEEK_END); | |
152 *size = vfs_ftell(fd); | |
153 | |
154 *buf = g_new(gchar, *size); | |
155 | |
156 if (*buf == NULL) | |
157 return; | |
158 | |
159 vfs_fseek(fd, 0, SEEK_SET); | |
160 vfs_fread(*buf, 1, *size, fd); | |
161 | |
162 vfs_fclose(fd); | |
163 } |