ftwin 0.8.10
human_size.c File Reference

Implementation of human-readable size parsing and formatting. More...

#include "human_size.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <apr_strings.h>
Include dependency graph for human_size.c:

Go to the source code of this file.

Functions

const char * format_human_size (apr_off_t size, apr_pool_t *pool)
 Formats a size in bytes into a human-readable string.
 
apr_off_t parse_human_size (const char *size_str)
 Parses a human-readable size string (e.g., "10M", "2.5G") into bytes.
 

Detailed Description

Implementation of human-readable size parsing and formatting.

Definition in file human_size.c.

Function Documentation

◆ format_human_size()

const char * format_human_size ( apr_off_t  size,
apr_pool_t *  pool 
)

Formats a size in bytes into a human-readable string.

The function selects the most appropriate unit (B, KB, MB, GB, TB) to produce a concise representation.

Parameters
[in]sizeThe size in bytes.
[in]poolThe APR pool to allocate the resulting string from.
Returns
A pointer to the formatted, human-readable size string.

Definition at line 13 of file human_size.c.

◆ parse_human_size()

apr_off_t parse_human_size ( const char *  size_str)

Parses a human-readable size string (e.g., "10M", "2.5G") into bytes.

Supports suffixes: B (bytes), K (kilobytes), M (megabytes), G (gigabytes), T (terabytes). If no suffix is provided, the value is treated as bytes.

Parameters
[in]size_strThe string to parse.
Returns
The size in bytes as an apr_off_t, or -1 on parsing error.

Definition at line 32 of file human_size.c.