aboutsummaryrefslogtreecommitdiff
path: root/text.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-17 12:56:05 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-17 16:24:16 +0200
commit3a454f70904ed84d27c9d380ba1b1e3e4a368c44 (patch)
treef2cb5cf298cdf9948aeb8bb79e5498beccc87150 /text.h
parentae7795327928efbe34288cce45b5547d0371b22a (diff)
downloadvis-3a454f70904ed84d27c9d380ba1b1e3e4a368c44.tar.gz
vis-3a454f70904ed84d27c9d380ba1b1e3e4a368c44.tar.xz
text: add infrastructure to save non-contiguous ranges
Diffstat (limited to 'text.h')
-rw-r--r--text.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/text.h b/text.h
index db71173..392bafd 100644
--- a/text.h
+++ b/text.h
@@ -18,6 +18,7 @@ typedef struct {
typedef struct Text Text;
typedef struct Piece Piece;
+typedef struct TextSave TextSave;
typedef struct {
const char *start; /* begin of piece's data */
@@ -132,6 +133,20 @@ const char *text_newline_char(Text*);
* new inode to file. */
bool text_save(Text*, const char *filename);
bool text_save_range(Text*, Filerange*, const char *file);
+
+/* this set of functions can be used to write multiple non-consecutive
+ * file ranges. For every call to `text_save_begin` there must be exactly
+ * one matching call to either `text_save_commit` or `text_save_cancel`
+ * to release the underlying resources. */
+TextSave *text_save_begin(Text*, const char *filename);
+ssize_t text_save_write_range(TextSave*, Filerange*);
+/* try committing the changes to disk */
+bool text_save_commit(TextSave*);
+/* does not guarantee to undo the previous writes (they might have been
+ * performed in-place) however it releases the underlying resources and
+ * free(3)'s the given TextSave* pointer which must no longer be used. */
+void text_save_cancel(TextSave*);
+
/* write the text content to the given file descriptor `fd'. Return the
* number of bytes written or -1 in case there was an error. */
ssize_t text_write(Text*, int fd);