*BSD News Article 48207


Return to BSD News archive

Newsgroups: comp.unix.bsd.freebsd.misc
Path: sserve!euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!swidir.switch.ch!scsing.switch.ch!news.belwue.de!fu-berlin.de!news.mathworks.com!newsfeed.internetmci.com!nntp-hub2.barrnet.net!news.Stanford.EDU!microunity!deborah
From: deborah@microunity.com (Deborah Gronke Bennett)
Subject: Re: Simple BSD code acting funny in FreeBSD (correctly in Linux)
Message-ID: <DD2CyK.A1x@microunity.com>
Sender: usenet@microunity.com (news id)
Organization: MicroUnity Systems Engineering, Inc.
X-Newsreader: NN version 6.5.0 #6
References: <DD06CB.It1@midway.uchicago.edu> <807927921.19978@pencotts.demon.co.uk>
Date: Wed, 9 Aug 1995 21:56:44 GMT
Lines: 29

Andrew Gordon <andrew.gordon@net-tel.co.uk> writes:

>The problem is that FreeBSD allows files larger than 4Gb, hence that
>sbuf.st_size is not a long but a quad (64-bit) integer.  Your "%7d" format is
>only using up the first 32 bits and so the rest of the arguments get out of
>step.

>Your printf should look more like:

> printf("%7qd %.12s ", sbuf.st_size, ctime(&sbuf.st_mtime)+4);
>           ^^

>Presumably linux still has the 32-bit file size limit and so your program works
>OK there.

I had a similar problem when I ported rdist 6.1.0 to FreeBSD.
For any varargs functions (like *printf) you have to decide whether
to stick to 4GB file sizes (in which case you cast the target (st_size)
to int or long), or use the perhaps not-portable %q option to
printf. I chose to cast the target sizes instead.

(For anyone interested in the rdist changes for FreeBSD,
they are available at ftp://ftp.dataplex.net/pub/FreeBSD/contrib/rdist
for the time being. I have submitted them to usc as well.)
-- 
Deborah Gronke Bennett 	(WD5HJH) 	kernel and device drivers engineer
deborah@microunity.com			(408)-734-8100
MicroUnity Systems Eng., 255 Caspian Drive, Sunnyvale, CA 94089-1015 USA
 "Pick yourself up, dust yourself off, start all over again" 							Ginger Rogers in "Swingtime"