aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2009-11-15 00:12:53 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2009-11-15 00:12:53 +0100
commita307af1af62c51e33e2801d74dbc35560af0fc0e (patch)
tree8d1164763328f7b580afceda831b979de97b7da7
parentcc8b6871a71e42a3e0bdb79e534b90cc3eb4c8e6 (diff)
downloadbusybox-w32-a307af1af62c51e33e2801d74dbc35560af0fc0e.tar.gz
busybox-w32-a307af1af62c51e33e2801d74dbc35560af0fc0e.tar.bz2
busybox-w32-a307af1af62c51e33e2801d74dbc35560af0fc0e.zip
use utimes() rather than obsolescent utime()
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r--archival/libunarchive/data_extract_all.c6
-rw-r--r--coreutils/touch.c14
-rw-r--r--libbb/copy_file.c8
-rwxr-xr-xtestsuite/all_sourcecode.tests2
4 files changed, 13 insertions, 17 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index 0d529a616..889face10 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -143,9 +143,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
143 } 143 }
144 /* same for utime */ 144 /* same for utime */
145 if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) { 145 if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
146 struct utimbuf t; 146 struct timeval t = {.tv_sec = file_header->mtime,
147 t.actime = t.modtime = file_header->mtime; 147 .tv_usec = 0};
148 utime(file_header->name, &t); 148 utimes(file_header->name, &t);
149 } 149 }
150 } 150 }
151} 151}
diff --git a/coreutils/touch.c b/coreutils/touch.c
index e79092fc1..7d1bf0d9e 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -49,13 +49,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
49 "date\0" Required_argument "d" 49 "date\0" Required_argument "d"
50 ; 50 ;
51# endif 51# endif
52 struct utimbuf timebuf; 52 struct timeval timebuf = {.tv_usec = 0};
53 char *reference_file = NULL; 53 char *reference_file = NULL;
54 char *date_str = NULL; 54 char *date_str = NULL;
55#else 55#else
56# define reference_file NULL 56# define reference_file NULL
57# define date_str NULL 57# define date_str NULL
58# define timebuf (*(struct utimbuf*)NULL) 58# define timebuf (*(struct timeval*)NULL)
59#endif 59#endif
60 int fd; 60 int fd;
61 int status = EXIT_SUCCESS; 61 int status = EXIT_SUCCESS;
@@ -83,8 +83,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
83 if (reference_file) { 83 if (reference_file) {
84 struct stat stbuf; 84 struct stat stbuf;
85 xstat(reference_file, &stbuf); 85 xstat(reference_file, &stbuf);
86 timebuf.actime = stbuf.st_atime; 86 timebuf.tv_sec = stbuf.st_mtime;
87 timebuf.modtime = stbuf.st_mtime;
88 } 87 }
89 88
90 if (date_str) { 89 if (date_str) {
@@ -100,12 +99,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
100 tm_time.tm_isdst = -1; /* Be sure to recheck dst */ 99 tm_time.tm_isdst = -1; /* Be sure to recheck dst */
101 t = validate_tm_time(date_str, &tm_time); 100 t = validate_tm_time(date_str, &tm_time);
102 101
103 timebuf.actime = t; 102 timebuf.tv_sec = t;
104 timebuf.modtime = t;
105 } 103 }
106 104
107 do { 105 do {
108 if (utime(*argv, reference_file ? &timebuf : NULL)) { 106 if (utimes(*argv, reference_file ? &timebuf : NULL)) {
109 if (errno == ENOENT) { /* no such file */ 107 if (errno == ENOENT) { /* no such file */
110 if (opts) { /* creation is disabled, so ignore */ 108 if (opts) { /* creation is disabled, so ignore */
111 continue; 109 continue;
@@ -116,7 +114,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
116 ); 114 );
117 if ((fd >= 0) && !close(fd)) { 115 if ((fd >= 0) && !close(fd)) {
118 if (reference_file) 116 if (reference_file)
119 utime(*argv, &timebuf); 117 utimes(*argv, &timebuf);
120 continue; 118 continue;
121 } 119 }
122 } 120 }
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index ff298855d..a96691b24 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -374,12 +374,10 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
374 /* Cannot happen: */ 374 /* Cannot happen: */
375 /* && !(flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) */ 375 /* && !(flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) */
376 ) { 376 ) {
377 struct utimbuf times; 377 struct timeval times = {.tv_sec = source_stat.st_mtime,
378 378 .tv_usec = 0};
379 times.actime = source_stat.st_atime;
380 times.modtime = source_stat.st_mtime;
381 /* BTW, utimes sets usec-precision time - just FYI */ 379 /* BTW, utimes sets usec-precision time - just FYI */
382 if (utime(dest, &times) < 0) 380 if (utimes(dest, &times) < 0)
383 bb_perror_msg("can't preserve %s of '%s'", "times", dest); 381 bb_perror_msg("can't preserve %s of '%s'", "times", dest);
384 if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) { 382 if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) {
385 source_stat.st_mode &= ~(S_ISUID | S_ISGID); 383 source_stat.st_mode &= ~(S_ISUID | S_ISGID);
diff --git a/testsuite/all_sourcecode.tests b/testsuite/all_sourcecode.tests
index 94f4360b2..071399c28 100755
--- a/testsuite/all_sourcecode.tests
+++ b/testsuite/all_sourcecode.tests
@@ -73,7 +73,7 @@ rm -f src.typos
73# don't allow obsolete functions 73# don't allow obsolete functions
74# 74#
75find $srcdir/.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \ 75find $srcdir/.. '(' -name '*.c' -o -name '*.h' ')' -print0 | xargs -0 \
76 grep -E -e '\<(bcmp|bcopy|bzero|getwd|index|mktemp|rindex|utimes|sigblock|siggetmask|sigsetmask)\>[[:space:]]*\(' \ 76 grep -E -e '\<(bcmp|bcopy|bzero|getwd|index|mktemp|rindex|utime|sigblock|siggetmask|sigsetmask)\>[[:space:]]*\(' \
77 | sed -e "s:^$srcdir/\.\./::g" > src.obsolete.funcs 77 | sed -e "s:^$srcdir/\.\./::g" > src.obsolete.funcs
78testing "Obsolete function usage" "cat src.obsolete.funcs" "" "" "" 78testing "Obsolete function usage" "cat src.obsolete.funcs" "" "" ""
79rm -f src.obsolete.funcs 79rm -f src.obsolete.funcs