Skip to content
Sudheer edited this page Apr 2, 2023 · 19 revisions

Miscellaneous utilities, not necessarilty related to the main theme of the efio library. These are intended for usage in lua to achieve respective functionalities not available in pure lua.

Can be refactored in the future as a separate library along with many such utility functions

Single precistion floatint point and double precision floating point related functions

float max_float()

DESCRIPTION: returns the maximum value of a float

double max_double()

DESCRIPTION: returns the maximum value of a double

long double max_long_double()

DESCRIPTION: returns the maximum value of a long double

int isfloat_nan(float f)

DESCRIPTION: returns 1 if the input float is not a number
ARGUMENTS:
    float f

int isfloat_inf(float f)

DESCRIPTION: returns 1 if the input float is infinity
ARGUMENTS:
    float f

int isdouble_nan(double d)

DESCRIPTION: returns 1 if the input double is not a number
ARGUMENTS:
    double d

int isdouble_inf(double d)

DESCRIPTION: returns 1 if the input double is infinity
ARGUMENTS:
    double d

Encoding and decoding functions

unsigned char *hex_encode(const unsigned char *data, size_t input_length, size_t *output_\length)

    DESCRIPTION:
        Encodes the given input binary data to HEX string format.
        Memory needed for the returned string is allocated within and the calling functions is
        expected to free the memory.
    PARAMETERS:
        const unsigned char *data : binary data
        size_t input_length       : size of the binary data
        size_t *output_length     : pointer to variable of type size_t where the length of the output
                                    buffer will be written
    RETURN:
        output_length
        unsigned char *           : output buffer

unsigned char *hex_decode(const unsigned char *data, size_t input_length, size_t *output_length)

    DESCRIPTION:
        Decodes the input hex string
        Memory needed for the returned binary data is allocated within and the calling functions is
        expected to free the memory.
    PARAMETERS:
        const unsigned char *data : string data
        size_t input_length       : size of the string data
        size_t *output_length     : pointer to variable of type size_t where the length of the output
                                    buffer will be written
    RETURN:
        output_length
        unsigned char *           : output buffer

unsigned char *base64_encode(const unsigned char *data, size_t input_length, size_t *output_length)

    DESCRIPTION:
        Encodes the given input binary data to base64 string format.
        Memory needed for the returned string is allocated within and the calling functions are
        expected to free the memory.
    PARAMETERS:
        const unsigned char *data : binary data
        size_t input_length       : size of the binary data
        size_t *output_length     : pointer to variable of type size_t where the length of the output
                                    buffer will be written
    RETURN:
        output_length
        unsigned char *           : output buffer

unsigned char *base64_decode(const unsigned char *data, size_t input_length, size_t *output_length)

    DESCRIPTION:
        Decodes the input base64 encoded string
        Memory needed for the returned binary data is allocated within and the calling functions are
        expected to free the memory.
    PARAMETERS:
        const unsigned char *data : string data
        size_t input_length       : size of the string data
        size_t *output_length     : pointer to variable of type size_t where the length of the output
                                    buffer will be written
    RETURN:
        output_length
        unsigned char *           : output buffer

#include <ev_compression.h>

int compress_inp_buf(void *in, size_t in_size, void *out_ptr, size_t out_len)

    DESCRIPTION:
        Compresses the input buffer of given size using zlib, and at Z_DEFAULT_COMPRESSION level
        Memory needed for the returned binary data is allocated within and the calling functions are
        expected to free the memory.
    PARAMETERS:
        void * data        : input buffer, data to be compressed
        size_t in_size     : size of the input data
        void ** out_ptr    : pointer to to be allocated pointer where the compressed data will be written
        size_t * out_len   : pointer to variable of type size_t where the length of the output
                                buffer will be written
    RETURN:
        int ret            : Z_OK (0) in case of successful compression, error value otherwise

int uncompress_inp_buf(void *in, size_t in_size, void *out_ptr, size_t out_len)

    DESCRIPTION:
        Decompresses the input buffer of given size using zlib. 
        Memory needed for the returned binary data is allocated within and the calling functions are
        expected to free the memory.
    PARAMETERS:
        void * data        : input compressed data
        size_t in_size     : size of the input data
        void ** out_ptr    : pointer to to be allocated pointer where the decompressed data will be written
        size_t * out_len   : pointer to variable of type size_t where the length of the output
                                buffer will be written
    RETURN:
        int ret            : Z_OK (0) in case of successful compression, error value otherwise

const char * zerr(int ret)

    DESCRIPTION:
        Returns the string discription of the given error
    PARAMETERS:
        int ret            : integer value returned by either of compress or uncompress functions above

    RETURN:
        const char *       : Descripton of the error message