aboutsummaryrefslogtreecommitdiff
path: root/bin/date/date.c
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2015-05-07 20:54:38 +0000
committerXin LI <delphij@FreeBSD.org>2015-05-07 20:54:38 +0000
commit8b45db8ee2a9476c41bb5fd666a31dfc6a2546c2 (patch)
treeae793dd03e9e340d820063d2713250a1044c231b /bin/date/date.c
parent1cba33332992490a84dc872f27f2acb4efc5b858 (diff)
downloadsrc-8b45db8ee2a9476c41bb5fd666a31dfc6a2546c2.tar.gz
src-8b45db8ee2a9476c41bb5fd666a31dfc6a2546c2.zip
date(1): Make -r behave like GNU's version when the option can not be
interpreted as a number, which checks the file's modification time and use that as the date/time value. This improves compatibility with GNU coreutils's version of time(1). MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=282608
Diffstat (limited to 'bin/date/date.c')
-rw-r--r--bin/date/date.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/bin/date/date.c b/bin/date/date.c
index 2c09848a151e..9ae6502e2a7e 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <ctype.h>
#include <err.h>
@@ -85,6 +86,7 @@ main(int argc, char *argv[])
struct vary *v;
const struct vary *badv;
struct tm lt;
+ struct stat sb;
v = NULL;
fmt = NULL;
@@ -116,8 +118,12 @@ main(int argc, char *argv[])
case 'r': /* user specified seconds */
rflag = 1;
tval = strtoq(optarg, &tmp, 0);
- if (*tmp != 0)
- usage();
+ if (*tmp != 0) {
+ if (stat(optarg, &sb) == 0)
+ tval = sb.st_mtim.tv_sec;
+ else
+ usage();
+ }
break;
case 't': /* minutes west of UTC */
/* error check; don't allow "PST" */