Useful generic functions and macros.
More...
Go to the source code of this file.
|
#define | EXIT_SUCCESS 0 |
| Successful execution of a program.
|
|
#define | EXIT_FAILURE 1 |
| Unsuccessful execution of a program.
|
|
#define | RAND_MAX ((1U << 31U) - 1U) |
| The maximum value returned by the rand function.
|
|
|
size_t | malloc_usable_size (void *ptr) |
| Returns the number of usable bytes in the block pointed to by ptr. More...
|
|
void * | malloc (unsigned int size) |
| Provides dynamically allocated memory. More...
|
|
void * | calloc (size_t num, size_t size) |
| Allocates a block of memory for an array of num elements. More...
|
|
void * | realloc (void *ptr, size_t size) |
| Reallocates the given area of memory. More...
|
|
void | free (void *ptr) |
| Frees dynamically allocated memory. More...
|
|
void | abort (void) |
| Cause an abnormal program termination with core-dump.
|
|
int | setenv (const char *name, const char *value, int overwrite) |
| Tries to adds the variable to the environment. More...
|
|
int | unsetenv (const char *name) |
| Tries to remove the variable from the environment. More...
|
|
char * | getenv (const char *name) |
| Returns the value of the given variable. More...
|
|
void | srand (unsigned x) |
| Allows to set the seed of the random value generator. More...
|
|
unsigned | rand (void) |
| Generates a random unsigned integer between 0 and RAND_MAX. More...
|
|
float | randf (void) |
| Generates a random floating point number between 0 and 1. More...
|
|
int | randint (int lb, int ub) |
| Generates a random integer between lb and ub. More...
|
|
unsigned | randuint (unsigned lb, unsigned ub) |
| Generates a random unsigned between lb and ub. More...
|
|
float | randfloat (float lb, float ub) |
| Generates a random float between lb and ub. More...
|
|
Useful generic functions and macros.
- Copyright
- (c) 2014-2024 This file is distributed under the MIT License. See LICENSE.md for details.
◆ calloc()
Allocates a block of memory for an array of num elements.
- Parameters
-
num | The number of elements. |
size | The size of an element. |
- Returns
- A pointer to the allocated memory.
◆ free()
Frees dynamically allocated memory.
- Parameters
-
ptr | The pointer to the allocated memory. |
◆ getenv()
char* getenv |
( |
const char * |
name | ) |
|
Returns the value of the given variable.
- Parameters
-
name | Name of the variable. |
- Returns
- A pointer to the value, or NULL if there is no match.
◆ malloc()
void* malloc |
( |
unsigned int |
size | ) |
|
Provides dynamically allocated memory.
- Parameters
-
size | The amount of memory to allocate. |
- Returns
- A pointer to the allocated memory.
◆ malloc_usable_size()
size_t malloc_usable_size |
( |
void * |
ptr | ) |
|
Returns the number of usable bytes in the block pointed to by ptr.
- Parameters
-
ptr | The pointer for which we want to retrieve the usable size. |
- Returns
- The number of usable bytes in the block of allocated memory pointed to by ptr. If ptr is not a valid pointer, 0 is returned.
◆ rand()
Generates a random unsigned integer between 0 and RAND_MAX.
- Returns
- the random value.
◆ randf()
Generates a random floating point number between 0 and 1.
- Returns
- the random value.
◆ randfloat()
float randfloat |
( |
float |
lb, |
|
|
float |
ub |
|
) |
| |
Generates a random float between lb and ub.
- Parameters
-
lb | the lower-bound value. |
ub | the upper-bound value. |
- Returns
- the random value.
◆ randint()
int randint |
( |
int |
lb, |
|
|
int |
ub |
|
) |
| |
Generates a random integer between lb and ub.
- Parameters
-
lb | the lower-bound value. |
ub | the upper-bound value. |
- Returns
- the random value.
◆ randuint()
unsigned randuint |
( |
unsigned |
lb, |
|
|
unsigned |
ub |
|
) |
| |
Generates a random unsigned between lb and ub.
- Parameters
-
lb | the lower-bound value. |
ub | the upper-bound value. |
- Returns
- the random value.
◆ realloc()
void* realloc |
( |
void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
Reallocates the given area of memory.
- Parameters
-
ptr | The pointer to the memory to reallocate. |
size | The new size for the memory. |
- Returns
- A pointer to the new portion of memory.
It must be previously allocated by malloc(), calloc() or realloc() and not yet freed with a call to free or realloc. Otherwise, the results are undefined.
◆ setenv()
int setenv |
( |
const char * |
name, |
|
|
const char * |
value, |
|
|
int |
overwrite |
|
) |
| |
Tries to adds the variable to the environment.
- Parameters
-
name | Name of the variable. |
value | Value of the variable. |
overwrite | Override existing variable value or not. |
- Returns
- Zero on success, or -1 on error with errno indicating the cause.
◆ srand()
Allows to set the seed of the random value generator.
- Parameters
-
◆ unsetenv()
int unsetenv |
( |
const char * |
name | ) |
|
Tries to remove the variable from the environment.
- Parameters
-
name | Name of the variable. |
- Returns
- Zero on success, or -1 on error with errno indicating the cause.