*BSD News Article 48386


Return to BSD News archive

Path: sserve!euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!news.sprintlink.net!dispatch.news.demon.net!demon!pencotts.demon.co.uk
From: Andrew Gordon <andrew.gordon@net-tel.co.uk>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Simple BSD code acting funny in FreeBSD (correctly in Linux)
Date: Wed, 09 Aug 1995 00:25:21 GMT
Lines: 26
Message-ID: <807927921.19978@pencotts.demon.co.uk>
References: <DD06CB.It1@midway.uchicago.edu>
NNTP-Posting-Host: pencotts.demon.co.uk
X-NNTP-Posting-Host: pencotts.demon.co.uk
X-Mailer: Mozilla 1.1N (X11; I; BSD/386 uname failed)
MIME-Version: 1.0
To: frank@gsb13580.uchicago.edu
X-URL: news:DD06CB.It1@midway.uchicago.edu
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii

frank@gsb13580.uchicago.edu (Frank S. Fejes) wrote:
>     Hello, I have been attempting to compile and run a simple ls-type
>program under FreeBSD.  It is very simple Berkeley Unix C coding, but
>I have run into a small problem running it under FreeBSD (it works
>perfectly in Linux, though).  The problem lies in the ctime function
                                                       ^^^^^
I don't think so.

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

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.