[BusyBox-cvs] busybox/coreutils date.c,1.43,1.44
Glenn McGrath
bug1 at busybox.net
Tue Feb 17 12:22:24 UTC 2004
Update of /var/cvs/busybox/coreutils
In directory nail:/tmp/cvs-serv27620/coreutils
Modified Files:
date.c
Log Message:
Add the -r option, patch from Rob with some help from myself.
Index: date.c
===================================================================
RCS file: /var/cvs/busybox/coreutils/date.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- date.c 17 Feb 2004 07:58:04 -0000 1.43
+++ date.c 17 Feb 2004 12:22:21 -0000 1.44
@@ -118,8 +118,9 @@
#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 @@
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 @@
# 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 @@
/* 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) {
More information about the busybox-cvs
mailing list