This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix utimes (was Re: utimes())


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]