expand_number(3)

expand_number3

Format a number from human readable form

Usage

#include <libutil.h>

int

expand_number(const char *buf, uint64_t *num);

Library

System Utilities Library (libutil, -lutil)

Overview

The expand_number() function parses the buf string and stores a unsigned 64-bit quantity at *num.

The expand_number() function is case-insensitive and follows the SI power of two convention.

The suffixes are:

SuffixDescriptionMultiplier
Kkilo1024
Mmega1048576
Ggiga1073741824
Ttera1099511627776
Ppeta1125899906842624
Eexa1152921504606846976

Return values

The expand_number() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

Errors

The expand_number() function will fail if:

[EINVAL]

The given string contains no digits.

[EINVAL]

An unrecognized suffix was given.

[ERANGE]

Result doesn't fit into 64 bits.

Releases

Unchanged in 38 releases since macOS 11.0.1.

  1. 11.0.1–26.5

History

The expand_number() function first appeared in FreeBSD 6.3.

From libutil 73 in macOS 26.5. Parsed by carta from the page's mdoc source.