AminetAminet
Search:
84736 packages online
About
Recent
Browse
Search
Upload
Setup
Services

dev/lib/bytes.lha

Mirror:Random
Showing: ppc-morphos icongeneric icon
No screenshot available
Short:Byte <-> string conversion library
Author:TJ Holowaychuk, Joseph Werle and others
Type:dev/lib
Version:0.0.4
Architecture:m68k-amigaos,generic
Distribution:Aminet
Date:2020-05-10
Download:/dev/lib/bytes.lha - View contents
Readme:/dev/lib/bytes.readme
Downloads:4507

About

    Convert byte length strings such as "5kb" to a long long and vice versa.

Installation

    Copy byte.h and byte.c to your source code tree.

Usage

    void test_string_to_bytes(void) {
        assert(100 == string_to_bytes("100"));
        assert(100 == string_to_bytes("100b"));
        assert(100 == string_to_bytes("100 bytes"));
        assert(1024 == string_to_bytes("1kb"));
        assert(1024 * 1024 == string_to_bytes("1mb"));
        assert(1024 * 1024 * 1024 == string_to_bytes("1gb"));
        assert(2 * 1024 == string_to_bytes("2kb"));
        assert(5 * 1024 * 1024 == string_to_bytes("5mb"));
    }

    void test_bytes_to_string(void) {
        equal("100b", bytes_to_string(100));
        equal("1kb", bytes_to_string(1024));
        equal("1mb", bytes_to_string(1024 * 1024));
        equal("5mb", bytes_to_string(1024 * 1024 * 5));
        equal("1gb", bytes_to_string(1024 * 1024 * 1024));
        equal("5gb", bytes_to_string((long long) 1024 * 1024 * 1024 * 5));
    }

API

    long long
    string_to_bytes(const char *str);

    char *
    bytes_to_string(long long bytes);

License

    MIT


Contents of dev/lib/bytes.lha
PERMISSION  UID  GID    PACKED    SIZE  RATIO METHOD CRC     STAMP     NAME
---------- ----------- ------- ------- ------ ---------- ------------ ----------
[unknown]                  633    1579  40.1% -lh5- 9507 May  7 12:30 bytes/bytes.c
[unknown]                  159     217  73.3% -lh5- 5497 May  7 12:30 bytes/bytes.h
[unknown]                  496    1417  35.0% -lh5- 744b May  7 12:30 bytes/bytes.readme
[unknown]                  200     267  74.9% -lh5- 444c May  7 12:30 bytes/Makefile
[unknown]                 2360    5074  46.5% -lh5- 1df9 May  7 12:30 bytes/strtoll.c
[unknown]                19994   36160  55.3% -lh5- 4dc0 May  7 12:30 bytes/test
[unknown]                  556    1550  35.9% -lh5- 7926 May  7 12:30 bytes/test.c
[unknown]                 2653    8515  31.2% -lh5- 3d40 May  7 12:30 bytes/vstring.h
---------- ----------- ------- ------- ------ ---------- ------------ ----------
 Total         8 files   27051   54779  49.4%            May 10 02:22
Page generated in 0.02 seconds
Aminet © 1992-2024 Urban Müller and the Aminet team. Aminet contact address: <aminetaminet net>