filetype: Set "groovy" for Jenkinsfile
[vis.git] / text-internal.h
blob5ed84ae92df314912aaab4941ad1469f7a72a35b
1 #ifndef TEXT_INTERNAL
2 #define TEXT_INTERNAL
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include "text.h"
8 /* Block holding the file content, either readonly mmap(2)-ed from the original
9 * file or heap allocated to store the modifications.
11 typedef struct {
12 size_t size; /* maximal capacity */
13 size_t len; /* current used length / insertion position */
14 char *data; /* actual data */
15 enum { /* type of allocation */
16 BLOCK_TYPE_MMAP_ORIG, /* mmap(2)-ed from an external file */
17 BLOCK_TYPE_MMAP, /* mmap(2)-ed from a temporary file only known to this process */
18 BLOCK_TYPE_MALLOC, /* heap allocated block using malloc(3) */
19 } type;
20 } Block;
22 Block *block_alloc(size_t size);
23 Block *block_read(size_t size, int fd);
24 Block *block_mmap(size_t size, int fd, off_t offset);
25 Block *block_load(int dirfd, const char *filename, enum TextLoadMethod method, struct stat *info);
26 void block_free(Block*);
27 bool block_capacity(Block*, size_t len);
28 const char *block_append(Block*, const char *data, size_t len);
29 bool block_insert(Block*, size_t pos, const char *data, size_t len);
30 bool block_delete(Block*, size_t pos, size_t len);
32 Block *text_block_mmaped(Text*);
33 void text_saved(Text*, struct stat *meta);
35 #endif