*BSD News Article 84370


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!nntp.coast.net!news.sgi.com!news.corp.sgi.com!enews.sgi.com!news.mathworks.com!fu-berlin.de!news.belwue.de!news.uni-ulm.de!borchert
From: borchert@turing.mathematik.uni-ulm.de (Andreas Borchert)
Newsgroups: comp.unix.solaris,comp.unix.bsd.misc,comp.unix.internals
Subject: Re: Solaris 2.6
Date: 6 Dec 1996 10:45:02 GMT
Organization: University of Ulm, SAI, Germany
Lines: 42
Distribution: inet
Message-ID: <588tfe$pf2@arktur.rz.uni-ulm.de>
References: <32986299.AC7@mail.esrin.esa.it> <580sgh$kpi@panix2.panix.com> <casper.32a40b7b@mail.fwi.uva.nl> <587jrv$9rf@news.parc.xerox.com> <587meg$h67@web.nmti.com> <5880ig$1a5$1@shade.twinsun.com> <slrn5af88v.199.dave@pc-damir.srce.hr>
NNTP-Posting-Host: turing.mathematik.uni-ulm.de
X-Newsreader: slrn (0.9.0.0 (BETA) UNIX)
Xref: euryale.cc.adfa.oz.au comp.unix.solaris:91603 comp.unix.bsd.misc:1697 comp.unix.internals:11477

On 6 Dec 1996 04:28:33 GMT, Drazen Kacar <dave@pc-damir.srce.hr> wrote:
> In article <5880ig$1a5$1@shade.twinsun.com>, Paul Eggert wrote:
> >I don't want to add something like `#define _LARGEFILE64_SOURCE'
> >to each module that wants to work correctly with large Solaris files.
> >Nor do I want to change lseek/off_t to llseek/offset_t.
> >That sort of thing would be a porting nightmare.
> >Surely Sun isn't planning anything as braindamaged as that.
> 
> But of course they are. Thou shalt use off_t and ifdef it for Solaris 2.6
> Suppose you have:
> 
>    fstat(fd, &inode)
>    printf("%d\n", inode.st_size);
> 
> st_size is off_t (64 bits), but %d wants int (32 bits, the same as long).
> Thou shalt use "%dll" and guard it with ifdef from normal systems.
> And if not... Imagine all those HTTP servers returning "Content-Length: 0".

Now, please tell me, is there any difference in this problem to BSD
4.4?  The problem of this code snippet is *not* the type of transition
but rather the non-portable code. As yesterday, today, and tomorrow,
you can, in general, assume nothing about the actual size of off_t.
Printing it via %d is consequently non-portable.

Regrettably, there isn't a clean and portable solution to this problem
in C (as in many other cases). As discussed earlier, it would be fine
to have one integer type which is large enough to hold all of these
types (including pointers) -- long does not do the job because of the
existence of sometimes larger types named long long. Then you may cast
(or assign) it accordingly. You need, of course, an associated %-tag
for it.  But obviously the C-world likes huge number of #ifdefs in its
sources.  A cleaner solution is here offered by C++ (and many other
languages as well).

Andreas.

-- 
Andreas Borchert, Universitaet Ulm, SAI, Helmholtzstr. 18, 89069 Ulm,  Germany
E-Mail: borchert@mathematik.uni-ulm.de
WWW:	http://www.mathematik.uni-ulm.de/sai/borchert/
PGP key available via ``finger borchert@laborix.mathematik.uni-ulm.de''