diff src/audacious/vfs.c @ 2562:07b990906823 trunk

[svn] - add reference-counting to VFS and add new function, vfs_dup() to mark a VFS handle as duplicated.
author nenolod
date Sat, 24 Feb 2007 06:01:39 -0800
parents c3d5ac206052
children 9713b5a67cba
line wrap: on
line diff
--- a/src/audacious/vfs.c	Fri Feb 23 20:10:54 2007 -0800
+++ b/src/audacious/vfs.c	Sat Feb 24 06:01:39 2007 -0800
@@ -95,6 +95,7 @@
 
     file->uri = g_strdup(path);
     file->base = vtable;
+    file->ref = 1;
 
     g_free(decpath);
 
@@ -117,6 +118,9 @@
     if (file == NULL)
         return -1;
 
+    if (--file->ref > 0)
+        return -1;
+
     if (file->base->vfs_fclose_impl(file) != 0)
         ret = -1;
 
@@ -351,3 +355,23 @@
 
     return (info.st_mode & S_IWUSR);
 }
+
+/**
+ * vfs_dup:
+ * @in: The VFSFile handle to mark as duplicated.
+ *
+ * Increments the amount of references that are using this FD.
+ * References are removed by calling vfs_fclose on the handle returned
+ * from this function.
+ * If the amount of references reaches zero, then the file will be
+ * closed.
+ **/
+VFSFile *
+vfs_dup(VFSFile *in)
+{
+    g_return_val_if_fail(in != NULL, NULL);
+
+    in->ref++;
+
+    return in;
+}