touch: do not ignore argument of -d/-t option

Previously -d/-t was no-op due to wrong handling of args passed to
utimes(2).

Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Mikhail Gusarov 2010-03-21 14:22:47 +06:00 committed by Denys Vlasenko
parent 53f72bb3f0
commit 927e4bb644

View File

@ -104,7 +104,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
} }
do { do {
if (utimes(*argv, reference_file ? timebuf : NULL) != 0) { if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) {
if (errno == ENOENT) { /* no such file */ if (errno == ENOENT) { /* no such file */
if (opts) { /* creation is disabled, so ignore */ if (opts) { /* creation is disabled, so ignore */
continue; continue;
@ -113,7 +113,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
fd = open(*argv, O_RDWR | O_CREAT, 0666); fd = open(*argv, O_RDWR | O_CREAT, 0666);
if (fd >= 0) { if (fd >= 0) {
xclose(fd); xclose(fd);
if (reference_file) if (reference_file || date_str)
utimes(*argv, timebuf); utimes(*argv, timebuf);
continue; continue;
} }