• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Problem with timestamp code under SunOS...

Hi,

I'm using the following code to compare timestamps between two files.

  struct stat fbuf;
  int i,fres;
  long time1=0,time2=0;

  fres = stat ("file1.c",&fbuf);
  if (fres == 0) {
    if (debug) printf ("file1.c, size=%d, date=%s (%d)\n",fbuf.st_size,ctime(&fbuf.st_atime),fbuf.st_atime);
    time1 = fbuf.st_atime;
  }
  fres = stat ("file2",&fbuf);
  if (fres == 0) {
    if (debug) printf ("file2, size=%d, date=%s (%d)\n",fbuf.st_size,ctime(&fbuf.st_atime),fbuf.st_atime);
    time2 = fbuf.st_atime;
  }

File1.c is a C module which is compiled and made with other modules to create an executable, File2. The problem is that sometimes this code returns the correct timestamp on File1.c, sometimes not. Here's one example (this is running on SunOS, I have not see the problem occur under Linux):

Debug dump from program execution:
file1.c, size=10888, date=Wed Apr 13 17:02:36 2005
 (1113436956)
file2, size=7273948, date=Thu Apr 14 15:07:32 2005
 (1113516452)

Timestamps from SunOS:
> ls -alrt file*
-rwxr-xr-x   1 userj    pedft    7273948 Apr 14 15:07 file2
-rwxr-xr-x   1 uesrj    pedft      10888 Apr 14 15:25 file1.c

jimdgar


0
jimdgar
Asked:
jimdgar
1 Solution
 
grg99Commented:
There are several different kinds of timestamps.  Depending on the OS, there may be time of file creation, time of last read, time of last write, or time of last open.    I suspect the ls command prints one of these, and you're printing a different one.  They'd be the same for a newly created file, so you'll get the same results some of the time, but not in general.


Figure out which one you makes more sense for your needs and stick to that one.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now