utime misusage

Henry Spencer henry at utzoo.UUCP
Sat Dec 1 03:17:38 AEST 1984


> The instances you refer to are of the form:
> 
>         char *filename;
>         struct stat st;
>         ...
>         utime(filename, &st.st_atime);
> 
> Despite its rather inelegant appearance, why should this fail?
> 
> The second argument of utime(2) is expected to be the address of
> this kind of struct:
> 
>         struct utimbuf { time_t actime, modtime; } ubuf;
> 
> Using the address of the st_atime field of a stat(2) struct would
> provide these values correctly, because the word following st_atime in
> the structure is st_mtime (the mod. time).  Here's a picture:
> 
>  &st.st_atime -----> st_atime      &ubuf -----> actime
>                      st_mtime                   modtime
> 
> So is this really a bug, or is your C compiler acting strangely?

It's really a bug.  You are assuming that the st_atime + st_mtime fragment
of "struct stat" is laid out in memory the same way as a "struct utimbuf".
This is a compiler-dependent and system-dependent assumption, albeit one
that is often true on reasonable machines.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Net.bugs.usg mailing list