Mercurial > vim
diff src/memline.c @ 14599:72d6f6f7ead7 v8.1.0313
patch 8.1.0313: information about a swap file is unavailable
commit https://github.com/vim/vim/commit/00f123a56585363cd13f062fd3bb123efcfaa664
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 21 20:28:54 2018 +0200
patch 8.1.0313: information about a swap file is unavailable
Problem: Information about a swap file is unavailable.
Solution: Add swapinfo(). (Enzo Ferber)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 21 Aug 2018 20:30:05 +0200 |
parents | b6b2f7d69c7f |
children | d0ff19a55579 |
line wrap: on
line diff
--- a/src/memline.c +++ b/src/memline.c @@ -2042,6 +2042,49 @@ static int process_still_running; #endif /* + * Return information found in swapfile "fname" in dictionary "d". + * This is used by the swapinfo() function. + */ + void +get_b0_dict(char_u *fname, dict_T *d) +{ + int fd; + struct block0 b0; + + if ((fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) >= 0) + { + if (read_eintr(fd, &b0, sizeof(b0)) == sizeof(b0)) + { + if (b0_magic_wrong(&b0)) + { + dict_add_string(d, "error", + vim_strsave((char_u *)"magic number mismatch")); + } + else + { + /* we have swap information */ + dict_add_string(d, "version", vim_strsave(b0.b0_version)); + dict_add_string(d, "user", vim_strsave(b0.b0_uname)); + dict_add_string(d, "host", vim_strsave(b0.b0_hname)); + dict_add_string(d, "fname", vim_strsave(b0.b0_fname)); + + dict_add_number(d, "pid", char_to_long(b0.b0_pid)); + dict_add_number(d, "mtime", char_to_long(b0.b0_mtime)); +#ifdef CHECK_INODE + dict_add_number(d, "inode", char_to_long(b0.b0_ino)); +#endif + } + } + else + dict_add_string(d, "error", + vim_strsave((char_u *)"Cannot read file")); + close(fd); + } + else + dict_add_string(d, "error", vim_strsave((char_u *)"Cannot open file")); +} + +/* * Give information about an existing swap file. * Returns timestamp (0 when unknown). */