changeset 1683:e9c24e35bd76 trunk

[svn] - File stream API for audacious vfs; uses real getc/ungetc functions for vfs_stdio and emulated functions for vfs_gnome
author giacomo
date Wed, 13 Sep 2006 15:59:49 -0700
parents ecf1d19f74c7
children a81d0a7d9059
files ChangeLog libaudacious/vfs.h libaudacious/vfs_common.c libaudacious/vfs_gnome.c libaudacious/vfs_stdio.c
diffstat 5 files changed, 59 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Sep 13 14:01:54 2006 -0700
+++ b/ChangeLog	Wed Sep 13 15:59:49 2006 -0700
@@ -1,3 +1,12 @@
+2006-09-13 21:01:54 +0000  Jonathan Schleifer <js@h3c.de>
+  revision [2301]
+  Added BSD make to the recommended make versions since it's officially supported now.
+  
+
+  Changes:        Modified:
+  +1 -1           trunk/mk/objective.mk  
+
+
 2006-09-13 20:58:21 +0000  William Pitcock <nenolod@nenolod.net>
   revision [2299]
   - fix missing name in ChangeLog (I forgot to add js to our changelog scripts, oops)
--- a/libaudacious/vfs.h	Wed Sep 13 14:01:54 2006 -0700
+++ b/libaudacious/vfs.h	Wed Sep 13 15:59:49 2006 -0700
@@ -24,6 +24,9 @@
                   size_t nmemb,
                   VFSFile *file);
 
+extern gint vfs_getc(VFSFile *stream);
+extern gint vfs_ungetc(gint c,
+                       VFSFile *stream);
 extern gchar *vfs_fgets(gchar *s,
                         gint n,
                         VFSFile *stream);
--- a/libaudacious/vfs_common.c	Wed Sep 13 14:01:54 2006 -0700
+++ b/libaudacious/vfs_common.c	Wed Sep 13 15:59:49 2006 -0700
@@ -18,15 +18,6 @@
 #include <stdlib.h>
 #include <glib/gprintf.h>
 
-/* FIXME low performance vfs_getc */
-gint vfs_getc(VFSFile *stream)
-{
-    guchar uc;
-    if (vfs_fread(&uc, 1, 1, stream))
-	return uc;
-    return EOF;
-}
-
 
 gint vfs_fputc(gint c, VFSFile *stream)
 {
--- a/libaudacious/vfs_gnome.c	Wed Sep 13 14:01:54 2006 -0700
+++ b/libaudacious/vfs_gnome.c	Wed Sep 13 15:59:49 2006 -0700
@@ -22,6 +22,7 @@
 {
     GnomeVFSHandle *handle;
     gboolean eof;
+    GSList *streamstack;
 };
 
 
@@ -54,6 +55,7 @@
 
     file = g_new(VFSFile, 1);
     file->eof = FALSE;
+    file->streamstack = NULL;
 
     mode_to_gnome_vfs(mode, &g_mode, &truncate, &append);
     gchar *escaped_file = gnome_vfs_escape_path_string(path);
@@ -107,6 +109,10 @@
             ret = -1;
     }
 
+    /* free the streamstack */
+    if ( file->streamstack != NULL )
+      g_slist_free( file->streamstack );
+
     g_free(file);
 
     return ret;
@@ -156,6 +162,35 @@
 }
 
 gint
+vfs_getc(VFSFile *stream)
+{
+    guchar uc;
+    if ( stream->streamstack != NULL ) /* check if some char was ungetc'ed before */
+    {
+      uc = GPOINTER_TO_INT(stream->streamstack->data);
+      stream->streamstack = g_slist_delete_link( stream->streamstack , stream->streamstack );
+      return uc;
+    }
+    else /* for gnomevfs, vfs_getc is emulated by vfs_fread */
+    {
+      if (vfs_fread(&uc, 1, 1, stream))
+        return uc;
+      else
+        return EOF;
+    }
+}
+
+gint
+vfs_ungetc(gint c, VFSFile *stream)
+{
+    stream->streamstack = g_slist_prepend( stream->streamstack , GINT_TO_POINTER(c) );
+    if ( stream->streamstack != NULL )
+      return c;
+    else
+      return EOF; /* an error occurred */
+}
+
+gint
 vfs_fseek(VFSFile * file,
           glong offset,
           gint whence)
--- a/libaudacious/vfs_stdio.c	Wed Sep 13 14:01:54 2006 -0700
+++ b/libaudacious/vfs_stdio.c	Wed Sep 13 15:59:49 2006 -0700
@@ -96,6 +96,18 @@
 }
 
 gint
+vfs_getc(VFSFile *stream)
+{
+  return getc( stream->handle );
+}
+
+gint
+vfs_ungetc(gint c, VFSFile *stream)
+{
+  return ungetc( c , stream->handle );
+}
+
+gint
 vfs_fseek(VFSFile * file,
           glong offset,
           gint whence)