summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-05-21 18:59:11 +0000
committerdelphij <delphij@FreeBSD.org>2015-05-21 18:59:11 +0000
commitf14ca7e990e6d5c28f5f21d1b2ab19979227cbc9 (patch)
treecde425df03a69e4164a5b35f7f88c0afe25c2533 /bin
parent6ce5eda96c3bedbd34633c5234de0efd98d88bca (diff)
downloadFreeBSD-src-f14ca7e990e6d5c28f5f21d1b2ab19979227cbc9.zip
FreeBSD-src-f14ca7e990e6d5c28f5f21d1b2ab19979227cbc9.tar.gz
MFC r282608:
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 date(1).
Diffstat (limited to 'bin')
-rw-r--r--bin/date/date.17
-rw-r--r--bin/date/date.c10
2 files changed, 13 insertions, 4 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1
index 5e9e664..dd791ec 100644
--- a/bin/date/date.1
+++ b/bin/date/date.1
@@ -32,7 +32,7 @@
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
-.Dd April 26, 2014
+.Dd May 7, 2015
.Dt DATE 1
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl jRu
-.Op Fl r Ar seconds
+.Op Fl r Ar seconds | Ar filename
.Oo
.Fl v
.Sm off
@@ -150,6 +150,9 @@ is the number of seconds since the Epoch
see
.Xr time 3 ) ,
and can be specified in decimal, octal, or hex.
+.It Fl r Ar filename
+Print the date and time of the last modification of
+.Ar filename .
.It Fl t Ar minutes_west
Set the system's value for minutes west of
.Tn GMT .
diff --git a/bin/date/date.c b/bin/date/date.c
index 2c09848..9ae6502 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" */
OpenPOWER on IntegriCloud