Andrew Tridgell <[EMAIL PROTECTED]> wrote:
> > Speaking of this, does anyone know a portable way to get printf to
> > handle off_t values when they may be larger that a long?  Is there
> > none?
> 
> The best way I know of is what I used in other places in rsync, which
> is this:
> 
>   off_t foo = ....;
>   printf("seek to %.0f\n", (double)foo);
> 
> I know using a double is ugly, but it seems to be the only portable
> solution.
> 
> 

Well, there IS this silliness (this won't compile, its just
pseudo-code, as its been a while since I've had to do this):

union hacko_union
{
        off_t foo;
        long foolongs[2];
};

void printbigstuff(off_t biggie)
{
        hacko_union theUnion;
        theUnion.foo = biggie;

        if (theUnion.foolongs[0])
        {
                printf("%d%012d",theUnion.foolongs[0],theUnion.foolongs[1]);
        }
        else
        {
                printf("%d",theUnion.foolongs[1]);
        }
}

the most non-portable thing here, I think, is figuring out how many elements
to put into your foolongs.... (then of course you've got to do more 'cases'
for leading zero stuff).

Oh - wait!  I forgot - when I did this I limited the range of foolongs[1] to
a power of 10.  Shoot!  Never mind!

Ok, so the only other option would be to write an 'arbitrary length' printf
routine that you pass longer-than-long things to and it prints them... (Gag,
implementing printf manually again!)  If it seems like a good idea (for pretty
small values of good, I think!) I'd be happy to come up with something (that 
actually compiles ;-) if there's no huge hurry for it....

(The above stuff is such a hack I kinda hate to admit I came up with it! ;-)

rc


Rusty Carruth          Email:     [EMAIL PROTECTED] or [EMAIL PROTECTED]
Voice: (480) 345-3621  SnailMail: Schlumberger ATE
FAX:   (480) 345-8793             7855 S. River Parkway, Suite 116
Ham: N7IKQ @ 146.82+,pl 162.2     Tempe, AZ 85284-1825
ICBM: 33 20' 44"N   111 53' 47"W

Reply via email to