Re: Stat mod time

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


On Wed, 7 Sep 1994, Jeremy Elson wrote:

> > Ok, thanks for all the help - things were looking good until...
> > 
> > This is the code I've got:
> > 
> > struct stat *statbuf;
> > time_t modified_time;
> > 
> > stat(MOTD_FILE, statbuf);
> > modified_time = statbuf.st_mtime;          /* this is line 1722 in the code *
> 
> The above code is wrong.  statbuf as you've declared it is a pointer to a
> structure, meaning you should use '->' instead of '.' to reference structures.
> But, there's the additional problem that you haven't actually initialized
> statbuf to point to anything in particular so it will most certainly crash
> if you try to run it.  The code should read:
> 
> struct stat statbuf;
> time_t modified time;
> 
> stat(MOTD_FILE, &statbuf);
> modified_time = statbuf.st_mtime;
> 
> J

I'm pretty sure this was just a typo, but shouldn't the code read:

struct stat statbuf;
time-t modified time;

stat(MOTD_FILE, &statbuf);  /* I missed the & error the first time :) */
modified_time = statbuf->st_mtime;

Since you mentioned it before, I am assuming the last line was just a typo. 

##=====================###================================================##
||  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