io: add lots of directory and path manipulation functions
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
|
||||
#define B_DIRECTORY(p) ((b_directory *)(p))
|
||||
#define B_DIRECTORY_ROOT ((b_directory *)NULL)
|
||||
|
||||
typedef struct b_directory b_directory;
|
||||
@@ -36,6 +37,16 @@ typedef struct b_directory_iterator {
|
||||
|
||||
BLUE_API b_status b_directory_open(
|
||||
b_directory *root, const b_path *path, b_directory **out);
|
||||
BLUE_API const b_path *b_directory_get_path(const 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_status b_directory_path_stat(
|
||||
const b_directory *root, const b_path *path, struct b_file_info *out);
|
||||
BLUE_API b_status 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,
|
||||
@@ -44,4 +55,14 @@ 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);
|
||||
|
||||
static inline b_directory *b_directory_retain(b_directory *dir)
|
||||
{
|
||||
return B_DIRECTORY(b_retain(B_OBJECT(dir)));
|
||||
}
|
||||
|
||||
static inline void b_directory_release(b_directory *dir)
|
||||
{
|
||||
b_release(B_OBJECT(dir));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,11 +5,19 @@
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/object/object.h>
|
||||
|
||||
#define B_FILE(p) ((b_file *)(p))
|
||||
#define B_FILE(p) ((b_file *)(p))
|
||||
|
||||
#define B_OFFSET_CURRENT ((size_t) - 1)
|
||||
|
||||
struct b_directory;
|
||||
struct b_path;
|
||||
|
||||
typedef enum b_seek_basis {
|
||||
B_SEEK_BEGINNING,
|
||||
B_SEEK_CURRENT,
|
||||
B_SEEK_END
|
||||
} b_seek_basis;
|
||||
|
||||
typedef enum b_file_attribute {
|
||||
B_FILE_ATTRIB_NORMAL = 0x01u,
|
||||
B_FILE_ATTRIB_DIRECTORY = 0x02u,
|
||||
@@ -21,10 +29,14 @@ typedef enum b_file_attribute {
|
||||
typedef enum b_file_mode {
|
||||
B_FILE_READ_ONLY = 0x01u,
|
||||
B_FILE_WRITE_ONLY = 0x02u,
|
||||
B_FILE_READ_WRITE = 0x03u,
|
||||
B_FILE_READ_WRITE = B_FILE_READ_ONLY | B_FILE_WRITE_ONLY,
|
||||
B_FILE_TRUNCATE = 0x04u,
|
||||
B_FILE_APPEND = 0x08u,
|
||||
B_FILE_BINARY = 0x10u,
|
||||
B_FILE_CREATE = 0x08u,
|
||||
B_FILE_CREATE_ONLY = 0x10u | B_FILE_CREATE,
|
||||
B_FILE_APPEND = 0x20u,
|
||||
B_FILE_BINARY = 0x40u,
|
||||
B_FILE_DELETE_ON_CLOSE = 0x80u,
|
||||
B_FILE_SHADOW = 0x100u,
|
||||
} b_file_mode;
|
||||
|
||||
typedef struct b_file_info {
|
||||
@@ -36,11 +48,26 @@ typedef struct b_file_info {
|
||||
|
||||
typedef struct b_file b_file;
|
||||
|
||||
BLUE_API enum b_status b_file_open(
|
||||
BLUE_API b_status b_file_open(
|
||||
struct b_directory *root, const struct b_path *path, b_file_mode mode,
|
||||
b_file **out);
|
||||
BLUE_API b_status b_file_open_temp(b_file_mode mode, b_file **out);
|
||||
BLUE_API b_status b_file_open_shadow(
|
||||
b_file *original, b_file_mode mode, b_file **out);
|
||||
|
||||
BLUE_API enum b_status b_file_stat(b_file *file, b_file_info *out);
|
||||
BLUE_API b_status b_file_stat(b_file *file, b_file_info *out);
|
||||
BLUE_API b_status b_file_size(b_file *file, size_t *out_len);
|
||||
BLUE_API b_status b_file_cursor(b_file *file, size_t *out_pos);
|
||||
BLUE_API b_status b_file_resize(b_file *file, size_t len);
|
||||
BLUE_API b_status b_file_seek(b_file *file, long long offset, b_seek_basis basis);
|
||||
|
||||
BLUE_API b_status b_file_swap_shadow(b_file *main_file, b_file *shadow_file);
|
||||
|
||||
BLUE_API b_status b_file_read(
|
||||
b_file *file, size_t offset, size_t len, void *buf, size_t *nr_read);
|
||||
BLUE_API b_status b_file_write(
|
||||
b_file *file, size_t offset, size_t len, const void *buf,
|
||||
size_t *nr_written);
|
||||
|
||||
static inline b_file *b_file_retain(b_file *file)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include <blue/object/object.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define B_PATH(p) ((b_path *)p)
|
||||
#define B_PATH(p) ((b_path *)p)
|
||||
|
||||
#define B_RV_PATH(cstr) B_RV(b_path_create_from_str(cstr))
|
||||
|
||||
struct b_file_info;
|
||||
|
||||
@@ -27,7 +29,13 @@ BLUE_API bool b_path_is_absolute(const b_path *path);
|
||||
BLUE_API bool b_path_exists(const b_path *path);
|
||||
BLUE_API bool b_path_is_file(const b_path *path);
|
||||
BLUE_API bool b_path_is_directory(const b_path *path);
|
||||
BLUE_API enum b_status b_path_stat(const b_path *path, struct b_file_info *out);
|
||||
BLUE_API b_status b_path_stat(const b_path *path, struct b_file_info *out);
|
||||
BLUE_API b_status b_path_unlink(const b_path *path);
|
||||
|
||||
BLUE_API enum b_status b_path_get_directory(
|
||||
const b_path *path, b_path **out_dir_path);
|
||||
BLUE_API enum b_status b_path_get_filename(
|
||||
const b_path *path, struct b_string *out_name);
|
||||
|
||||
BLUE_API const char *b_path_ptr(const b_path *path);
|
||||
BLUE_API size_t b_path_length(const b_path *path);
|
||||
|
||||
Reference in New Issue
Block a user