Mercurial > audlegacy
changeset 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 | 778f078cda5a |
children | 0abfd27b3849 |
files | ChangeLog Plugins/Container/m3u/m3u.c Plugins/Container/pls/pls.c libaudacious/vfs.h libaudacious/vfs_common.c |
diffstat | 5 files changed, 66 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Sep 11 13:15:31 2006 -0700 +++ b/ChangeLog Mon Sep 11 15:24:52 2006 -0700 @@ -1,3 +1,11 @@ +2006-09-11 20:15:31 +0000 Tony Vroon <chainsaw@gentoo.org> + revision [2273] + Partial sync with upstream. + + Changes: Modified: + +6 -3 trunk/Plugins/Input/wma/libffwma/wmadec.c + + 2006-09-11 18:23:34 +0000 revision [2271] fix a typo
--- a/Plugins/Container/m3u/m3u.c Mon Sep 11 13:15:31 2006 -0700 +++ b/Plugins/Container/m3u/m3u.c Mon Sep 11 15:24:52 2006 -0700 @@ -140,16 +140,16 @@ { GList *node; gchar *outstr = NULL; - FILE *file; + VFSFile *file; g_return_if_fail(filename != NULL); - file = fopen(filename, "wb"); + file = vfs_fopen(filename, "wb"); g_return_if_fail(file != NULL); if (cfg.use_pl_metadata) - g_fprintf(file, "#EXTM3U\n"); + vfs_fprintf(file, "#EXTM3U\n"); PLAYLIST_LOCK(); @@ -166,20 +166,20 @@ outstr = g_locale_from_utf8(entry->title, -1, NULL, NULL, NULL); if(outstr) { - g_fprintf(file, "#EXTINF:%d,%s\n", seconds, outstr); + vfs_fprintf(file, "#EXTINF:%d,%s\n", seconds, outstr); g_free(outstr); outstr = NULL; } else { - g_fprintf(file, "#EXTINF:%d,%s\n", seconds, entry->title); + vfs_fprintf(file, "#EXTINF:%d,%s\n", seconds, entry->title); } } - g_fprintf(file, "%s\n", entry->filename); + vfs_fprintf(file, "%s\n", entry->filename); } PLAYLIST_UNLOCK(); - fclose(file); + vfs_fclose(file); } PlaylistContainer plc_m3u = {
--- a/Plugins/Container/pls/pls.c Mon Sep 11 13:15:31 2006 -0700 +++ b/Plugins/Container/pls/pls.c Mon Sep 11 15:24:52 2006 -0700 @@ -36,6 +36,7 @@ #include "audacious/playlist.h" #include "audacious/playlist_container.h" #include "audacious/plugin.h" +#include "libaudacious/vfs.h" static void playlist_load_pls(const gchar * filename, gint pos) @@ -73,25 +74,25 @@ playlist_save_pls(const gchar *filename, gint pos) { GList *node; - FILE *file = fopen(filename, "wb"); + VFSFile *file = vfs_fopen(filename, "wb"); g_return_if_fail(file != NULL); - g_fprintf(file, "[playlist]\n"); - g_fprintf(file, "NumberOfEntries=%d\n", playlist_get_length()); + vfs_fprintf(file, "[playlist]\n"); + vfs_fprintf(file, "NumberOfEntries=%d\n", playlist_get_length()); PLAYLIST_LOCK(); for (node = playlist_get(); node; node = g_list_next(node)) { PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); - g_fprintf(file, "File%d=%s\n", g_list_position(playlist_get(), node) + 1, + vfs_fprintf(file, "File%d=%s\n", g_list_position(playlist_get(), node) + 1, entry->filename); } PLAYLIST_UNLOCK(); - fclose(file); + vfs_fclose(file); } PlaylistContainer plc_pls = {
--- a/libaudacious/vfs.h Mon Sep 11 13:15:31 2006 -0700 +++ b/libaudacious/vfs.h Mon Sep 11 15:24:52 2006 -0700 @@ -42,6 +42,8 @@ extern gboolean vfs_truncate(VFSFile * file, glong length); +extern int vfs_fprintf(VFSFile *stream, gchar const *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); G_END_DECLS
--- a/libaudacious/vfs_common.c Mon Sep 11 13:15:31 2006 -0700 +++ b/libaudacious/vfs_common.c Mon Sep 11 15:24:52 2006 -0700 @@ -14,6 +14,9 @@ */ #include "vfs.h" +#include <string.h> +#include <stdlib.h> +#include <glib/gprintf.h> /* FIXME low performance vfs_getc */ gint vfs_getc(VFSFile *stream) @@ -25,6 +28,17 @@ } +gint vfs_fputc(gint c, VFSFile *stream) +{ + guchar uc = (guchar) c; + + if (! vfs_fwrite(&uc, 1, 1, stream)) { + return EOF; + } + + return uc; +} + gchar *vfs_fgets(gchar *s, gint n, VFSFile *stream) { gint c; @@ -49,3 +63,32 @@ return NULL; } + +int vfs_fputs(const gchar *s, VFSFile *stream) +{ + size_t n = strlen(s); + + return ((vfs_fwrite(s, 1, n, stream) == n) ? n : EOF); +} + +int vfs_vfprintf(VFSFile *stream, gchar const *format, va_list args) +{ + gchar *string; + gint rv = g_vasprintf(&string, format, args); + if (rv<0) return rv; + rv = vfs_fputs(string, stream); + free (string); + return rv; +} + +int vfs_fprintf(VFSFile *stream, gchar const *format, ...) +{ + va_list arg; + gint rv; + + va_start(arg, format); + rv = vfs_vfprintf(stream, format, arg); + va_end(arg); + + return rv; +}