diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-02-17 12:22:21 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-02-17 12:22:21 +0000 |
| commit | 01cdb66987906ca375feeaa9ff71b91c8469756c (patch) | |
| tree | 55c3a91d86d37486e2b47624b37368beaa25b4e0 /coreutils | |
| parent | a8f756fc7fed3b57fa154ec70a9c9b4a4a3d90af (diff) | |
| download | busybox-w32-01cdb66987906ca375feeaa9ff71b91c8469756c.tar.gz busybox-w32-01cdb66987906ca375feeaa9ff71b91c8469756c.tar.bz2 busybox-w32-01cdb66987906ca375feeaa9ff71b91c8469756c.zip | |
Add the -r option, patch from Rob with some help from myself.
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/date.c | 15 |
1 files changed, 11 insertions, 4 deletions
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) | |||
| 118 | #define DATE_OPT_SET 0x02 | 118 | #define DATE_OPT_SET 0x02 |
| 119 | #define DATE_OPT_UTC 0x04 | 119 | #define DATE_OPT_UTC 0x04 |
| 120 | #define DATE_OPT_DATE 0x08 | 120 | #define DATE_OPT_DATE 0x08 |
| 121 | #define DATE_OPT_REFERENCE 0x10 | ||
| 121 | #ifdef CONFIG_FEATURE_DATE_ISOFMT | 122 | #ifdef CONFIG_FEATURE_DATE_ISOFMT |
| 122 | # define DATE_OPT_TIMESPEC 0x10 | 123 | # define DATE_OPT_TIMESPEC 0x20 |
| 123 | #endif | 124 | #endif |
| 124 | 125 | ||
| 125 | int date_main(int argc, char **argv) | 126 | int date_main(int argc, char **argv) |
| @@ -133,6 +134,7 @@ int date_main(int argc, char **argv) | |||
| 133 | time_t tm; | 134 | time_t tm; |
| 134 | unsigned long opt; | 135 | unsigned long opt; |
| 135 | struct tm tm_time; | 136 | struct tm tm_time; |
| 137 | char *filename = NULL; | ||
| 136 | 138 | ||
| 137 | #ifdef CONFIG_FEATURE_DATE_ISOFMT | 139 | #ifdef CONFIG_FEATURE_DATE_ISOFMT |
| 138 | int ifmt = 0; | 140 | int ifmt = 0; |
| @@ -143,8 +145,8 @@ int date_main(int argc, char **argv) | |||
| 143 | # define GETOPT_ISOFMT | 145 | # define GETOPT_ISOFMT |
| 144 | #endif | 146 | #endif |
| 145 | bb_opt_complementaly = "d~ds:s~ds"; | 147 | bb_opt_complementaly = "d~ds:s~ds"; |
| 146 | opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT, | 148 | opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT, |
| 147 | &date_str, &date_str | 149 | &date_str, &date_str, &filename |
| 148 | #ifdef CONFIG_FEATURE_DATE_ISOFMT | 150 | #ifdef CONFIG_FEATURE_DATE_ISOFMT |
| 149 | , &isofmt_arg | 151 | , &isofmt_arg |
| 150 | #endif | 152 | #endif |
| @@ -194,7 +196,12 @@ int date_main(int argc, char **argv) | |||
| 194 | /* Now we have parsed all the information except the date format | 196 | /* Now we have parsed all the information except the date format |
| 195 | which depends on whether the clock is being set or read */ | 197 | which depends on whether the clock is being set or read */ |
| 196 | 198 | ||
| 197 | time(&tm); | 199 | if(filename) { |
| 200 | struct stat statbuf; | ||
| 201 | if(stat(filename,&statbuf)) | ||
| 202 | bb_perror_msg_and_die("File '%s' not found.\n",filename); | ||
| 203 | tm=statbuf.st_mtime; | ||
| 204 | } else time(&tm); | ||
| 198 | memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); | 205 | memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); |
| 199 | /* Zero out fields - take her back to midnight! */ | 206 | /* Zero out fields - take her back to midnight! */ |
| 200 | if (date_str != NULL) { | 207 | if (date_str != NULL) { |
