summaryrefslogtreecommitdiff
path: root/src/libaudcore/vfs.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libaudcore/vfs.h')
-rw-r--r--src/libaudcore/vfs.h138
1 files changed, 76 insertions, 62 deletions
diff --git a/src/libaudcore/vfs.h b/src/libaudcore/vfs.h
index e7f9ecd..33c5a65 100644
--- a/src/libaudcore/vfs.h
+++ b/src/libaudcore/vfs.h
@@ -1,6 +1,6 @@
/*
* vfs.h
- * Copyright 2006-2013 William Pitcock, Daniel Barkalow, Ralf Ertzinger,
+ * Copyright 2006-2013 Ariadne Conill, Daniel Barkalow, Ralf Ertzinger,
* Yoshiki Yazawa, Matti Hämäläinen, and John Lindgren
*
* Redistribution and use in source and binary forms, with or without
@@ -33,21 +33,24 @@
#include <libaudcore/index.h>
#include <libaudcore/objects.h>
-enum VFSFileTest {
- VFS_IS_REGULAR = (1 << 0),
- VFS_IS_SYMLINK = (1 << 1),
- VFS_IS_DIR = (1 << 2),
+enum VFSFileTest
+{
+ VFS_IS_REGULAR = (1 << 0),
+ VFS_IS_SYMLINK = (1 << 1),
+ VFS_IS_DIR = (1 << 2),
VFS_IS_EXECUTABLE = (1 << 3),
- VFS_EXISTS = (1 << 4),
- VFS_NO_ACCESS = (1 << 5)
+ VFS_EXISTS = (1 << 4),
+ VFS_NO_ACCESS = (1 << 5)
};
-enum VFSReadOptions {
- VFS_APPEND_NULL = (1 << 0),
+enum VFSReadOptions
+{
+ VFS_APPEND_NULL = (1 << 0),
VFS_IGNORE_MISSING = (1 << 1)
};
-enum VFSSeekType {
+enum VFSSeekType
+{
VFS_SEEK_SET = 0,
VFS_SEEK_CUR = 1,
VFS_SEEK_END = 2
@@ -57,18 +60,22 @@ enum VFSSeekType {
#include <stdio.h>
-constexpr int from_vfs_seek_type (VFSSeekType whence)
+constexpr int from_vfs_seek_type(VFSSeekType whence)
{
- return (whence == VFS_SEEK_SET) ? SEEK_SET :
- (whence == VFS_SEEK_CUR) ? SEEK_CUR :
- (whence == VFS_SEEK_END) ? SEEK_END : -1;
+ return (whence == VFS_SEEK_SET)
+ ? SEEK_SET
+ : (whence == VFS_SEEK_CUR)
+ ? SEEK_CUR
+ : (whence == VFS_SEEK_END) ? SEEK_END : -1;
}
-constexpr VFSSeekType to_vfs_seek_type (int whence)
+constexpr VFSSeekType to_vfs_seek_type(int whence)
{
- return (whence == SEEK_SET) ? VFS_SEEK_SET :
- (whence == SEEK_CUR) ? VFS_SEEK_CUR :
- (whence == SEEK_END) ? VFS_SEEK_END : (VFSSeekType) -1;
+ return (whence == SEEK_SET)
+ ? VFS_SEEK_SET
+ : (whence == SEEK_CUR)
+ ? VFS_SEEK_CUR
+ : (whence == SEEK_END) ? VFS_SEEK_END : (VFSSeekType)-1;
}
#endif // WANT_VFS_STDIO_COMPAT
@@ -86,91 +93,98 @@ constexpr VFSSeekType to_vfs_seek_type (int whence)
class LIBAUDCORE_PUBLIC VFSImpl
{
public:
- VFSImpl () {}
- virtual ~VFSImpl () {}
+ VFSImpl() {}
+ virtual ~VFSImpl() {}
- VFSImpl (const VFSImpl &) = delete;
- VFSImpl & operator= (const VFSImpl &) = delete;
+ VFSImpl(const VFSImpl &) = delete;
+ VFSImpl & operator=(const VFSImpl &) = delete;
- virtual int64_t fread (void * ptr, int64_t size, int64_t nmemb) = 0;
- virtual int fseek (int64_t offset, VFSSeekType whence) = 0;
+ virtual int64_t fread(void * ptr, int64_t size, int64_t nmemb) = 0;
+ virtual int fseek(int64_t offset, VFSSeekType whence) = 0;
- virtual int64_t ftell () = 0;
- virtual int64_t fsize () = 0;
- virtual bool feof () = 0;
+ virtual int64_t ftell() = 0;
+ virtual int64_t fsize() = 0;
+ virtual bool feof() = 0;
- virtual int64_t fwrite (const void * ptr, int64_t size, int64_t nmemb) = 0;
- virtual int ftruncate (int64_t length) = 0;
- virtual int fflush () = 0;
+ virtual int64_t fwrite(const void * ptr, int64_t size, int64_t nmemb) = 0;
+ virtual int ftruncate(int64_t length) = 0;
+ virtual int fflush() = 0;
- virtual String get_metadata (const char * field) { return String (); }
+ virtual String get_metadata(const char * field) { return String(); }
};
class VFSFile
{
public:
- VFSFile () {}
+ VFSFile() {}
- VFSFile (const char * filename, VFSImpl * impl) :
- m_filename (filename),
- m_impl (impl) {}
+ VFSFile(const char * filename, VFSImpl * impl)
+ : m_filename(filename), m_impl(impl)
+ {
+ }
- VFSFile (const char * filename, const char * mode);
+ VFSFile(const char * filename, const char * mode);
/* creates a temporary file (deleted when closed) */
- static VFSFile tmpfile ();
+ static VFSFile tmpfile();
- explicit operator bool () const
- { return (bool) m_impl; }
- const char * filename () const
- { return m_filename; }
- const char * error () const
- { return m_error; }
+ explicit operator bool() const { return (bool)m_impl; }
+ const char * filename() const { return m_filename; }
+ const char * error() const { return m_error; }
/* basic operations */
- int64_t fread (void * ptr, int64_t size, int64_t nmemb) __attribute__ ((warn_unused_result));
- int fseek (int64_t offset, VFSSeekType whence) __attribute__ ((warn_unused_result));
+ int64_t fread(void * ptr, int64_t size, int64_t nmemb)
+ __attribute__((warn_unused_result));
+ int fseek(int64_t offset, VFSSeekType whence)
+ __attribute__((warn_unused_result));
- int64_t ftell ();
- int64_t fsize ();
- bool feof ();
+ int64_t ftell();
+ int64_t fsize();
+ bool feof();
- int64_t fwrite (const void * ptr, int64_t size, int64_t nmemb) __attribute__ ((warn_unused_result));
- int ftruncate (int64_t length) __attribute__ ((warn_unused_result));
- int fflush () __attribute__ ((warn_unused_result));
+ int64_t fwrite(const void * ptr, int64_t size, int64_t nmemb)
+ __attribute__((warn_unused_result));
+ int ftruncate(int64_t length) __attribute__((warn_unused_result));
+ int fflush() __attribute__((warn_unused_result));
/* used to read e.g. ICY metadata */
- String get_metadata (const char * field);
+ String get_metadata(const char * field);
/* the VFS layer buffers up to 256 KB of data at the beginning of files
* opened in read-only mode; this function disallows reading outside the
* buffered region (useful for probing the file type) */
- void set_limit_to_buffer (bool limit);
+ void set_limit_to_buffer(bool limit);
/* utility functions */
/* reads the entire file into memory (limited to 16 MB) */
- Index<char> read_all ();
+ Index<char> read_all();
/* reads data from another open file and appends it to this one */
- bool copy_from (VFSFile & source, int64_t size = -1);
+ bool copy_from(VFSFile & source, int64_t size = -1);
/* overwrites the entire file with the contents of another */
- bool replace_with (VFSFile & source);
+ bool replace_with(VFSFile & source);
/* tests certain attributes of a file without opening it.
* the 2-argument version returns true if all requested tests passed.
- * the 3-argument version returns a bitmask indicating which tests passed. */
- static bool test_file (const char * filename, VFSFileTest test);
- static VFSFileTest test_file (const char * filename, VFSFileTest test, String & error);
+ * the 3-argument version returns a bitmask indicating which tests passed.
+ */
+ static bool test_file(const char * filename, VFSFileTest test);
+ static VFSFileTest test_file(const char * filename, VFSFileTest test,
+ String & error);
/* returns a sorted list of folder entries (as full URIs) */
- static Index<String> read_folder (const char * filename, String & error);
+ static Index<String> read_folder(const char * filename, String & error);
/* convenience functions to read/write entire files */
- static Index<char> read_file (const char * filename, VFSReadOptions options);
- static bool write_file (const char * filename, const void * data, int64_t len);
+ static Index<char> read_file(const char * filename, VFSReadOptions options);
+ static bool write_file(const char * filename, const void * data,
+ int64_t len);
+
+ /* returns a list of supported URI schemes */
+ static Index<const char *> supported_uri_schemes();
private:
String m_filename, m_error;