io: implement stat'ing paths, files, and directory contents
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <blue/core/iterator.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
|
||||
#define B_DIRECTORY_ROOT ((b_directory *)NULL)
|
||||
@@ -19,11 +20,14 @@ typedef enum b_directory_iterator_flags {
|
||||
|
||||
typedef struct b_directory_iterator {
|
||||
b_iterator _base;
|
||||
struct z__b_directory_iterator *_z;
|
||||
|
||||
b_directory_iterator_flags flags;
|
||||
b_directory *root;
|
||||
|
||||
const b_path *filepath;
|
||||
char *filename;
|
||||
struct z__b_directory_iterator *_z;
|
||||
b_file_info info;
|
||||
} b_directory_iterator;
|
||||
|
||||
#define b_directory_foreach(it, dir, flags) \
|
||||
|
||||
54
io/include/blue/io/file.h
Normal file
54
io/include/blue/io/file.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef BLUELIB_IO_FILE_H_
|
||||
#define BLUELIB_IO_FILE_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/object/object.h>
|
||||
|
||||
#define B_FILE(p) ((b_file *)(p))
|
||||
|
||||
struct b_directory;
|
||||
struct b_path;
|
||||
|
||||
typedef enum b_file_attribute {
|
||||
B_FILE_ATTRIB_NORMAL = 0x01u,
|
||||
B_FILE_ATTRIB_DIRECTORY = 0x02u,
|
||||
B_FILE_ATTRIB_BLOCK_DEVICE = 0x04u,
|
||||
B_FILE_ATTRIB_CHAR_DEVICE = 0x08u,
|
||||
B_FILE_ATTRIB_SYMLINK = 0x80u,
|
||||
} 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_TRUNCATE = 0x04u,
|
||||
B_FILE_APPEND = 0x08u,
|
||||
B_FILE_BINARY = 0x10u,
|
||||
} b_file_mode;
|
||||
|
||||
typedef struct b_file_info {
|
||||
b_file_attribute attrib;
|
||||
b_file_mode mode;
|
||||
|
||||
size_t length;
|
||||
} b_file_info;
|
||||
|
||||
typedef struct b_file b_file;
|
||||
|
||||
BLUE_API enum b_status b_file_open(
|
||||
struct b_directory *root, const struct b_path *path, b_file_mode mode,
|
||||
b_file **out);
|
||||
|
||||
BLUE_API enum b_status b_file_stat(b_file *file, b_file_info *out);
|
||||
|
||||
static inline b_file *b_file_retain(b_file *file)
|
||||
{
|
||||
return B_FILE(b_retain(B_OBJECT(file)));
|
||||
}
|
||||
static inline void b_file_release(b_file *file)
|
||||
{
|
||||
b_release(B_OBJECT(file));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#define B_PATH(p) ((b_path *)p)
|
||||
|
||||
struct b_file_info;
|
||||
|
||||
typedef struct b_path b_path;
|
||||
|
||||
BLUE_API b_path *b_path_create();
|
||||
@@ -25,6 +27,7 @@ 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 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