diff options
author | Denys Vlasenko | 2021-04-13 15:11:47 +0200 |
---|---|---|
committer | Denys Vlasenko | 2021-04-13 15:11:47 +0200 |
commit | 6f63a2ba0e54f7fc8ec66d470beb0212dd1b4d4f (patch) | |
tree | 322ea42f38b7669f648b8610b1c61b020893ddf1 /coreutils | |
parent | e3c6a0973c8a4fe17d2510093738ef5ae052523e (diff) | |
download | busybox-6f63a2ba0e54f7fc8ec66d470beb0212dd1b4d4f.zip busybox-6f63a2ba0e54f7fc8ec66d470beb0212dd1b4d4f.tar.gz |
touch: code shrink
function old new delta
.rodata 103215 103218 +3
touch_main 460 450 -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 3/-10) Total: -7 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/touch.c | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c index 189428a..43312d2 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c @@ -85,8 +85,19 @@ int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int touch_main(int argc UNUSED_PARAM, char **argv) { int fd; - int status = EXIT_SUCCESS; int opts; + smalluint status = EXIT_SUCCESS; +#if ENABLE_FEATURE_TOUCH_SUSV3 + char *reference_file = NULL; + char *date_str = NULL; + /* timebuf[0] is atime, timebuf[1] is mtime */ + struct timespec timebuf[2]; +#else +# define reference_file NULL +# define date_str NULL +# define timebuf ((struct timespec*)NULL) +#endif + enum { OPT_c = (1 << 0), OPT_h = (1 << 1) * ENABLE_FEATURE_TOUCH_NODEREF, @@ -105,17 +116,6 @@ int touch_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") ; #endif -#if ENABLE_FEATURE_TOUCH_SUSV3 - char *reference_file = NULL; - char *date_str = NULL; - /* timebuf[0] is atime, timebuf[1] is mtime */ - struct timespec timebuf[2]; -#else -# define reference_file NULL -# define date_str NULL -# define timebuf ((struct timespec*)NULL) -#endif - /* -d and -t both set time. In coreutils, * accepted data format differs a bit between -d and -t. * We accept the same formats for both @@ -125,9 +125,10 @@ int touch_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_TOUCH_SUSV3("r:d:t:am") /*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am") "\0" /* opt_complementary: */ - /* coreutils forbids -r and -t at once: */ IF_FEATURE_TOUCH_SUSV3("r--t:t--r") - /* but allows these combinations: "r--d:d--r:t--d:d--t" */, - touch_longopts + /* at least one arg: */ "-1" + /* coreutils forbids -r and -t at once: */ IF_FEATURE_TOUCH_SUSV3(":r--t:t--r") + /* but allows these combinations: "r--d:d--r:t--d:d--t" */ + , touch_longopts #if ENABLE_FEATURE_TOUCH_SUSV3 , &reference_file , &date_str @@ -135,13 +136,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv) #endif ); - argv += optind; - if (!*argv) { - bb_show_usage(); - } - timebuf[0].tv_nsec = timebuf[1].tv_nsec = UTIME_NOW; - if (reference_file) { struct stat stbuf; xstat(reference_file, &stbuf); @@ -150,7 +145,6 @@ int touch_main(int argc UNUSED_PARAM, char **argv) timebuf[0].tv_nsec = stbuf.st_atim.tv_nsec; timebuf[1].tv_nsec = stbuf.st_mtim.tv_nsec; } - if (date_str) { struct tm tm_time; time_t t; @@ -168,7 +162,6 @@ int touch_main(int argc UNUSED_PARAM, char **argv) timebuf[1].tv_sec = timebuf[0].tv_sec = t; timebuf[1].tv_nsec = timebuf[0].tv_nsec = 0; } - if (opts & OPT_a) { timebuf[1].tv_nsec = UTIME_OMIT; } @@ -176,6 +169,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv) timebuf[0].tv_nsec = UTIME_OMIT; } + argv += optind; do { int result = utimensat(AT_FDCWD, *argv, timebuf, (opts & OPT_h) ? AT_SYMLINK_NOFOLLOW : 0); |