diff options
author | peter <peter@FreeBSD.org> | 2002-11-15 22:43:56 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2002-11-15 22:43:56 +0000 |
commit | 5044bd9ace87bfc9ba423a4ea2003b64b244ba2c (patch) | |
tree | a0eafd5feb222b2bf80af2251cfd704f0cd26f7c /usr.bin | |
parent | 97526c738c4cd08d52cb022605460e34b2f0b80f (diff) | |
download | FreeBSD-src-5044bd9ace87bfc9ba423a4ea2003b64b244ba2c.zip FreeBSD-src-5044bd9ace87bfc9ba423a4ea2003b64b244ba2c.tar.gz |
A little bit of anti-foot-shooting. Use utimes(2) rather than
the deprecated utime(3). utimes(2) uses timeval, but utime(3) uses
time_t's. If you do bad things (like I did) by mixing up include files
with libc, then install can do strange things if you mismatch the time_t
stuff. utime() is emulated entirely within libc.
Approved by: re (jhb)
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/xinstall/xinstall.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 4d7e683..c856bf2 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <sysexits.h> #include <unistd.h> -#include <utime.h> #include "pathnames.h" @@ -262,7 +261,7 @@ void install(const char *from_name, const char *to_name, u_long fset, u_int flags) { struct stat from_sb, temp_sb, to_sb; - struct utimbuf utb; + struct timeval tvb[2]; int devnull, files_match, from_fd, serrno, target; int tempcopy, temp_fd, to_fd; char backup[MAXPATHLEN], *p, pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN]; @@ -377,9 +376,11 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags) * Need to preserve target file times, though. */ if (to_sb.st_nlink != 1) { - utb.actime = to_sb.st_atime; - utb.modtime = to_sb.st_mtime; - (void)utime(tempfile, &utb); + tvb[0].tv_sec = to_sb.st_atime; + tvb[0].tv_usec = 0; + tvb[1].tv_sec = to_sb.st_mtime; + tvb[1].tv_usec = 0; + (void)utimes(tempfile, tvb); } else { files_match = 1; (void)unlink(tempfile); @@ -433,9 +434,11 @@ install(const char *from_name, const char *to_name, u_long fset, u_int flags) * Preserve the timestamp of the source file if necessary. */ if (dopreserve && !files_match && !devnull) { - utb.actime = from_sb.st_atime; - utb.modtime = from_sb.st_mtime; - (void)utime(to_name, &utb); + tvb[0].tv_sec = from_sb.st_atime; + tvb[0].tv_usec = 0; + tvb[1].tv_sec = from_sb.st_mtime; + tvb[1].tv_usec = 0; + (void)utimes(to_name, tvb); } if (fstat(to_fd, &to_sb) == -1) { |