Mercurial > vim
diff src/undo.c @ 2266:ae2e615a7320 vim73
Fix tiny build, move functions to undo.c.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 14 Jun 2010 01:39:13 +0200 |
parents | 771f21e35ec5 |
children | c08f91142c41 |
line wrap: on
line diff
--- a/src/undo.c +++ b/src/undo.c @@ -102,6 +102,8 @@ static void u_freeentry __ARGS((u_entry_ #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;