stat doesn't work in vc.net 2003?

  • Thread starter Thread starter one2001boy
  • Start date Start date
O

one2001boy

Hello,
I tried to find the access time of a file using stat() function.
but the following C code in windows vc.net 2003 always give
the same access time. the same code works correctly in linux gcc.
do I miss something?

#include <stdio.h>
#include <sys/stat.h>

int main() {
struct stat sbuf;
char *name="testfile";
FILE *fd;
char result[100];

if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fd = fopen(name, "r");
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fread(result, 3,1, fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fclose(fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
return 0;
}


thanks.
 
I tried to find the access time of a file using stat() function.
but the following C code in windows vc.net 2003 always give
the same access time. the same code works correctly in linux gcc.

Is the volume formatted with NTFS?
 
tried unde pure NTFS windows XP SP 2,
the same problem. the access time is never changed.

Have you used any registry tricks to improve NTFS performance? Not
generating short filenames and not updating access times are two favorites
for saving cycles.
 
Have you used any registry tricks to improve NTFS performance? Not
generating short filenames and not updating access times are two favorites
for saving cycles.


Not sure which registry value to look for not generating short filenames
or not updating access time?

are you able to run the following code successfully in windows xp
with different access time?

#include <stdio.h>
#include <sys/stat.h>

int main() {
struct stat sbuf;
char *name="c:\\windows\\win.ini";
FILE *fd;
char result[100];

if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fd = fopen(name, "r");
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fread(result, 3,1, fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fclose(fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
return 0;
}
 
Not sure which registry value to look for not generating short filenames
or not updating access time?

are you able to run the following code successfully in windows xp
with different access time?
Yes and no:

atime = 1163171213
atime = 1163171213
atime = 1163171213
atime = 1163175949


Second run:

atime = 1163175949
atime = 1163175949
atime = 1163175949
atime = 1163175949


See also
http://technet2.microsoft.com/Windo...bf8e-4164-862d-dac5418c59481033.mspx?mfr=true
and search for "Last Access Time".

Indeed, _fstat works considerably better, changing once per second.
 
Back
Top