use utimes() rather than obsolescent utime()

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This commit is contained in:
Bernhard Reutner-Fischer
2009-11-15 00:12:53 +01:00
parent cc8b6871a7
commit a307af1af6
4 changed files with 13 additions and 17 deletions

View File

@@ -49,13 +49,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
"date\0" Required_argument "d"
;
# endif
struct utimbuf timebuf;
struct timeval timebuf = {.tv_usec = 0};
char *reference_file = NULL;
char *date_str = NULL;
#else
# define reference_file NULL
# define date_str NULL
# define timebuf (*(struct utimbuf*)NULL)
# define timebuf (*(struct timeval*)NULL)
#endif
int fd;
int status = EXIT_SUCCESS;
@@ -83,8 +83,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
if (reference_file) {
struct stat stbuf;
xstat(reference_file, &stbuf);
timebuf.actime = stbuf.st_atime;
timebuf.modtime = stbuf.st_mtime;
timebuf.tv_sec = stbuf.st_mtime;
}
if (date_str) {
@@ -100,12 +99,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
tm_time.tm_isdst = -1; /* Be sure to recheck dst */
t = validate_tm_time(date_str, &tm_time);
timebuf.actime = t;
timebuf.modtime = t;
timebuf.tv_sec = t;
}
do {
if (utime(*argv, reference_file ? &timebuf : NULL)) {
if (utimes(*argv, reference_file ? &timebuf : NULL)) {
if (errno == ENOENT) { /* no such file */
if (opts) { /* creation is disabled, so ignore */
continue;
@@ -116,7 +114,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
);
if ((fd >= 0) && !close(fd)) {
if (reference_file)
utime(*argv, &timebuf);
utimes(*argv, &timebuf);
continue;
}
}