Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Strange Behaviour in finding Size of a File
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Keith Thompson  
View profile  
 More options Nov 9 2012, 2:34 pm
Newsgroups: comp.lang.c
From: Keith Thompson <ks...@mib.org>
Date: Fri, 09 Nov 2012 11:34:54 -0800
Local: Fri, Nov 9 2012 2:34 pm
Subject: Re: Strange Behaviour in finding Size of a File

felix <ckpra...@gmail.com> writes:
> 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 )
> {
>    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.

It's been pointed out that 1048576 is the wrong value if you want 10 MB
(more pedantically, 10 MiB).  But LogSize is also the wrong type.
It should be the same type as the st_size member.

You probably want to use "const" rather than "static" in the definition
of LogSize, unless the value can change.

Neither of these is likely to be the cause of the problem you're seeing.
Since stat() is defined by POSIX, not by C, you'll likely get better
answers in comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks...@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.