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 | |
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>
-rw-r--r-- | coreutils/date.c | 7 | ||||
-rw-r--r-- | coreutils/touch.c | 42 | ||||
-rw-r--r-- | coreutils/uname.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | include/usage.h | 5 | ||||
-rw-r--r-- | libbb/time.c | 9 | ||||
-rwxr-xr-x | testsuite/bunzip2.tests | 4 | ||||
-rwxr-xr-x | testsuite/bzcat.tests | 4 | ||||
-rw-r--r-- | testsuite/cp/cp-a-files-to-dir | 2 | ||||
-rw-r--r-- | testsuite/mv/mv-files-to-dir | 2 | ||||
-rw-r--r-- | testsuite/mv/mv-refuses-mv-dir-to-subdir | 2 | ||||
-rwxr-xr-x | testsuite/runtest | 11 |
12 files changed, 64 insertions, 29 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 */ |
diff --git a/include/libbb.h b/include/libbb.h index 9de52331b..936d98a23 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -438,6 +438,7 @@ struct BUG_too_small { | |||
438 | 438 | ||
439 | 439 | ||
440 | void parse_datestr(const char *date_str, struct tm *tm_time) FAST_FUNC; | 440 | void parse_datestr(const char *date_str, struct tm *tm_time) FAST_FUNC; |
441 | time_t validate_tm_time(const char *date_str, struct tm *tm_time) FAST_FUNC; | ||
441 | 442 | ||
442 | 443 | ||
443 | int xsocket(int domain, int type, int protocol) FAST_FUNC; | 444 | int xsocket(int domain, int type, int protocol) FAST_FUNC; |
diff --git a/include/usage.h b/include/usage.h index 53ae0a8cc..9493b6d4b 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -4556,11 +4556,12 @@ | |||
4556 | "and show the status for however many processes will fit on the screen." \ | 4556 | "and show the status for however many processes will fit on the screen." \ |
4557 | 4557 | ||
4558 | #define touch_trivial_usage \ | 4558 | #define touch_trivial_usage \ |
4559 | "[-c] FILE [FILE]..." | 4559 | "[-c] [-d DATE] FILE [FILE]..." |
4560 | #define touch_full_usage "\n\n" \ | 4560 | #define touch_full_usage "\n\n" \ |
4561 | "Update the last-modified date on the given FILE[s]\n" \ | 4561 | "Update the last-modified date on the given FILE[s]\n" \ |
4562 | "\nOptions:" \ | 4562 | "\nOptions:" \ |
4563 | "\n -c Do not create any files" \ | 4563 | "\n -c Do not create files" \ |
4564 | "\n -d DT Date/time to use" \ | ||
4564 | 4565 | ||
4565 | #define touch_example_usage \ | 4566 | #define touch_example_usage \ |
4566 | "$ ls -l /tmp/foo\n" \ | 4567 | "$ ls -l /tmp/foo\n" \ |
diff --git a/libbb/time.c b/libbb/time.c index 30b760f71..1cf2a050e 100644 --- a/libbb/time.c +++ b/libbb/time.c | |||
@@ -71,6 +71,15 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time) | |||
71 | } | 71 | } |
72 | } | 72 | } |
73 | 73 | ||
74 | time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *tm_time) | ||
75 | { | ||
76 | time_t t = mktime(tm_time); | ||
77 | if (t == (time_t) -1L) { | ||
78 | bb_error_msg_and_die(bb_msg_invalid_date, date_str); | ||
79 | } | ||
80 | return t; | ||
81 | } | ||
82 | |||
74 | #if ENABLE_MONOTONIC_SYSCALL | 83 | #if ENABLE_MONOTONIC_SYSCALL |
75 | 84 | ||
76 | #include <sys/syscall.h> | 85 | #include <sys/syscall.h> |
diff --git a/testsuite/bunzip2.tests b/testsuite/bunzip2.tests index a7555aca9..7875cd1ae 100755 --- a/testsuite/bunzip2.tests +++ b/testsuite/bunzip2.tests | |||
@@ -517,8 +517,8 @@ if test "${0##*/}" = "bunzip2.tests"; then | |||
517 | if test1_bz2 | ${bb}bunzip2 >/dev/null \ | 517 | if test1_bz2 | ${bb}bunzip2 >/dev/null \ |
518 | && test "`test1_bz2 | ${bb}bunzip2 | md5sum`" = "61bbeee4be9c6f110a71447f584fda7b -" | 518 | && test "`test1_bz2 | ${bb}bunzip2 | md5sum`" = "61bbeee4be9c6f110a71447f584fda7b -" |
519 | then | 519 | then |
520 | echo "$unpack: test bz2 file: PASS" | 520 | echo "PASS: $unpack: test bz2 file" |
521 | else | 521 | else |
522 | echo "$unpack: test bz2 file: FAIL" | 522 | echo "FAIL: $unpack: test bz2 file" |
523 | fi | 523 | fi |
524 | fi | 524 | fi |
diff --git a/testsuite/bzcat.tests b/testsuite/bzcat.tests index 0bc744244..78d74f229 100755 --- a/testsuite/bzcat.tests +++ b/testsuite/bzcat.tests | |||
@@ -32,9 +32,9 @@ prep() { | |||
32 | check() { | 32 | check() { |
33 | eval $2 >t_actual 2>&1 | 33 | eval $2 >t_actual 2>&1 |
34 | if $ECHO -ne "$expected" | cmp - t_actual; then | 34 | if $ECHO -ne "$expected" | cmp - t_actual; then |
35 | echo "$1: PASS" | 35 | echo "PASS: $1" |
36 | else | 36 | else |
37 | echo "$1: FAIL" | 37 | echo "FAIL: $1" |
38 | fi | 38 | fi |
39 | } | 39 | } |
40 | 40 | ||
diff --git a/testsuite/cp/cp-a-files-to-dir b/testsuite/cp/cp-a-files-to-dir index abdbdf77d..b199ef9b9 100644 --- a/testsuite/cp/cp-a-files-to-dir +++ b/testsuite/cp/cp-a-files-to-dir | |||
@@ -3,7 +3,7 @@ echo file number two > file2 | |||
3 | ln -s file2 link1 | 3 | ln -s file2 link1 |
4 | mkdir dir1 | 4 | mkdir dir1 |
5 | # why??? | 5 | # why??? |
6 | #touch --date='Sat Jan 29 21:24:08 PST 2000' dir1/file3 | 6 | #TZ=UTC0 touch -d '2000-01-30 05:24:08' dir1/file3 |
7 | mkdir there | 7 | mkdir there |
8 | busybox cp -a file1 file2 link1 dir1 there | 8 | busybox cp -a file1 file2 link1 dir1 there |
9 | test -f there/file1 | 9 | test -f there/file1 |
diff --git a/testsuite/mv/mv-files-to-dir b/testsuite/mv/mv-files-to-dir index c8eaba88e..2b567f77f 100644 --- a/testsuite/mv/mv-files-to-dir +++ b/testsuite/mv/mv-files-to-dir | |||
@@ -2,7 +2,7 @@ echo file number one > file1 | |||
2 | echo file number two > file2 | 2 | echo file number two > file2 |
3 | ln -s file2 link1 | 3 | ln -s file2 link1 |
4 | mkdir dir1 | 4 | mkdir dir1 |
5 | touch --date='Sat Jan 29 21:24:08 PST 2000' dir1/file3 | 5 | TZ=UTC0 touch -d '2000-01-30 05:24:08' dir1/file3 |
6 | mkdir there | 6 | mkdir there |
7 | busybox mv file1 file2 link1 dir1 there | 7 | busybox mv file1 file2 link1 dir1 there |
8 | test -f there/file1 | 8 | test -f there/file1 |
diff --git a/testsuite/mv/mv-refuses-mv-dir-to-subdir b/testsuite/mv/mv-refuses-mv-dir-to-subdir index 7c572c4f8..3bad131a6 100644 --- a/testsuite/mv/mv-refuses-mv-dir-to-subdir +++ b/testsuite/mv/mv-refuses-mv-dir-to-subdir | |||
@@ -2,7 +2,7 @@ echo file number one > file1 | |||
2 | echo file number two > file2 | 2 | echo file number two > file2 |
3 | ln -s file2 link1 | 3 | ln -s file2 link1 |
4 | mkdir dir1 | 4 | mkdir dir1 |
5 | touch --date='Sat Jan 29 21:24:08 PST 2000' dir1/file3 | 5 | TZ=UTC0 touch -d '2000-01-30 05:24:08' dir1/file3 |
6 | mkdir there | 6 | mkdir there |
7 | busybox mv file1 file2 link1 dir1 there | 7 | busybox mv file1 file2 link1 dir1 there |
8 | test -f there/file1 | 8 | test -f there/file1 |
diff --git a/testsuite/runtest b/testsuite/runtest index 2d60591fb..5560f7bc2 100755 --- a/testsuite/runtest +++ b/testsuite/runtest | |||
@@ -120,12 +120,17 @@ fi | |||
120 | 120 | ||
121 | # Populate a directory with links to all busybox applets | 121 | # Populate a directory with links to all busybox applets |
122 | 122 | ||
123 | # Note: if $LINKSDIR/applet exists, we do not overwrite it. | ||
124 | # Useful if one wants to run tests against a standard utility, not an applet. | ||
125 | LINKSDIR="$bindir/runtest-tempdir-links" | 123 | LINKSDIR="$bindir/runtest-tempdir-links" |
126 | #rm -rf "$LINKSDIR" 2>/dev/null | 124 | |
125 | # Comment this line out if you have put a different binary in $LINKSDIR | ||
126 | # (say, a "standard" tool's binary) in order to run tests against it: | ||
127 | rm -rf "$LINKSDIR" 2>/dev/null | ||
128 | |||
127 | mkdir "$LINKSDIR" 2>/dev/null | 129 | mkdir "$LINKSDIR" 2>/dev/null |
128 | for i in $implemented; do | 130 | for i in $implemented; do |
131 | # Note: if $LINKSDIR/applet exists, we do not overwrite it. | ||
132 | # Useful if one wants to run tests against a standard utility, | ||
133 | # not an applet. | ||
129 | ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null | 134 | ln -s "$bindir/busybox" "$LINKSDIR/$i" 2>/dev/null |
130 | done | 135 | done |
131 | 136 | ||