comparison 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
comparison
equal deleted inserted replaced
2561:5b761b745289 2562:07b990906823
93 if (file == NULL) 93 if (file == NULL)
94 return NULL; 94 return NULL;
95 95
96 file->uri = g_strdup(path); 96 file->uri = g_strdup(path);
97 file->base = vtable; 97 file->base = vtable;
98 file->ref = 1;
98 99
99 g_free(decpath); 100 g_free(decpath);
100 101
101 return file; 102 return file;
102 } 103 }
113 vfs_fclose(VFSFile * file) 114 vfs_fclose(VFSFile * file)
114 { 115 {
115 gint ret = 0; 116 gint ret = 0;
116 117
117 if (file == NULL) 118 if (file == NULL)
119 return -1;
120
121 if (--file->ref > 0)
118 return -1; 122 return -1;
119 123
120 if (file->base->vfs_fclose_impl(file) != 0) 124 if (file->base->vfs_fclose_impl(file) != 0)
121 ret = -1; 125 ret = -1;
122 126
349 if (stat(path, &info) == -1) 353 if (stat(path, &info) == -1)
350 return FALSE; 354 return FALSE;
351 355
352 return (info.st_mode & S_IWUSR); 356 return (info.st_mode & S_IWUSR);
353 } 357 }
358
359 /**
360 * vfs_dup:
361 * @in: The VFSFile handle to mark as duplicated.
362 *
363 * Increments the amount of references that are using this FD.
364 * References are removed by calling vfs_fclose on the handle returned
365 * from this function.
366 * If the amount of references reaches zero, then the file will be
367 * closed.
368 **/
369 VFSFile *
370 vfs_dup(VFSFile *in)
371 {
372 g_return_val_if_fail(in != NULL, NULL);
373
374 in->ref++;
375
376 return in;
377 }