Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2006

Tip: Looking for answers? Try searching our database.

stat doesn't work in vc.net 2003?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
one2001boy@yahoo.com - 07 Nov 2006 08:06 GMT
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.
Eberhard Schefold - 07 Nov 2006 12:50 GMT
> 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?
one2001boy@yahoo.com - 08 Nov 2006 02:24 GMT
>> 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?

Under C, it is NTFS.
Under D, it is fat32.
but I run the program under C drive.
one2001boy@yahoo.com - 08 Nov 2006 04:55 GMT
>> 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.
Ben Voigt - 08 Nov 2006 14:45 GMT
>>> 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
[quoted text clipped - 4 lines]
> 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.
one2001boy@yahoo.com - 09 Nov 2006 05:51 GMT
> 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;
}
Ben Voigt - 10 Nov 2006 16:35 GMT
>> Have you used any registry tricks to improve NTFS performance?  Not
>> generating short filenames and not updating access times are two
[quoted text clipped - 5 lines]
> 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/WindowsServer/en/library/8cc5891d-bf8e-4164-862d-d
ac5418c59481033.mspx?mfr=true

and search for "Last Access Time".

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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.