Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!henry
From: henry@utzoo.UUCP (Henry Spencer)
Newsgroups: net.bugs.usg,net.lang.c
Subject: Re: utime misusage
Message-ID: <4702@utzoo.UUCP>
Date: Fri, 30-Nov-84 12:17:38 EST
Article-I.D.: utzoo.4702
Posted: Fri Nov 30 12:17:38 1984
Date-Received: Fri, 30-Nov-84 12:17:38 EST
References: <6114@brl-tgr.ARPA>, <613@amdahl.UUCP>
Organization: U of Toronto Zoology
Lines: 30

> 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