summaryrefslogtreecommitdiff
path: root/src/undo.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2010-06-14 01:39:13 +0200
committerBram Moolenaar <Bram@vim.org>2010-06-14 01:39:13 +0200
commit191e0a2bc7cb4787e19aa1f8c6958b47e05d7882 (patch)
tree33740966cf8b50b85665b6c779eb29639dab7d60 /src/undo.c
parent80794b1ce64b394fe6a1355ddd7159d1c97d6f48 (diff)
downloadvim-git-191e0a2bc7cb4787e19aa1f8c6958b47e05d7882.tar.gz
Fix tiny build, move functions to undo.c.
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/undo.c b/src/undo.c
index 592604ff3..07412acc5 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -102,6 +102,8 @@ static void u_freeentry __ARGS((u_entry_T *, long));
#ifdef FEAT_PERSISTENT_UNDO
static void corruption_error __ARGS((char *msg, char_u *file_name));
static void u_free_uhp __ARGS((u_header_T *uhp));
+static size_t fwrite_crypt __ARGS((buf_T *buf UNUSED, char_u *ptr, size_t len, FILE *fp));
+static char_u *read_string_decrypt __ARGS((buf_T *buf UNUSED, FILE *fd, int len));
static int serialize_header __ARGS((FILE *fp, buf_T *buf, char_u *hash));
static int serialize_uhp __ARGS((FILE *fp, buf_T *buf, u_header_T *uhp));
static u_header_T *unserialize_uhp __ARGS((FILE *fp, char_u *file_name));
@@ -661,7 +663,7 @@ nomem:
return FAIL;
}
-#ifdef FEAT_PERSISTENT_UNDO
+#if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO)
# define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */
# define UF_START_MAGIC_LEN 9
@@ -801,6 +803,62 @@ u_free_uhp(uhp)
vim_free(uhp);
}
+/*
+ * Like fwrite() but crypt the bytes when 'key' is set.
+ * Returns 1 if successful.
+ */
+ static size_t
+fwrite_crypt(buf, ptr, len, fp)
+ buf_T *buf UNUSED;
+ char_u *ptr;
+ size_t len;
+ FILE *fp;
+{
+#ifdef FEAT_CRYPT
+ char_u *copy;
+ char_u small_buf[100];
+ size_t i;
+
+ if (*buf->b_p_key == NUL)
+ return fwrite(ptr, len, (size_t)1, fp);
+ if (len < 100)
+ copy = small_buf; /* no malloc()/free() for short strings */
+ else
+ {
+ copy = lalloc(len, FALSE);
+ if (copy == NULL)
+ return 0;
+ }
+ crypt_encode(ptr, len, copy);
+ i = fwrite(copy, len, (size_t)1, fp);
+ if (copy != small_buf)
+ vim_free(copy);
+ return i;
+#else
+ return fwrite(ptr, len, (size_t)1, fp);
+#endif
+}
+
+/*
+ * Read a string of length "len" from "fd".
+ * When 'key' is set decrypt the bytes.
+ */
+ static char_u *
+read_string_decrypt(buf, fd, len)
+ buf_T *buf UNUSED;
+ FILE *fd;
+ int len;
+{
+ char_u *ptr;
+
+ ptr = read_string(fd, len);
+#ifdef FEAT_CRYPT
+ if (ptr != NULL || *buf->b_p_key != NUL)
+ crypt_decode(ptr, len);
+#endif
+ return ptr;
+}
+
static int
serialize_header(fp, buf, hash)
FILE *fp;