85 lines
2.7 KiB
C
85 lines
2.7 KiB
C
#ifndef BLUE_IO_DIRECTORY_H_
|
|
#define BLUE_IO_DIRECTORY_H_
|
|
|
|
#include <blue/core/error.h>
|
|
#include <blue/core/iterator.h>
|
|
#include <blue/core/macros.h>
|
|
#include <blue/core/misc.h>
|
|
#include <blue/io/file.h>
|
|
#include <blue/io/path.h>
|
|
|
|
#define B_DIRECTORY_ROOT ((b_directory *)NULL)
|
|
|
|
B_DECLS_BEGIN;
|
|
|
|
struct b_directory_p;
|
|
|
|
#define B_TYPE_DIRECTORY (b_directory_get_type())
|
|
|
|
B_DECLARE_TYPE(b_directory);
|
|
|
|
B_TYPE_CLASS_DECLARATION_BEGIN(b_directory)
|
|
B_TYPE_CLASS_DECLARATION_END(b_directory)
|
|
|
|
struct z__b_directory_iterator;
|
|
|
|
typedef enum b_directory_iterator_flags {
|
|
B_DIRECTORY_ITERATE_PARENT_FIRST = 0x01u,
|
|
B_DIRECTORY_ITERATE_PARENT_LAST = 0x02u,
|
|
} b_directory_iterator_flags;
|
|
|
|
typedef enum b_directory_open_flags {
|
|
B_DIRECTORY_OPEN_CREATE = 0x01u,
|
|
B_DIRECTORY_OPEN_CREATE_INTERMEDIATE = 0x03u,
|
|
B_DIRECTORY_OPEN_DELETE_ON_CLOSE = 0x04u,
|
|
} b_directory_open_flags;
|
|
|
|
typedef struct b_directory_iterator {
|
|
b_iterator _base;
|
|
struct z__b_directory_iterator *_z;
|
|
struct b_directory_p *_p;
|
|
|
|
b_directory_iterator_flags flags;
|
|
b_directory *root;
|
|
|
|
const b_path *filepath;
|
|
char *filename;
|
|
b_file_info info;
|
|
} b_directory_iterator;
|
|
|
|
#define b_directory_foreach(it, dir, flags) \
|
|
for (int z__b_unique_name() = b_directory_iterator_begin(dir, it, flags); \
|
|
b_directory_iterator_is_valid(it); b_directory_iterator_next(it))
|
|
|
|
BLUE_API b_type b_directory_get_type(void);
|
|
|
|
BLUE_API b_result b_directory_open(
|
|
b_directory *root, const b_path *path, b_directory_open_flags flags,
|
|
b_directory **out);
|
|
BLUE_API b_result b_directory_open_temp(b_directory **out);
|
|
BLUE_API const b_path *b_directory_get_path(const b_directory *dir);
|
|
BLUE_API const b_path *b_directory_get_rel_path(const b_directory *dir);
|
|
BLUE_API const char *b_directory_get_path_cstr(const b_directory *dir);
|
|
BLUE_API const char *b_directory_get_rel_path_cstr(const b_directory *dir);
|
|
BLUE_API b_result b_directory_delete(b_directory *dir);
|
|
|
|
BLUE_API bool b_directory_path_exists(const b_directory *root, const b_path *path);
|
|
BLUE_API bool b_directory_path_is_file(const b_directory *root, const b_path *path);
|
|
BLUE_API bool b_directory_path_is_directory(
|
|
const b_directory *root, const b_path *path);
|
|
BLUE_API b_result b_directory_path_stat(
|
|
const b_directory *root, const b_path *path, struct b_file_info *out);
|
|
BLUE_API b_result b_directory_path_unlink(
|
|
const b_directory *root, const b_path *path);
|
|
|
|
BLUE_API int b_directory_iterator_begin(
|
|
b_directory *directory, b_directory_iterator *it,
|
|
b_directory_iterator_flags flags);
|
|
BLUE_API bool b_directory_iterator_next(b_directory_iterator *it);
|
|
BLUE_API b_status b_directory_iterator_erase(b_directory_iterator *it);
|
|
BLUE_API bool b_directory_iterator_is_valid(const b_directory_iterator *it);
|
|
|
|
B_DECLS_END;
|
|
|
|
#endif
|