-/* $OpenBSD: exf.c,v 1.35 2015/04/19 01:10:59 millert Exp $ */
+/* $OpenBSD: exf.c,v 1.36 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
#include <sys/queue.h>
#include <sys/stat.h>
+#include <sys/time.h>
/*
* We include <sys/file.h>, because the flock(2) and open(2) #defines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "common.h"
if (!LF_ISSET(FS_OPENERR))
F_SET(frp, FR_NEWFILE);
- time(&ep->mtime);
+ (void)clock_gettime(CLOCK_REALTIME, &ep->mtim);
} else {
/*
* XXX
ep->mdev = sb.st_dev;
ep->minode = sb.st_ino;
- ep->mtime = sb.st_mtime;
+ ep->mtim = sb.st_mtim;
if (!S_ISREG(sb.st_mode))
msgq_str(sp, M_ERR, oname,
if (noname && !LF_ISSET(FS_FORCE | FS_APPEND) &&
((F_ISSET(ep, F_DEVSET) &&
(sb.st_dev != ep->mdev || sb.st_ino != ep->minode)) ||
- sb.st_mtime != ep->mtime)) {
+ timespeccmp(&sb.st_mtim, &ep->mtim, !=))) {
msgq_str(sp, M_ERR, name, LF_ISSET(FS_POSSIBLE) ?
"250|%s: file modified more recently than this copy; use ! to override" :
"251|%s: file modified more recently than this copy");
*/
if (noname) {
if (stat(name, &sb))
- time(&ep->mtime);
+ (void)clock_gettime(CLOCK_REALTIME, &ep->mtim);
else {
F_SET(ep, F_DEVSET);
ep->mdev = sb.st_dev;
ep->minode = sb.st_ino;
- ep->mtime = sb.st_mtime;
+ ep->mtim = sb.st_mtim;
}
}
-/* $OpenBSD: exf.h,v 1.4 2001/01/29 01:58:29 niklas Exp $ */
+/* $OpenBSD: exf.h,v 1.5 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
LIST_HEAD(_markh, _lmark) marks;/* Linked list of file MARK's. */
- /*
- * XXX
- * Mtime should be a struct timespec, but time_t is more portable.
- */
dev_t mdev; /* Device. */
ino_t minode; /* Inode. */
- time_t mtime; /* Last modification time. */
+ struct timespec mtim; /* Last modification time. */
int fcntl_fd; /* Fcntl locking fd; see exf.c. */
-/* $OpenBSD: recover.c,v 1.21 2015/03/27 04:11:25 brynet Exp $ */
+/* $OpenBSD: recover.c,v 1.22 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1993, 1994
#include <sys/queue.h>
#include <sys/stat.h>
+#include <sys/time.h>
/*
* We include <sys/file.h>, because the open #defines were found there
struct stat sb;
DIR *dirp;
EXF *ep;
- time_t rec_mtime;
+ struct timespec rec_mtim;
int fd, found, locked, requested, sv_fd;
char *name, *p, *t, *rp, *recp, *pathp;
char file[PATH_MAX], path[PATH_MAX], recpath[PATH_MAX];
name = frp->name;
sv_fd = -1;
- rec_mtime = 0;
+ rec_mtim.tv_sec = rec_mtim.tv_nsec = 0;
recp = pathp = NULL;
for (found = requested = 0; (dp = readdir(dirp)) != NULL;) {
if (strncmp(dp->d_name, "recover.", 8))
/*
* If we've found more than one, take the most recent.
- *
- * XXX
- * Since we're using st_mtime, for portability reasons,
- * we only get a single second granularity, instead of
- * getting it right.
*/
(void)fstat(fd, &sb);
- if (recp == NULL || rec_mtime < sb.st_mtime) {
+ if (recp == NULL ||
+ timespeccmp(&rec_mtim, &sb.st_mtim, <)) {
p = recp;
t = pathp;
if ((recp = strdup(recpath)) == NULL) {
free(p);
free(t);
}
- rec_mtime = sb.st_mtime;
+ rec_mtim = sb.st_mtim;
if (sv_fd != -1)
(void)close(sv_fd);
sv_fd = fd;
-/* $OpenBSD: ex_cscope.c,v 1.25 2015/04/21 01:41:42 jsg Exp $ */
+/* $OpenBSD: ex_cscope.c,v 1.26 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1994, 1996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <termios.h>
#include <unistd.h>
csc->dname = csc->buf;
csc->dlen = len;
memcpy(csc->dname, dname, len);
- csc->mtime = sb.st_mtime;
+ csc->mtim = sb.st_mtim;
/* Get the search paths for the cscope. */
if (get_paths(sp, csc))
if (stat(buf, &sb) == 0) {
*dirp = *pp;
*dlenp = strlen(*pp);
- *isolderp = sb.st_mtime < csc->mtime;
+ *isolderp = timespeccmp(
+ &sb.st_mtim, &csc->mtim, <);
return;
}
}
-/* $OpenBSD: tag.h,v 1.5 2013/12/01 19:26:37 krw Exp $ */
+/* $OpenBSD: tag.h,v 1.6 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
char *dname; /* Base directory of this cscope connection. */
size_t dlen; /* Length of base directory. */
pid_t pid; /* PID of the connected cscope process. */
- time_t mtime; /* Last modification time of cscope database. */
+ struct timespec mtim; /* Last modification time of cscope database. */
FILE *from_fp; /* from cscope: FILE. */
int from_fd; /* from cscope: file descriptor. */
-/* $OpenBSD: vi.h,v 1.7 2013/11/28 22:12:40 krw Exp $ */
+/* $OpenBSD: vi.h,v 1.8 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1992, 1993, 1994
size_t busy_fx; /* Busy character x coordinate. */
size_t busy_oldy; /* Saved y coordinate. */
size_t busy_oldx; /* Saved x coordinate. */
- struct timeval busy_tv; /* Busy timer. */
+ struct timespec busy_ts;/* Busy timer. */
char *ps; /* Paragraph plus section list. */
-/* $OpenBSD: vs_msg.c,v 1.13 2014/11/12 04:28:41 bentley Exp $ */
+/* $OpenBSD: vs_msg.c,v 1.14 2015/04/24 21:48:31 brynet Exp $ */
/*-
* Copyright (c) 1993, 1994
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "../common/common.h"
GS *gp;
VI_PRIVATE *vip;
static const char flagc[] = "|/-\\";
- struct timeval tv;
+ struct timespec ts, ts_diff;
size_t len, notused;
const char *p;
/* Initialize state for updates. */
vip->busy_ch = 0;
- (void)gettimeofday(&vip->busy_tv, NULL);
+ (void)clock_gettime(CLOCK_MONOTONIC, &vip->busy_ts);
/* Save the current cursor. */
(void)gp->scr_cursor(sp, &vip->busy_oldy, &vip->busy_oldx);
break;
/* Update no more than every 1/8 of a second. */
- (void)gettimeofday(&tv, NULL);
- if (((tv.tv_sec - vip->busy_tv.tv_sec) * 1000000 +
- (tv.tv_usec - vip->busy_tv.tv_usec)) < 125000)
+ (void)clock_gettime(CLOCK_MONOTONIC, &ts);
+ ts_diff = ts;
+ ts_diff.tv_sec -= vip->busy_ts.tv_sec;
+ ts_diff.tv_nsec -= vip->busy_ts.tv_nsec;
+ if (ts_diff.tv_nsec < 0) {
+ ts_diff.tv_sec--;
+ ts_diff.tv_nsec += 1000000000;
+ }
+ if ((ts_diff.tv_sec == 0 && ts_diff.tv_nsec < 125000000) ||
+ ts_diff.tv_sec < 0)
return;
- vip->busy_tv = tv;
+ vip->busy_ts = ts;
/* Display the update. */
if (vip->busy_ch == sizeof(flagc) - 1)