diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2020-09-28 15:42:14 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2020-10-10 10:48:10 +0200 |
| commit | 574567b125d1a81bb191cfecdecc76c70f216231 (patch) | |
| tree | b6ffbff29ade3306506ef917c2875b2d377f20fd /text-internal.h | |
| parent | a889c06ffe1bae1659a976d812c76433e6b69e51 (diff) | |
| download | vis-574567b125d1a81bb191cfecdecc76c70f216231.tar.gz vis-574567b125d1a81bb191cfecdecc76c70f216231.tar.xz | |
text: move I/O related code to separate file
This groups all I/O related code together to make it reusable in different
core text data structure implementations.
Diffstat (limited to 'text-internal.h')
| -rw-r--r-- | text-internal.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/text-internal.h b/text-internal.h new file mode 100644 index 0000000..5ed84ae --- /dev/null +++ b/text-internal.h @@ -0,0 +1,35 @@ +#ifndef TEXT_INTERNAL +#define TEXT_INTERNAL + +#include <stdbool.h> +#include <stddef.h> +#include "text.h" + +/* Block holding the file content, either readonly mmap(2)-ed from the original + * file or heap allocated to store the modifications. + */ +typedef struct { + size_t size; /* maximal capacity */ + size_t len; /* current used length / insertion position */ + char *data; /* actual data */ + enum { /* type of allocation */ + BLOCK_TYPE_MMAP_ORIG, /* mmap(2)-ed from an external file */ + BLOCK_TYPE_MMAP, /* mmap(2)-ed from a temporary file only known to this process */ + BLOCK_TYPE_MALLOC, /* heap allocated block using malloc(3) */ + } type; +} Block; + +Block *block_alloc(size_t size); +Block *block_read(size_t size, int fd); +Block *block_mmap(size_t size, int fd, off_t offset); +Block *block_load(int dirfd, const char *filename, enum TextLoadMethod method, struct stat *info); +void block_free(Block*); +bool block_capacity(Block*, size_t len); +const char *block_append(Block*, const char *data, size_t len); +bool block_insert(Block*, size_t pos, const char *data, size_t len); +bool block_delete(Block*, size_t pos, size_t len); + +Block *text_block_mmaped(Text*); +void text_saved(Text*, struct stat *meta); + +#endif |
