From e80d859867e515d95492e61bf5dca08a1c325130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 14 Dec 2016 13:02:47 +0100 Subject: text: expose text save method to calling code There are cases where it is useful to specify how the file should be saved. --- text.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'text.h') 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*); -- cgit v1.2.3