On Friday, 9 November 2012 17:26:28 UTC+5:30, James Kuyper wrote:
> On 11/09/2012 02:09 AM, felix wrote:
>
> > This method was written to create new Log File, when the size of the Log File reaches a max size defined by user [10MB in our case]. Here is the code snippet that does this check:
>
> >
>
> > //-- Code starts here : --
>
> >
>
> > static size_t LogSize = 1048576;
>
> > bool CreateNewLogs = false;
>
> >
>
> >
>
> > if ( stat ( logFile, &results ) == 0 )
>
>
>
> That is presumably the POSIX stat() function, or something similar? If
>
> so, its behavior is defined by the POSIX standard, not the C standard,
>
> and you'll get better answers to your questions in comp.unix.programmer
>
> than in this newsgroup.
>
>
>
> > {
>
> > if ( results.st_size > LogSize )
>
> > {
>
> > CreateNewLogs = true;
>
> > }
>
> > }
>
> > //-- Code ends here : --
>
> >
>
> > It is strange that the condition got satisfied when results.st_size = 2589116.
>
> > And we are sure that the size of the data that is written is between 50 to 100 bytes in one operation. And this check is done before writing into the LogFile.
>
>
>
> Keep in mind that file I/O is normally buffered, so the buffer size is
>
> more relevant than the size of your individual writes. Still, that seems
>
> to be a rather large jump to explain by buffering.
>
>
>
> > I am not sure if I am missing anything in our understanding of the stat function. Any inputs or pointers on this regard will be really Helpful.
>
>
>
> The people in comp.unix.programming may need to know more details about
>
> how data is written to the file, and whether or not you've used any
>
> POSIX functions to change the file mode.
>
> Just to get a better idea of what's going on, I'd recommend reporting
>
> the file size somewhere (probably in a separate log file) every time you
>
> call stat().
>
> --
>
> James Kuyper
Thanks a Lot James and all others that helped me understand this problem.
As said above, the file I/O is buffered. The file size was not getting updated after each fwrite(). We tried to fflush() the after writing the data into log files. And now we see the correct size of the file.
We are trying to understand ftell()/fseek() also as suggested.
And thanks for suggestions regarding the constant - LogSize.
--
Felix