From a307af1af62c51e33e2801d74dbc35560af0fc0e Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 15 Nov 2009 00:12:53 +0100 Subject: use utimes() rather than obsolescent utime() Signed-off-by: Bernhard Reutner-Fischer --- coreutils/touch.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'coreutils/touch.c') diff --git a/coreutils/touch.c b/coreutils/touch.c index e79092f..7d1bf0d 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c @@ -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; } } -- cgit v1.1