diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-18 03:41:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-07-18 03:41:29 +0200 |
commit | 7aca89a7a32a1e560c447952c28a8b1e7fb775fc (patch) | |
tree | b988939ee5fc2cf2235847d5f04ba5887b185e05 /coreutils | |
parent | 73b71f381d24218cf6368364be723a7b5c9aeda9 (diff) | |
download | busybox-w32-7aca89a7a32a1e560c447952c28a8b1e7fb775fc.tar.gz busybox-w32-7aca89a7a32a1e560c447952c28a8b1e7fb775fc.tar.bz2 busybox-w32-7aca89a7a32a1e560c447952c28a8b1e7fb775fc.zip |
touch: implement -d --date (our own testsuite needs that)
function old new delta
static.uname_longopts - 137 +137
touch_main 231 360 +129
static.touch_longopts - 32 +32
validate_tm_time - 28 +28
packed_usage 26616 26624 +8
date_main 687 686 -1
static.longopts 162 - -162
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 2/1 up/down: 334/-163) Total: 171 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/date.c | 7 | ||||
-rw-r--r-- | coreutils/touch.c | 42 | ||||
-rw-r--r-- | coreutils/uname.c | 4 |
3 files changed, 36 insertions, 17 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index 7f2a5b351..09ced0ea1 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -142,12 +142,11 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
142 | } else { | 142 | } else { |
143 | parse_datestr(date_str, &tm_time); | 143 | parse_datestr(date_str, &tm_time); |
144 | } | 144 | } |
145 | |||
145 | /* Correct any day of week and day of year etc. fields */ | 146 | /* Correct any day of week and day of year etc. fields */ |
146 | tm_time.tm_isdst = -1; /* Be sure to recheck dst */ | 147 | tm_time.tm_isdst = -1; /* Be sure to recheck dst */ |
147 | tm = mktime(&tm_time); | 148 | tm = validate_tm_time(date_str, &tm_time); |
148 | if (tm < 0) { | 149 | |
149 | bb_error_msg_and_die(bb_msg_invalid_date, date_str); | ||
150 | } | ||
151 | maybe_set_utc(opt); | 150 | maybe_set_utc(opt); |
152 | 151 | ||
153 | /* if setting time, set it */ | 152 | /* if setting time, set it */ |
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 */ |
diff --git a/coreutils/uname.c b/coreutils/uname.c index df4566063..8453bcc01 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c | |||
@@ -74,7 +74,7 @@ int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
74 | int uname_main(int argc UNUSED_PARAM, char **argv) | 74 | int uname_main(int argc UNUSED_PARAM, char **argv) |
75 | { | 75 | { |
76 | #if ENABLE_LONG_OPTS | 76 | #if ENABLE_LONG_OPTS |
77 | static const char longopts[] ALIGN1 = | 77 | static const char uname_longopts[] ALIGN1 = |
78 | /* name, has_arg, val */ | 78 | /* name, has_arg, val */ |
79 | "all\0" No_argument "a" | 79 | "all\0" No_argument "a" |
80 | "kernel-name\0" No_argument "s" | 80 | "kernel-name\0" No_argument "s" |
@@ -97,7 +97,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv) | |||
97 | const unsigned short *delta; | 97 | const unsigned short *delta; |
98 | unsigned toprint; | 98 | unsigned toprint; |
99 | 99 | ||
100 | IF_LONG_OPTS(applet_long_options = longopts); | 100 | IF_LONG_OPTS(applet_long_options = uname_longopts); |
101 | toprint = getopt32(argv, options); | 101 | toprint = getopt32(argv, options); |
102 | 102 | ||
103 | if (argv[optind]) { /* coreutils-6.9 compat */ | 103 | if (argv[optind]) { /* coreutils-6.9 compat */ |