From owner-freebsd-hackers Wed Aug 1 18:46:15 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from cain.gsoft.com.au (genesi.lnk.telstra.net [139.130.136.161]) by hub.freebsd.org (Postfix) with ESMTP id 3DF8637B403 for ; Wed, 1 Aug 2001 18:46:09 -0700 (PDT) (envelope-from doconnor@gsoft.com.au) Received: from cain.gsoft.com.au (root@spare0.gsoft.com.au [203.38.152.114]) by cain.gsoft.com.au (8.8.8/8.8.8) with ESMTP id LAA02208; Thu, 2 Aug 2001 11:15:57 +0930 (CST) (envelope-from doconnor@gsoft.com.au) Message-ID: X-Mailer: XFMail 1.4.7 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <00b201c11af3$4fef1c10$0a2d2d0a@battleship> Date: Thu, 02 Aug 2001 11:15:56 +0930 (CST) From: "Daniel O'Connor" To: Joseph Gleason Subject: RE: Finding filesizes in C++ for files greater than 4gb Cc: freebsd-hackers@FreeBSD.ORG Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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