apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: apr_strfsize cannot handle sizes bigger than a few MiBs without largefiles support
Date Wed, 30 Jan 2002 08:31:03 GMT
Sorry Bill, but how do we make the food for thoughts into real CODE (or 
at least well defined API as a first step). You have mentioned many 
ideas but let's work out some concrete plan.

If library developers (clib, foolib, whatever) didn't see a need for 
order in strings, I don't see any reason why APR should take this as an 
excuse.

Here is my proposal. partly stolen from strftime(3) manpage.

NAME
        strfsize - format size

SYNOPSIS
        #include <apr_util.h>

        size_t strftime(char *s, apr_int64_t max,
                        const char *format, apr_int64_t size);

DESCRIPTION
        The strfsize() function formats the size according to the format 
specification and places the result in the character array s of size max.

        Ordinary characters placed in the format string are copied to s 
without conversion.  Conversion specifiers are introduced by a `%' 
character, and are replaced in s as follows:

        %b     Binary representation (i.e. convert a decimal number into 
2^x number)

        %f     File size (filesystem limits apply, sizes bigger than 
apr_off_t, marked as "Huge")

        %c     Characters (how many, utf aware?)

        %...   hex, oct, etc

so now you have a single function for formatting strings and you specify 
the format for whatever you want. You can add wrappers on top of it, to 
hide the format argument to make things simpler. If in the future 
someone wants to add new formats, we add these without arguing about the 
name for the new function.

I already have a good use for this formatting argument. Here is an example:

        %i  use kib, mib, gib ending strings
        %k  use kb, mb, gb ending strings
        %I  use KiB, MiB, GiB ending strings
        %K  use KB, MB, GIB ending strings
        %0  no 'i?B' ending at all.

So you can say "%b %I" and you get "101MiB"
if you say     "%b %K"     you get "101MB"
if you say     "%b %0"     you get "101M"
And who knows may be one day we will see strfsize(3) manpage, sitting 
next to strftime(3).

_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Mime
View raw message