This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: st_blocks incorrect for files larger than 2Gbytes
- To: newlib <newlib at sources dot redhat dot com>
- Subject: Re: st_blocks incorrect for files larger than 2Gbytes
- From: "J. Johnston" <jjohnstn at cygnus dot com>
- Date: Thu, 27 Jul 2000 15:27:10 -0400
- CC: vinschen at cygnus dot com
- Organization: Cygnus Solutions
- References: <10678.000726@logos-m.ru> <397EDE85.F590E086@cygnus.com>
Corinna Vinschen wrote:
>
> Egor Duda wrote:
> >
> > Hi!
> >
> > newlib declares off_t as signed long and cygwin's stat calculates
> > st_blocks as
> >
> > buf->st_blocks = (buf->st_size + S_BLKSIZE-1) / S_BLKSIZE;
> >
> > i.e. for file with size 2.164.854.784 bytes stat returns st_blocks=-2080187
> > or big positive value, when assigned to (unsigned long). this may be
> > fixed in a)newlib or b)cygwin or c)application
> >
> > which way is preferable?
>
> SUSv2 defines an own type blkcnt_t for that purpose. This
> might be the best way.
>
Are you referring to st_blocks like glibc does in bits/stat.h? If so, then this won't solve
the problem. The problem is that the division is being performed as signed. The result when
assigned to either a signed or unsigned result will be incorrect.
POSIX states that st_size is off_t. An easy solution to this without changing types is to just have
Cygwin do the cast: (unsigned long)buf->st_size in the calculation. This gives the correct positive
value which can indeed be stored in st_blocks.
-- Jeff Johnston