diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2015-07-07 18:34:13 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2015-07-07 18:34:13 +0000 |
commit | b84cd61057b6917d36e95f086d16f10e988858bb (patch) | |
tree | a7d73375b5496da186a32028b12d87acf1658191 /usr.bin/vi | |
parent | dabedadf9001f80ce337166e99639a6dc2cae544 (diff) |
Fix a regression caused by timespec changes when vi is run without
a file to edit. Based on a diff from Patrick Keshishian.
Diffstat (limited to 'usr.bin/vi')
-rw-r--r-- | usr.bin/vi/common/exf.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c index 5a6436123fc..33aee068c9b 100644 --- a/usr.bin/vi/common/exf.c +++ b/usr.bin/vi/common/exf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exf.c,v 1.36 2015/04/24 21:48:31 brynet Exp $ */ +/* $OpenBSD: exf.c,v 1.37 2015/07/07 18:34:12 millert Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -185,7 +185,8 @@ file_init(SCR *sp, FREF *frp, char *rcv_name, int flags) (void)snprintf(tname, sizeof(tname), "%s/vi.XXXXXXXXXX", O_STR(sp, O_TMP_DIRECTORY)); fd = mkstemp(tname); - if (fd == -1 || fchmod(fd, S_IRUSR | S_IWUSR) == -1) { + if (fd == -1 || fstat(fd, &sb) == -1 || + fchmod(fd, S_IRUSR | S_IWUSR) == -1) { msgq(sp, M_SYSERR, "237|Unable to create temporary file"); if (fd != -1) { @@ -210,8 +211,6 @@ file_init(SCR *sp, FREF *frp, char *rcv_name, int flags) psize = 1024; if (!LF_ISSET(FS_OPENERR)) F_SET(frp, FR_NEWFILE); - - (void)clock_gettime(CLOCK_REALTIME, &ep->mtim); } else { /* * XXX @@ -226,17 +225,18 @@ file_init(SCR *sp, FREF *frp, char *rcv_name, int flags) psize = 1; psize *= 1024; - F_SET(ep, F_DEVSET); - ep->mdev = sb.st_dev; - ep->minode = sb.st_ino; - - ep->mtim = sb.st_mtim; - if (!S_ISREG(sb.st_mode)) msgq_str(sp, M_ERR, oname, "238|Warning: %s is not a regular file"); } + /* Save device, inode and modification time. */ + F_SET(ep, F_DEVSET); + ep->mdev = sb.st_dev; + ep->minode = sb.st_ino; + + ep->mtim = sb.st_mtim; + /* Set up recovery. */ memset(&oinfo, 0, sizeof(RECNOINFO)); oinfo.bval = '\n'; /* Always set. */ |