stdlib.h

    UTILS

    Description:

    Declares common functions used for performing I/O operations.

    You can use the functions provided in this file to complete string conversion, random number generation, array sorting, and tree-related operations during development.

    Since:

    1.0

    Version:

    1.0

    Function Name

    Description

    (const char nptr)

    int 

    Converts an input string to an integer.

    atol (const char nptr)

    long 

    Converts an input string to a long integer.

    (const char nptr)

    long long 

    Converts a string to an 8-byte long integer.

    atof (const char nptr)

    double 

    Converts an input string to a double-precision floating-point number.

    (const char nptr, char **endptr)

    float 

    Converts an input string to a floating-point number.

    strtod (const char nptr, char endptr)

    double 

    Converts a string to double.

    (const char *nptr, char endptr)

    long double 

    Converts a string to long double.

    strtol (const char nptr, char **endptr, int base)

    long 

    Converts a string to a long integer according to the given base.

    (const char nptr, char endptr, int base)

    unsigned long 

    Converts a string to an unsigned long integer according to the given base.

    strtoll (const char *nptr, char endptr, int base)

    long long 

    Converts a string to a long long integer according to the given base.

    (const char nptr, char **endptr, int base)

    unsigned long long 

    Converts a string to an unsigned long long integer according to the given base.

    rand (void)

    int 

    Generates a pseudo-random number.

    (unsigned int seed)

    void 

    Initializes a random number generator.

    malloc (size_t size)

    void  

    Dynamically allocates a memory block of size.

    (size_t nmemb, size_t size)

    void  

    Dynamically allocates nmemb memory blocks of size.

    realloc (void ptr, size_t size)

    void  

    Changes the size of the memory block pointed to by ptr to size bytes.

    (void ptr)

    void 

    Releases the memory space pointed to by ptr.

    abort (void)

    _Noreturn void 

    Terminates an abnormal process and sends the SIGABRT signal to the caller.

    (void(func)(void))

    int 

    Registers a termination function.

    void 

    Terminates the calling process, clears the used memory space and various data structures in the kernel, and sends the process end status to the parent process. All functions registered with atexit and on_exit are called in the reverse order.

    getenv (const char name)

    char  

    Obtains the value of an environment variable.

    (int status)

    void 

    Terminates the calling process, clears the used memory space and various data structures in the kernel, and sends the process end status to the parent process.

    assert (scalar expression)

    void 

    Aborts the program if assertion is false.

    (const char name)

    char  

    Obtains the value of an environment variable.

    bsearch (const void key, const void base, size_t nel, size_t width, int(compar)(const void , const void ))

    void  

    Searches for key using the binary search algorithm from the array element base[0] to base[num-1].

    (const void base, size_t nel, size_t width, int(compar)(const void , const void ))

    void 

    Sorts array elements base[0] to base[num-1] based on the comparison rules of compar.

    abs (int i)

    int 

    Obtains the absolute value of an integer value.

    (long i)

    long 

    Calculates the absolute value of a long integer.

    llabs (long long i)

    long long 

    Calculates the absolute value of a long long integer.

    (int numerator, int denominator)

    div_t 

    Calculates the quotient and remainder of an integer after division.

    (long numerator, long denominator)

    ldiv_t 

    Calculates the quotient and remainder of a long integer after division.

    (long long numerator, long long denominator)

    lldiv_t 

    Calculates the quotient and remainder of a long long integer after division.

    (const char s, size_t n)

    int 

    Obtains the number of bytes in the next multi-byte string.

    mbtowc (wchar_t pwc, const char s, size_t n)

    int 

    Converts a string constant to a wide character.

    (char s, wchar_t wc)

    int 

    Converts a wide character to its multi-byte sequence and stores it in a character array.

    mbstowcs (wchar_t dest, const char src, size_t n)

    size_t 

    Converts a multi-byte string to a wide-character string.

    (char dest, const wchar_t src, size_t n)

    size_t 

    Converts a wide-character string to a multi-byte string.

    posix_memalign (void **memptr, size_t alignment, size_t size)

    int 

    Allocates memory with the specified size based on the given alignment.

    (const char name, const char value, int overwrite)

    int 

    Add or change an environment variable.

    unsetenv (const char name)

    int 

    Deletes an environment variable.

    (char template)

    int 

    Creates and opens a unique temporary file.

    mkostemp (char template, int flags)

    int 

    Creates and opens a unique temporary file.

    (char template)

    char  

    Creates a unique temporary directory based on template.

    getsubopt (char optionp, char const tokens, char valuep)

    int 

    Processes the parameters of an option in the command line.

    (unsigned seedp)

    int 

    Generates a pseudo-random number.

    char  

    Obtains a normalized absolute path.

    random (void)

    long int 

    Generates a pseudo-random number.

    (unsigned int seed)

    void 

    Initializes a random number generator.

    initstate (unsigned int seed, char state, size_t n)

    char  

    Initializes a random number generator.

    (char state)

    char  

    Sets the current state list for subsequent random use.

    putenv (char s)

    int 

    Configures an environment variable.

    (int fd)

    int 

    Unlocks the secondary pseudo terminal corresponding to a primary pseudo terminal.

    ptsname (int fd)

    char  

    Obtains the name of a pseudo terminal.

    (long value)

    char  

    Converts a long integer to a 64-bit ASCII string.

    a64l (const char str64)

    long 

    Converts between a 32-bit long integer and a little-endian 64-bit ASCII string.

    (void)

    double 

    Obtains a random number.

    erand48 (unsigned short xsubi[3])

    double 

    Obtains a random number.

    (void)

    long int 

    Generates pseudo-random numbers evenly distributed between [0, 2^31).

    nrand48 (unsigned short xsubi[3])

    long int 

    Generates pseudo-random numbers evenly distributed between [0, 2^31).

    (void)

    long 

    Generates pseudo-random numbers evenly distributed between [-2^31, 2^31).

    jrand48 (unsigned short xsubi[3])

    long 

    Generates pseudo-random numbers evenly distributed between [-2^31, 2^31).

    (long int seedval)

    void 

    Sets the start seed value for the pseudo-random number generator.

    seed48 (unsigned short[3])

    unsigned short  

    Generates an evenly distributed pseudo-random seed.

    (unsigned short param[7])

    void 

    Sets the seed and related algorithm parameters for the pseudo-random number generator.

    mktemp (char template)

    char  

    Creates a unique temporary file name.

    (char template, int suffixlen)

    int 

    Creates and opens a unique temporary file.

    mkostemps (char template, int suffixlen, int flags)

    int 

    Creates and opens a unique temporary file.

    (size_t size)

    void  

    Allocates memory with the specified size and aligns the allocated memory by page size.

    ecvt (double number, int ndigits, int decpt, int sign)

    char  

    Converts a double-precision floating-point number into a string.

    (double number, int ndigits, int decpt, int sign)

    char  

    Converts a floating-point number to a string.

    gcvt (double x, int n, char b)

    char * 

    Converts a floating-point number to a string.