alter() wants to set the file's access time to the future without changing
the modification time. utimensat() can do the latter directly with
UTIME_OMIT, eliminating the need for the stat(). Since we're using
timespecs instead of timevals, we can use clock_gettime(CLOCK_REALTIME)
instead of gettimeofday().
Finally, since gettimeofday() was the last thing requiring <sys/time.h>,
we can stop #including it. (Yeah yeah, it'll still be pulled in via other
headers, but that's not this code's fault)
ok?
Philip Guenther
Index: aux.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/aux.c,v
retrieving revision 1.27
diff -u -p -r1.27 aux.c
--- aux.c 16 Jan 2015 06:40:09 -0000 1.27
+++ aux.c 11 Oct 2015 03:50:03 -0000
@@ -31,6 +31,7 @@
*/
#include "rcv.h"
+#include <fcntl.h>
#include "extern.h"
/*
@@ -328,19 +329,12 @@ unstack(void)
void
alter(char *name)
{
- struct stat sb;
- struct timeval tv[2];
+ struct timespec ts[2];
- if (stat(name, &sb))
- return;
- (void) gettimeofday(&tv[0], (struct timezone *)0);
- tv[0].tv_sec++;
-#ifdef TIMESPEC_TO_TIMEVAL
- TIMESPEC_TO_TIMEVAL(&tv[1], &sb.st_mtimespec);
-#else
- tv[1].tv_sec = sb.st_mtime;
-#endif
- (void)utimes(name, tv);
+ clock_gettime(CLOCK_REALTIME, &ts[0]);
+ ts[0].tv_sec++;
+ ts[1].tv_nsec = UTIME_OMIT;
+ (void)utimensat(AT_FDCWD, name, ts, 0);
}
/*
Index: def.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/def.h,v
retrieving revision 1.15
diff -u -p -r1.15 def.h
--- def.h 20 Jan 2015 16:59:07 -0000 1.15
+++ def.h 11 Oct 2015 03:50:03 -0000
@@ -43,7 +43,6 @@
#define MAIL_DEF_H
#include <sys/stat.h>
-#include <sys/time.h>
#include <ctype.h>
#include <err.h>