wiki:library_stdlib

Version 9 (modified by alain, 8 years ago) (diff)

--

The stdlib library

The stdlib.c and stdlib.h files define a set of useful functions that do not require a system call.

void random_wait( unsigned int randomize , unsigned int value )

This function implements a 5 cycles waiting loop. If the <randomize> argument is set, the number of iterations is a pseudo-random number whose number of bits is defined by the <value> argument. If the <randomize> argument is zero, the number of iterations is defined by the <value> argument.

int atoi( char * string )

This function translate a character string to a signed integer. All characters (but the first) must be digits. For a negative value, the first character must be the '-' (minus) character.

double atof( char * string )

This function translate a character string to a double. Conversion stop at first non-numeric character (except a first '+' or '-' and one '.').

void* memcpy( void* dst, const void* src, unsigned int size )

This function copies size bytes from the src source buffer to the dst destination buffer.

void* memset( void* dst , int s , unsigned int size )

This function initializes size bytes in the dst destination buffer, with the value defined by (char)s.

unsigned int strlen( char* string )

This function returns the number of characters in a string. The terminating NUL character is not taken into account.

unsigned int strcmp( char* s1 , char* s2 )

This function compare the two s1 & s2 strings.It returns 0 if strings are identical (including the terminating NUL character), and returns 1 if they are not.

unsigned int strcpy( char* dest , char* source )

This function copies the source string to the dest string.It returns a pointer on the dest string.

unsigned int snprintf( char* string , unsigned int maxlen , char* format , va_list* args )

This function can be directly used by an application to build a formated string. It is also used the giet_tty_printf() and giet_fat_printf() system calls. It analyse the <format> and <args> arguments and returns a byte stream in the <stream> buffer. The TO_STREAM macro checks buffer overflow. It returns number of written bytes in case of success. It returns 0xFFFFFFFF in case of error (illegal format, or buffer overflow).