29 #include <sys/types.h>
32 #define VFS_SIG ('V' | ('F' << 8) | ('S' << 16))
68 static char last[256] =
"";
69 static int repeated = 0;
74 va_start (args, format);
75 vsnprintf (buf,
sizeof buf, format, args);
78 if (! strcmp (buf, last))
84 printf (
"VFS: (last message repeated %d times)\n", repeated);
98 file->handle = handle;
125 g_return_val_if_fail (path && mode,
NULL);
128 const char *
s = strstr (path,
"://");
129 g_return_val_if_fail (s,
NULL);
130 char scheme[s - path + 1];
131 strncpy (scheme, path, s - path);
132 scheme[s - path] = 0;
141 gchar buf[sub - path + 1];
142 memcpy (buf, path, sub - path);
145 void * handle = vtable->vfs_fopen_impl (buf, mode);
152 logger (
"VFS: <%p> open (mode %s) %s\n", file, mode, path);
166 g_return_val_if_fail (file && file->sig ==
VFS_SIG, -1);
169 logger (
"VFS: <%p> close\n", file);
173 if (file->base->vfs_fclose_impl(file) != 0)
178 memset (file, 0,
sizeof (
VFSFile));
195 g_return_val_if_fail (file && file->sig ==
VFS_SIG, 0);
197 int64_t readed = file->base->vfs_fread_impl (ptr, size, nmemb, file);
217 g_return_val_if_fail (file && file->sig ==
VFS_SIG, 0);
219 int64_t written = file->base->vfs_fwrite_impl (ptr, size, nmemb, file);
222 logger (
"VFS: <%p> write %"PRId64
" elements of size %"PRId64
" = "
223 "%"PRId64
"\n", file, nmemb, size, written);
237 g_return_val_if_fail (file && file->sig ==
VFS_SIG, EOF);
240 logger (
"VFS: <%p> getc\n", file);
242 return file->base->vfs_getc_impl(file);
255 g_return_val_if_fail (file && file->sig ==
VFS_SIG, EOF);
258 logger (
"VFS: <%p> ungetc\n", file);
260 return file->base->vfs_ungetc_impl(c, file);
281 g_return_val_if_fail (file && file->sig ==
VFS_SIG, -1);
284 logger (
"VFS: <%p> seek to %"PRId64
" from %s\n", file, offset, whence ==
285 SEEK_CUR ?
"current" : whence == SEEK_SET ?
"beginning" : whence ==
286 SEEK_END ?
"end" :
"invalid");
288 return file->base->vfs_fseek_impl(file, offset, whence);
299 g_return_if_fail (file && file->sig ==
VFS_SIG);
302 logger (
"VFS: <%p> rewind\n", file);
304 file->base->vfs_rewind_impl(file);
316 g_return_val_if_fail (file && file->sig ==
VFS_SIG, -1);
318 int64_t told = file->base->vfs_ftell_impl (file);
321 logger (
"VFS: <%p> tell = %"PRId64
"\n", file, told);
335 g_return_val_if_fail (file && file->sig ==
VFS_SIG,
TRUE);
337 bool_t eof = file->base->vfs_feof_impl (file);
340 logger (
"VFS: <%p> eof = %s\n", file, eof ?
"yes" :
"no");
354 g_return_val_if_fail (file && file->sig ==
VFS_SIG, -1);
357 logger (
"VFS: <%p> truncate to %"PRId64
"\n", file, length);
359 return file->base->vfs_ftruncate_impl(file, length);
370 g_return_val_if_fail (file && file->sig ==
VFS_SIG, -1);
372 int64_t size = file->base->vfs_fsize_impl (file);
375 logger (
"VFS: <%p> size = %"PRId64
"\n", file, size);
393 if (file->base->vfs_get_metadata_impl)
394 return file->base->vfs_get_metadata_impl(file, field);
408 if (strncmp (path,
"file://", 7))
419 if (lstat (path2, & st) < 0)
422 if (S_ISLNK (st.st_mode))
423 test &= ~VFS_IS_SYMLINK;
430 if (stat (path2, & st) < 0)
433 if (S_ISREG (st.st_mode))
435 if (S_ISDIR (st.st_mode))
437 if (st.st_mode & S_IXUSR)
461 if (stat(realfn, &info) == -1)
466 return (info.st_mode & S_IWUSR);
477 return strncmp (path,
"file://", 7) ?
TRUE :
FALSE;
static VFSConstructor *(* lookup_func)(const char *scheme)
EXPORT int64_t vfs_fwrite(const void *ptr, int64_t size, int64_t nmemb, VFSFile *file)
Writes to a VFS stream.
EXPORT bool_t vfs_feof(VFSFile *file)
Returns whether or not the VFS stream has reached EOF.
EXPORT int64_t vfs_ftell(VFSFile *file)
Returns the current position in the VFS stream's buffer.
EXPORT char * uri_to_filename(const char *uri)
Main API header for accessing Audacious VFS functionality.
EXPORT int vfs_fclose(VFSFile *file)
Closes a VFS stream and destroys a VFSFile object.
EXPORT bool_t vfs_is_streaming(VFSFile *file)
Tests if a file is associated to streaming.
void * handle
Opaque data used by the transport plugins.
EXPORT VFSFile * vfs_new(const char *path, VFSConstructor *vtable, void *handle)
char * uri
The URI of the stream.
EXPORT int vfs_ftruncate(VFSFile *file, int64_t length)
Truncates a VFS stream to a certain size.
EXPORT const char * vfs_get_filename(VFSFile *file)
EXPORT int vfs_fseek(VFSFile *file, int64_t offset, int whence)
Performs a seek in given VFS stream.
static void logger(const char *format,...)
int sig
Used to detect invalid or twice-closed objects.
EXPORT int64_t vfs_fread(void *ptr, int64_t size, int64_t nmemb, VFSFile *file)
Reads from a VFS stream.
EXPORT void vfs_set_lookup_func(VFSConstructor *(*func)(const char *scheme))
EXPORT void * vfs_get_handle(VFSFile *file)
EXPORT int vfs_ungetc(int c, VFSFile *file)
Pushes a character back to the VFS stream.
EXPORT bool_t vfs_is_writeable(const char *path)
Tests if a file is writeable.
void str_unref(char *str)
EXPORT VFSFile * vfs_fopen(const char *path, const char *mode)
Opens a stream from a VFS transport using one of the registered VFSConstructor handlers.
EXPORT void uri_parse(const char *uri, const char **base_p, const char **ext_p, const char **sub_p, int *isub_p)
EXPORT char * vfs_get_metadata(VFSFile *file, const char *field)
Returns metadata about the stream.
VFSFile objects describe an opened VFS stream, basically being similar in purpose as stdio FILE ...
EXPORT bool_t vfs_is_remote(const char *path)
Tests if a path is remote uri.
EXPORT void vfs_set_verbose(bool_t set)
EXPORT void vfs_rewind(VFSFile *file)
Rewinds a VFS stream.
EXPORT int vfs_getc(VFSFile *file)
Reads a character from a VFS stream.
char * str_get(const char *str)
VFSConstructor * base
The base vtable used for VFS functions.
EXPORT int64_t vfs_fsize(VFSFile *file)
Returns size of the file.
EXPORT bool_t vfs_file_test(const char *path, int test)
Wrapper for g_file_test().
#define VFS_IS_EXECUTABLE