• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

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