0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

Fix tiny build, move functions to undo.c.

This commit is contained in:
Bram Moolenaar
2010-06-14 01:39:13 +02:00
parent 80794b1ce6
commit 191e0a2bc7
4 changed files with 63 additions and 67 deletions

View File

@@ -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;