summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorGlenn L McGrath2004-02-17 12:22:21 +0000
committerGlenn L McGrath2004-02-17 12:22:21 +0000
commit01cdb66987906ca375feeaa9ff71b91c8469756c (patch)
tree55c3a91d86d37486e2b47624b37368beaa25b4e0 /coreutils
parenta8f756fc7fed3b57fa154ec70a9c9b4a4a3d90af (diff)
downloadbusybox-01cdb66987906ca375feeaa9ff71b91c8469756c.zip
busybox-01cdb66987906ca375feeaa9ff71b91c8469756c.tar.gz
Add the -r option, patch from Rob with some help from myself.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/date.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index 1aa3e22..a6b595e 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) {