Re: [PATCH] lib: [strutils] add some format options to size_to_human_string()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 23, 2011 at 03:30:35PM +0200, Francesco Cosoleto wrote:
> This adds a second parameter to size_to_human_string() to return a string with
> a different format based on the following flags: ONE_LETTER_SUFFIX (1K),
> THREE_LETTERS_SUFFIX (1KiB), SPACE_BEFORE_UNIT (1 KiB or 1 K).

 Applied with some changes, thanks.

> +/* Options for size_to_human_string() */
> +enum
> +{
> +        ONE_LETTER_SUFFIX = 0,
> +        THREE_LETTERS_SUFFIX = 1,
> +        SPACE_BEFORE_UNIT = 2


 renamed to SIZE_SUFFIX_* 

> +char *size_to_human_string(int options, uint64_t bytes)
>  {
>  	char buf[32];
>  	int dec, exp;
>  	uint64_t frac;
>  	const char *letters = "BKMGTPE";
> -	char c;
> +	char suffix[4], *psuf = suffix;

 " KiB\0" is five bytes ;-)

> +	if (options & THREE_LETTERS_SUFFIX) {
> +		*psuf++ = 'i';
> +		*psuf++ = 'B';
> +	}

 I think "BiB" is unexpected output, the "iB" suffix should be used
 only if the extension is not 'B'.

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux