This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Fix utimes (was Re: utimes())
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Ulrich Drepper <drepper at redhat dot com>, Roland McGrath <roland at redhat dot com>, Greg Schafer <gschafer at zip dot com dot au>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Thu, 31 Jul 2003 14:47:35 +0200
- Subject: [PATCH] Fix utimes (was Re: utimes())
- References: <20030731122612.GA620@tigers-lfs.nsw.bigpond.net.au>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Jul 31, 2003 at 10:26:12PM +1000, Greg Schafer wrote:
> Consider this:-
>
> ----------
> #include <stdlib.h>
> #include <sys/time.h>
> #include <time.h>
>
> int main()
> {
> time_t now;
> struct timeval tvp[2];
> time(&now);
> tvp[1].tv_sec = now + 100;
> utimes("foo.dat", tvp);
> exit(0);
> }
The testcase is wrong, you are passing 3 uninitialized values to utimes.
But sysdeps/unix/sysv/linux/utimes.c is wrong as well, it will set
actime and modtime to either 1 (unless tvp[0].tv_sec+tv_usec is very low).
2003-07-31 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/utimes.c (__utimes): Add parens so that
actime and modtime are computed properly.
--- libc/sysdeps/unix/sysv/linux/utimes.c.jj 2003-07-14 17:15:43.000000000 -0400
+++ libc/sysdeps/unix/sysv/linux/utimes.c 2003-07-31 08:43:08.000000000 -0400
@@ -47,8 +47,8 @@ __utimes (const char *file, const struct
if (tvp != NULL)
{
times = &buf;
- buf.actime = tvp[0].tv_sec + tvp[0].tv_usec >= 500000;
- buf.modtime = tvp[1].tv_sec + tvp[1].tv_usec >= 500000;
+ buf.actime = tvp[0].tv_sec + (tvp[0].tv_usec >= 500000);
+ buf.modtime = tvp[1].tv_sec + (tvp[1].tv_usec >= 500000);
}
else
times = NULL;
Jakub