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>
This commit is contained in:
@ -85,8 +85,19 @@ int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|||||||
int touch_main(int argc UNUSED_PARAM, char **argv)
|
int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int status = EXIT_SUCCESS;
|
|
||||||
int opts;
|
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 {
|
enum {
|
||||||
OPT_c = (1 << 0),
|
OPT_c = (1 << 0),
|
||||||
OPT_h = (1 << 1) * ENABLE_FEATURE_TOUCH_NODEREF,
|
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")
|
IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h")
|
||||||
;
|
;
|
||||||
#endif
|
#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,
|
/* -d and -t both set time. In coreutils,
|
||||||
* accepted data format differs a bit between -d and -t.
|
* accepted data format differs a bit between -d and -t.
|
||||||
* We accept the same formats for both
|
* 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")
|
IF_FEATURE_TOUCH_SUSV3("r:d:t:am")
|
||||||
/*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am")
|
/*ignored:*/ "f" IF_NOT_FEATURE_TOUCH_SUSV3("am")
|
||||||
"\0" /* opt_complementary: */
|
"\0" /* opt_complementary: */
|
||||||
/* coreutils forbids -r and -t at once: */ IF_FEATURE_TOUCH_SUSV3("r--t:t--r")
|
/* at least one arg: */ "-1"
|
||||||
/* but allows these combinations: "r--d:d--r:t--d:d--t" */,
|
/* coreutils forbids -r and -t at once: */ IF_FEATURE_TOUCH_SUSV3(":r--t:t--r")
|
||||||
touch_longopts
|
/* but allows these combinations: "r--d:d--r:t--d:d--t" */
|
||||||
|
, touch_longopts
|
||||||
#if ENABLE_FEATURE_TOUCH_SUSV3
|
#if ENABLE_FEATURE_TOUCH_SUSV3
|
||||||
, &reference_file
|
, &reference_file
|
||||||
, &date_str
|
, &date_str
|
||||||
@ -135,13 +136,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
argv += optind;
|
|
||||||
if (!*argv) {
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
timebuf[0].tv_nsec = timebuf[1].tv_nsec = UTIME_NOW;
|
timebuf[0].tv_nsec = timebuf[1].tv_nsec = UTIME_NOW;
|
||||||
|
|
||||||
if (reference_file) {
|
if (reference_file) {
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
xstat(reference_file, &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[0].tv_nsec = stbuf.st_atim.tv_nsec;
|
||||||
timebuf[1].tv_nsec = stbuf.st_mtim.tv_nsec;
|
timebuf[1].tv_nsec = stbuf.st_mtim.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (date_str) {
|
if (date_str) {
|
||||||
struct tm tm_time;
|
struct tm tm_time;
|
||||||
time_t t;
|
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_sec = timebuf[0].tv_sec = t;
|
||||||
timebuf[1].tv_nsec = timebuf[0].tv_nsec = 0;
|
timebuf[1].tv_nsec = timebuf[0].tv_nsec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts & OPT_a) {
|
if (opts & OPT_a) {
|
||||||
timebuf[1].tv_nsec = UTIME_OMIT;
|
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;
|
timebuf[0].tv_nsec = UTIME_OMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
argv += optind;
|
||||||
do {
|
do {
|
||||||
int result = utimensat(AT_FDCWD, *argv, timebuf,
|
int result = utimensat(AT_FDCWD, *argv, timebuf,
|
||||||
(opts & OPT_h) ? AT_SYMLINK_NOFOLLOW : 0);
|
(opts & OPT_h) ? AT_SYMLINK_NOFOLLOW : 0);
|
||||||
|
Reference in New Issue
Block a user