C standard library

August 13, 2024 ยท View on GitHub

Source: include/stdlib/c/cstdlib.ml

Provides bindings for ported functions of the c standard library.

Functions

FunctionDescription
absReturns the absolute value of an integer
atoiConverts a c string (int8*) to an integer
exitCleans resources and terminates the calling process immediately
fprintfWrites a formatted c string (int8*) to a specified file stream
freeDeallocates the memory previously allocated by malloc, calloc, or realloc
fscanfReads formatted input from a file stream
getcharReads the next character from standard input
isdigitChecks if a character is a digit ('0' to '9')
isspaceChecks if a character is a whitespace character
mallocRetuns a pointer to size bytes of uninitialized storage
memcpyCopies count bytes from the object pointed to by src to the object pointed to by dest
memsetFills a block of memory with the specified value
printfWrites a formatted c string to standard output
putsWrites a c string to standard output, followed by newline
reallocReallocates previously allocated memory to a new size
scanfReads formatted input from standard input
strcatAppends one c string to the end of another
strchrSearches for the first occurrence of a character in a c string
strcmpCompares two c strings lexicographically
strcpyCopies one c string to another
strdupDuplicates a c string by allocating memory for the new one
strlenReturns the length of a c string
strncatAppends a specified number of characters from one c string to another
strncmpCompares a specified number of characters from two c strings
strncpyCopies a specified number of characters from one c string to another
strrchrSearches for the last occurrence of a character in a c string
strstrFinds the first occurrence of a substring in a c string
strtollConverts a c string to int64 (long long int)

Warnings

Warning

The c standard library provided by ML is currently incomplete. To port a c standard library function ML, simply declare an external function with the same name as the c one along with its appropriate parameters and their ML-equivalent types. If such task interests you, please fork the project and add the required bindings along with the updated documentation and submit a pull request.