aboutsummaryrefslogtreecommitdiff
path: root/text.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-14 13:02:47 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-14 14:44:49 +0100
commite80d859867e515d95492e61bf5dca08a1c325130 (patch)
treeb970c6e7e42ab0d951c0ed1cf705dc43220efe61 /text.h
parent5b689baf18ca5e1feec1fc129d8af19f9c987c52 (diff)
downloadvis-e80d859867e515d95492e61bf5dca08a1c325130.tar.gz
vis-e80d859867e515d95492e61bf5dca08a1c325130.tar.xz
text: expose text save method to calling code
There are cases where it is useful to specify how the file should be saved.
Diffstat (limited to 'text.h')
-rw-r--r--text.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/text.h b/text.h
index ee7dd6b..0306a4c 100644
--- a/text.h
+++ b/text.h
@@ -128,6 +128,12 @@ enum TextNewLine {
enum TextNewLine text_newline_type(Text*);
const char *text_newline_char(Text*);
+enum TextSaveMethod {
+ TEXT_SAVE_AUTO, /* first try atomic, then fall back to inplace */
+ TEXT_SAVE_ATOMIC, /* create a new file, write content, atomically rename(2) over old file */
+ TEXT_SAVE_INPLACE, /* truncate file, overwrite content (any error will result in data loss) */
+};
+
/* save the whole text to the given `filename'. Return true if succesful.
* In which case an implicit snapshot is taken. The save might associate a
* new inode to file. */
@@ -138,7 +144,7 @@ bool text_save_range(Text*, Filerange*, const char *file);
* 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);
+TextSave *text_save_begin(Text*, const char *filename, enum TextSaveMethod);
ssize_t text_save_write_range(TextSave*, Filerange*);
/* try committing the changes to disk */
bool text_save_commit(TextSave*);