diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-08-21 20:28:54 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-08-21 20:28:54 +0200 |
commit | 00f123a56585363cd13f062fd3bb123efcfaa664 (patch) | |
tree | 7c8fb2556c2b395cb4d6035a1b0299f05073e409 /src/memline.c | |
parent | 8e82c057ffb86cec3210ad8a22ad3f21d52e0953 (diff) | |
download | vim-git-00f123a56585363cd13f062fd3bb123efcfaa664.tar.gz |
patch 8.1.0313: information about a swap file is unavailablev8.1.0313
Problem: Information about a swap file is unavailable.
Solution: Add swapinfo(). (Enzo Ferber)
Diffstat (limited to 'src/memline.c')
-rw-r--r-- | src/memline.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/memline.c b/src/memline.c index fbdd8a372..660e89c11 100644 --- 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). */ |