diff options
Diffstat (limited to 'coreutils/touch.c')
-rw-r--r-- | coreutils/touch.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c index 7d434a233..1b4a5f0ea 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c | |||
@@ -41,31 +41,34 @@ int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
41 | int touch_main(int argc UNUSED_PARAM, char **argv) | 41 | int touch_main(int argc UNUSED_PARAM, char **argv) |
42 | { | 42 | { |
43 | #if ENABLE_DESKTOP | 43 | #if ENABLE_DESKTOP |
44 | #if ENABLE_LONG_OPTS | 44 | # if ENABLE_LONG_OPTS |
45 | static const char longopts[] ALIGN1 = | 45 | static const char touch_longopts[] ALIGN1 = |
46 | /* name, has_arg, val */ | 46 | /* name, has_arg, val */ |
47 | "no-create\0" No_argument "c" | 47 | "no-create\0" No_argument "c" |
48 | "reference\0" Required_argument "r" | 48 | "reference\0" Required_argument "r" |
49 | "date\0" Required_argument "d" | ||
49 | ; | 50 | ; |
50 | #endif | 51 | # endif |
51 | struct utimbuf timebuf; | 52 | struct utimbuf timebuf; |
52 | char *reference_file = NULL; | 53 | char *reference_file = NULL; |
54 | char *date_str = NULL; | ||
53 | #else | 55 | #else |
54 | #define reference_file NULL | 56 | # define reference_file NULL |
55 | #define timebuf (*(struct utimbuf*)NULL) | 57 | # define date_str NULL |
58 | # define timebuf (*(struct utimbuf*)NULL) | ||
56 | #endif | 59 | #endif |
57 | int fd; | 60 | int fd; |
58 | int status = EXIT_SUCCESS; | 61 | int status = EXIT_SUCCESS; |
59 | int opts; | 62 | int opts; |
60 | 63 | ||
61 | #if ENABLE_DESKTOP | 64 | #if ENABLE_DESKTOP && ENABLE_LONG_OPTS |
62 | #if ENABLE_LONG_OPTS | 65 | applet_long_options = touch_longopts; |
63 | applet_long_options = longopts; | ||
64 | #endif | 66 | #endif |
65 | #endif | 67 | opts = getopt32(argv, "c" IF_DESKTOP("r:d:") |
66 | opts = getopt32(argv, "c" IF_DESKTOP("r:") | ||
67 | /*ignored:*/ "fma" | 68 | /*ignored:*/ "fma" |
68 | IF_DESKTOP(, &reference_file)); | 69 | IF_DESKTOP(, &reference_file) |
70 | IF_DESKTOP(, &date_str) | ||
71 | ); | ||
69 | 72 | ||
70 | opts &= 1; /* only -c bit is left */ | 73 | opts &= 1; /* only -c bit is left */ |
71 | argv += optind; | 74 | argv += optind; |
@@ -80,6 +83,23 @@ int touch_main(int argc UNUSED_PARAM, char **argv) | |||
80 | timebuf.modtime = stbuf.st_mtime; | 83 | timebuf.modtime = stbuf.st_mtime; |
81 | } | 84 | } |
82 | 85 | ||
86 | if (date_str) { | ||
87 | struct tm tm_time; | ||
88 | time_t t; | ||
89 | |||
90 | //time(&t); | ||
91 | //localtime_r(&t, &tm_time); | ||
92 | memset(&tm_time, 0, sizeof(tm_time)); | ||
93 | parse_datestr(date_str, &tm_time); | ||
94 | |||
95 | /* Correct any day of week and day of year etc. fields */ | ||
96 | tm_time.tm_isdst = -1; /* Be sure to recheck dst */ | ||
97 | t = validate_tm_time(date_str, &tm_time); | ||
98 | |||
99 | timebuf.actime = t; | ||
100 | timebuf.modtime = t; | ||
101 | } | ||
102 | |||
83 | do { | 103 | do { |
84 | if (utime(*argv, reference_file ? &timebuf : NULL)) { | 104 | if (utime(*argv, reference_file ? &timebuf : NULL)) { |
85 | if (errno == ENOENT) { /* no such file */ | 105 | if (errno == ENOENT) { /* no such file */ |