[PATCH v2 3/3] touch: add --time=what option
Xabier Oneca -- xOneca
xoneca at gmail.com
Mon Apr 12 22:27:50 UTC 2021
This option is the long version of -a and -m.
function old new delta
touch_main 484 539 +55
.rodata 103649 103680 +31
static.touch_longopts 49 56 +7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 93/0) Total: 93 bytes
v2: code shrink.
---
coreutils/touch.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/coreutils/touch.c b/coreutils/touch.c
index 6a4ffb400..0b94b7a39 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -76,7 +76,9 @@
* -t STAMP
* use [[CC]YY]MMDDhhmm[.ss] instead of current time
* --time=WORD
- * change the specified time: WORD is access, atime, or use
+ * change the specified time:
+ * WORD is access, atime, or use: equivalent to -a
+ * WORD is modify or mtime: equivalent to -m
*/
#include "libbb.h"
@@ -104,12 +106,14 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
"no-create\0" No_argument "c"
IF_FEATURE_TOUCH_SUSV3("reference\0" Required_argument "r")
IF_FEATURE_TOUCH_SUSV3("date\0" Required_argument "d")
+ IF_FEATURE_TOUCH_SUSV3("time\0" Required_argument "\x7f")
IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
;
#endif
#if ENABLE_FEATURE_TOUCH_SUSV3
char *reference_file = NULL;
char *date_str = NULL;
+ IF_LONG_OPTS(char *time_arg = NULL;)
/* timebuf[0] is atime, timebuf[1] is mtime */
struct timespec timebuf[2];
//timebuf[0].tv_sec = timebuf[1].tv_sec = 0; /* -- needed on
Linux <=v2.6.26? */
@@ -136,6 +140,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
, &reference_file
, &date_str
, &date_str
+ IF_LONG_OPTS(, &time_arg)
#endif
);
@@ -144,6 +149,24 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
}
+#if ENABLE_FEATURE_TOUCH_SUSV3 && ENABLE_LONG_OPTS
+ if (time_arg) {
+ static const char *time_values ALIGN1 =
+ /* OPT_a: */ "access\0" "atime\0" "use\0"
+ /* OPT_m: */ "modify\0" "mtime\0";
+ int pos = index_in_substrings(time_values, time_arg);
+
+ if (pos >= 3) {
+ opts |= OPT_m;
+ } else if (pos >= 0) {
+ opts |= OPT_a;
+ } else {
+ //bb_error_msg("Invalid value: %s", time_arg);
+ bb_show_usage();
+ }
+ }
+#endif
+
if (reference_file) {
struct stat stbuf;
xstat(reference_file, &stbuf);
--
2.30.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0003-touch-add-time-what-option.patch
Type: text/x-patch
Size: 2799 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210413/112e1250/attachment-0001.bin>
More information about the busybox
mailing list