aboutsummaryrefslogtreecommitdiff
path: root/coreutils/touch.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-18 03:41:29 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-18 03:41:29 +0200
commit7aca89a7a32a1e560c447952c28a8b1e7fb775fc (patch)
treeb988939ee5fc2cf2235847d5f04ba5887b185e05 /coreutils/touch.c
parent73b71f381d24218cf6368364be723a7b5c9aeda9 (diff)
downloadbusybox-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/touch.c')
-rw-r--r--coreutils/touch.c42
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;
41int touch_main(int argc UNUSED_PARAM, char **argv) 41int 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 */