*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->NetBSD man pages -> humanize_number (9)              
Title
Content
Arch
Section
 

HUMANIZE_NUMBER(9)

Contents


NAME    [Toc]    [Back]

     humanize_number, format_bytes - format a number into a human readable
     form

SYNOPSIS    [Toc]    [Back]

     int
     humanize_number(char *buf, size_t len, u_int64_t number,
             const char *suffix, int divisor);

     int
     format_bytes(char *buf, size_t len, u_int64_t number);

DESCRIPTION    [Toc]    [Back]

   humanize_number
     The humanize_number() function formats the unsigned 64 bit quantity given
     in number into buffer.  A space and then suffix is appended to the end.
     buffer must be at least len bytes bytes long.

     If the formatted number (including suffix) would be too long to fit into
     buffer, then divide number by divisor until it will.  In this case, prefix
 suffix with the appropriate SI designator.  Suitable values of
     divisor are 1024 or 1000 to remain consistent with the common meanings of
     the SI designator prefixes.

     The prefixes are:

           Prefix    Description    Multiplier
           K         kilo           1024
           M         mega           1048576
           G         giga           1073741824
           T         tera           1099511627776
           P         peta           1125899906842624
           E         exa            1152921504606846976

     len must be at least 4 plus the length of suffix, in order to ensure a
     useful result is generated into buffer.

   format_bytes
     The format_bytes() function is a front-end to humanize_number() that
     calls the latter with a suffix of ``B''.  Also, if the suffix in the
     returned buffer would not have a prefix, remove the suffix.  This means
     that a result of ``100000'' occurs, instead of ``100000 B''.

RETURN VALUES    [Toc]    [Back]

     humanize_number() and format_bytes() return the number of characters
     stored in buffer (excluding the terminating NUL) upon success, or -1 upon
     failure.

HISTORY    [Toc]    [Back]

     humanize_number() and format_bytes() first appeared in NetBSD 1.5.

BSD                              May 21, 1999                              BSD
[ Back ]
 Similar pages
Name OS Title
accessdb Linux dumps the content of a man-db database in a human readable format.
scan_scaled OpenBSD handle numbers with a human-readable scale
ERR_error_string NetBSD obtain human-readable error message
fmt_scaled OpenBSD handle numbers with a human-readable scale
ERR_reason_error_string OpenBSD obtain human-readable error message
ERR_lib_error_string OpenBSD obtain human-readable error message
ERR_func_error_string OpenBSD obtain human-readable error message
ERR_error_string_n OpenBSD obtain human-readable error message
ERR_reason_error_string Tru64 Obtain human-readable error message
ERR_lib_error_string Tru64 Obtain human-readable error message
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service