From 01cdb66987906ca375feeaa9ff71b91c8469756c Mon Sep 17 00:00:00 2001
From: Glenn L McGrath <bug1@ihug.co.nz>
Date: Tue, 17 Feb 2004 12:22:21 +0000
Subject: Add the -r option, patch from Rob with some help from myself.

---
 coreutils/date.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

(limited to 'coreutils/date.c')

diff --git a/coreutils/date.c b/coreutils/date.c
index 1aa3e22d2..a6b595e57 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -118,8 +118,9 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
 #define DATE_OPT_SET    	0x02
 #define DATE_OPT_UTC    	0x04
 #define DATE_OPT_DATE   	0x08
+#define DATE_OPT_REFERENCE	0x10
 #ifdef CONFIG_FEATURE_DATE_ISOFMT
-# define DATE_OPT_TIMESPEC	0x10
+# define DATE_OPT_TIMESPEC	0x20
 #endif
 
 int date_main(int argc, char **argv)
@@ -133,6 +134,7 @@ int date_main(int argc, char **argv)
 	time_t tm;
 	unsigned long opt;
 	struct tm tm_time;
+	char *filename = NULL;
 
 #ifdef CONFIG_FEATURE_DATE_ISOFMT
 	int ifmt = 0;
@@ -143,8 +145,8 @@ int date_main(int argc, char **argv)
 # define GETOPT_ISOFMT
 #endif
 	bb_opt_complementaly = "d~ds:s~ds";
-	opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT,
-					&date_str, &date_str
+	opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT,
+					&date_str, &date_str, &filename
 #ifdef CONFIG_FEATURE_DATE_ISOFMT
 					, &isofmt_arg
 #endif
@@ -194,7 +196,12 @@ int date_main(int argc, char **argv)
 	/* Now we have parsed all the information except the date format
 	   which depends on whether the clock is being set or read */
 
-	time(&tm);
+	if(filename) {
+		struct stat statbuf;
+		if(stat(filename,&statbuf))
+			bb_perror_msg_and_die("File '%s' not found.\n",filename);
+		tm=statbuf.st_mtime;
+	} else time(&tm);
 	memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
 	/* Zero out fields - take her back to midnight! */
 	if (date_str != NULL) {
-- 
cgit v1.2.3-55-g6feb