Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Aug 2001 11:15:56 +0930 (CST)
From:      "Daniel O'Connor" <doconnor@gsoft.com.au>
To:        Joseph Gleason <clash@tasam.com>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   RE: Finding filesizes in C++ for files greater than 4gb
Message-ID:  <XFMail.20010802111556.doconnor@gsoft.com.au>
In-Reply-To: <00b201c11af3$4fef1c10$0a2d2d0a@battleship>

next in thread | previous in thread | raw e-mail | index | archive | help

On 02-Aug-2001 Joseph Gleason wrote:
>  Currently, I use stat() and use st_size.  That is limited to 4gb (32bit
>  unsigned int)
>  
>  I could use st_blocks, but that wouldn't give me the exact size.
>  
>  (st_blocks -1) * 512 + (st_size % 512)
>  
>  This would make sense, but in tests st_blocks is larger than I would expect.
>  I assume it means that st_blocks is how many blocks the file takes up on the
>  filesystem, and does not directly translate to how large the file is.

st_size is an off_t which is typedef'd to _BSD_OFF_T_ which is #define'd as
__int64_t.

So.. you're program should grok >4Gb files.

>  I have some C++ utilities for manipulating files.  I have recently (and not
>  supprisingly) discovered that my program has issues with file sizes greater
>  than 4gb because I use an unsigned int for something.  I guess I will have
>  to switch to unsigned long long, which appears to be a 64bit int.

I would explicitly use off_t for file offsets/sizes which is what it is
designed for.

If you want an explicit bit width use it, eg u_int64_t etc.

That way you get what you ask for rather than second guessing the implementor.
 
---
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20010802111556.doconnor>