Re: Stat mod time

From: Mr. Wizard (jsbarrow@husc.harvard.edu)
Date: 09/07/94


On Wed, 7 Sep 1994, Jeremy Elson wrote:

> No, it wasn't a typo.  The code above won't compile; the '->' should be a '.'
> as I'd originally said.
> 
> What I meant was that the version of the code which declared statbuf as a
> 'struct stat *' (note * at the end) should have used '->' instead of '.'.
> But, that had the additional problem of not setting the statbuf pointer to
> actually point at anything.
> 
> My version of the code does not declare statbuf to be a pointer and thus
> does not require a CREATE, and requires a '.' instead of '->'.

Heh.  I wasn't lookign close enough.  Didn't realize you had declared it 
as a struct as opposed to a pointer to a struct.
 
> To clear up any confusion, I'll give two versions of the code.  Both work,
> but the first is better for obvious reasons.
> 
> Method 1:
> 
> struct stat statbuf;
> time_t modified time;
> 
> stat(MOTD_FILE, &statbuf);
> modified_time = statbuf.st_mtime;
> 
> 
> 
> Method 2:
> 
> struct stat *statbuf;
> time_t modified time;
> 
> CREATE(statbuf, struct stat, 1);
> stat(MOTD_FILE, statbuf);
> modified_time = statbuf->st_mtime;
> free(statbuf);
> 
> 
> 
> Jeremy

##=====================###================================================##
||  Joshua Sky Barrow  ||| Harvard University Faculty of Arts and Science ||
##=====================###================================================##
|| 19 Central St., #28 ||| "If you can imagine it, you can achieve it.    ||
|| Somerville, MA      |||  If you can dream it, you can become it."      ||
|| 02143-2834          |||                                   Unknown      ||
##=====================###================================================##
|| (617) 666-0859      ||| E-mail:  jsbarrow@fas.harvard.edu              ||
##=====================###================================================##



This archive was generated by hypermail 2b30 : 12/07/00 PST