LibCapy - cext

Functions and macros extending the C language.

Macros:

Conversion of a macro into a char* containing its value

Safe malloc, allocates 'size*sizeof(*ptr)' bytes of memory and raises CapyExc_MallocFailed if the allocation fails.

Safe realloc, raises CapyExc_MallocFailed if the reallocation fails and leaves 'ptr' unchanged if it fails

Shortcut equivalent to a for loop iterating from 0 to (nbIter-1) and storing the current iteration index in varName

Macro used to create padding fields

Input argument(s):

T: the type of the field to padd
I: index to differentiate several padding field in the same structure

Macros equivalent to printf and fprintf where a '\n' would have been added at the end of the formatting string

Macro to use OOP methods. Given a structure 'S' with a method defined as pointer to function as field 'm', an instance 's' of 'S' can execute this method with the command $(s, m)() (where 's' must be a pointer to 'S') The function pointed to by 'm' can access the instance at the origin of the call by defining the macro #define CapyThatS struct S* that = (struct S*)capyThat and calling this macro at the head of the function, before any call to another $(..., ...). A pointer to the instance is then available in the body of function through the variable 'that'. The macro CapyThat... must be defined for each structure using OOP methods. LibCapy provide this macro for each of the structure it defines.

Same as $(instance, method) but the value of 'that' in the execution of the method is replaced with 'actor' instead of 'instance'. Used to implement genericity.

Safe fscanf raising CapyExc_StreamReadError if it fails

Safe fprintf raising CapyExc_StreamWriteError if it fails

Safe fread raising CapyExc_StreamReadError if it fails

Safe fwrite raising CapyExc_StreamWriteError if it fails

Return the number of arguments of a variadic macro given the type 'type' of these arguments

Equality operator for float and double types.

Input argument(s):

a,b: the values to compare

Output and side effect(s):

Return true if the values are considered equal using the ULP method described here: https://randomascii.wordpress.com/2012/02/25/ comparing-floating-point-numbers-2012-edition/

Get the minimum value in a array of base type values

Input argument(s):

arr: the array
size: the size of the array

Output and side effect(s):

Return the minimum value

Get the maximum value in a array of base type values

Input argument(s):

arr: the array
size: the size of the array

Output and side effect(s):

Return the maximum value

Get the index of the minimum value in a array of base type values

Input argument(s):

arr: the array
size: the size of the array

Output and side effect(s):

Return the minimum value

Get the index of the maximum value in a array of base type values

Input argument(s):

arr: the array
size: the size of the array

Output and side effect(s):

Return the maximum value

for loop using the 'iterator' to iterates on each 'elem' of the iterator's associated container. A copy of the value in the container can be accessed with 'elem', and the adress of the value with 'elem'Ptr.

Inheritance operator. Use it in the 'Create' function of the inheriting class to initialise the 'Parent' properties and methods in 'Instance'. 'Args' are arguments given to the parent 'Create' function (inside parenthesis)

Get teh maximum possible value for an integer type

Get a pointer to the instance of the structure containing 'ptr' given its a structure of type 'containerType' and 'ptr' points to the 'fieldName' field in that structure.

Enumerations:

None.

Typedefs:

Typedef for struct sigaction to comply with CBo

Functions:

Safe fopen raising CapyExc_StreamOpenError if it fails

Safe sprintf allocating memory as necessary for the result string and raising CapyExc_MallocFailed if the memory allocation failed

Input argument(s):

str: pointer to the result string
fmt: format as in sprintf
...: arguments as in sprintf

Clone of asprintf

Input argument(s):

fmt: format as in sprintf
...: arguments as in sprintf

Output and side effect(s):

Return a newly allocated string

Exception(s):

May raise CapyExc_MallocFailed

Sleep for a given amount of time in milliseconds

Input argument(s):

delayMs: delay in milliseconds

Output and side effect(s):

Return -1 if the sleep has been interrupted by an interruption, else 0

Check if an address is inside the currently accessible address space

Input argument(s):

ptr: the address to check
nbByte: the number of bytes checked from that adress, if equal to 0 uses 1 byte instead

Output and side effect(s):

Return true if the 'nbByte' bytes from 'ptr' are in the accessible adress space, else false

Get the quantity of memory currently used by the process calling this function.

Output and side effect(s):

Return the quantity of memory in bytes. May return 0 if the quantity of used memory couldn't be measured.

Avoid child process to become zombies and wait until their parent's wait() call. This applies to *all* child processes.

2021-11-06
in LibCapy,
90 views
Copyright 2021-2024 Baillehache Pascal