55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
|
|
#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
|