diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fileio.c | 57 | ||||
-rw-r--r-- | src/proto/fileio.pro | 2 | ||||
-rw-r--r-- | src/undo.c | 60 |
3 files changed, 59 insertions, 60 deletions
diff --git a/src/fileio.c b/src/fileio.c index bfc11d0d9..aad76170e 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3011,63 +3011,6 @@ prepare_crypt_write(buf, lenp) #endif /* FEAT_CRYPT */ -/* - * Like fwrite() but crypt the bytes when 'key' is set. - * Returns 1 if successful. - */ - 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. - */ - 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; -} - - #ifdef UNIX static void set_file_time(fname, atime, mtime) diff --git a/src/proto/fileio.pro b/src/proto/fileio.pro index 75285dfef..88d3c27ea 100644 --- a/src/proto/fileio.pro +++ b/src/proto/fileio.pro @@ -4,8 +4,6 @@ int readfile __ARGS((char_u *fname, char_u *sfname, linenr_T from, linenr_T line int prep_exarg __ARGS((exarg_T *eap, buf_T *buf)); int prepare_crypt_read __ARGS((FILE *fp)); char_u *prepare_crypt_write __ARGS((buf_T *buf, int *lenp)); -size_t fwrite_crypt __ARGS((buf_T *buf, char_u *ptr, size_t len, FILE *fp)); -char_u *read_string_decrypt __ARGS((buf_T *buf, FILE *fd, int len)); int check_file_readonly __ARGS((char_u *fname, int perm)); int buf_write __ARGS((buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering)); void msg_add_fname __ARGS((buf_T *buf, char_u *fname)); 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; |