stat doesn't work in vc.net 2003?

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.
 
E

Eberhard Schefold

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?
 
B

Ben Voigt

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.
 
O

one2001boy

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;
}
 
B

Ben Voigt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top