Helper for memory management.
More...
#include <kdbmacros.h>
#include <kdbtypes.h>
#include <stdarg.h>
#include <stddef.h>
|
void * | elektraMalloc (size_t size) |
| Allocate memory for Elektra. More...
|
|
void * | elektraCalloc (size_t size) |
| Allocate memory for Elektra. More...
|
|
void | elektraFree (void *ptr) |
| Free memory of Elektra or its backends. More...
|
|
int | elektraRealloc (void **buffer, size_t size) |
| Reallocate Storage in a save way. More...
|
|
char * | elektraStrDup (const char *s) |
| Copy string into new allocated memory. More...
|
|
char * | elektraStrNDup (const char *s, size_t l) |
| Copy buffer into new allocated memory. More...
|
|
char char * | elektraVFormat (const char *format, va_list arg_list) |
| Does string formatting in fresh allocated memory. More...
|
|
int | elektraStrCmp (const char *s1, const char *s2) |
| Compare Strings. More...
|
|
int | elektraStrNCmp (const char *s1, const char *s2, size_t n) |
| Compare Strings up to a maximum length. More...
|
|
int | elektraStrCaseCmp (const char *s1, const char *s2) |
| Compare Strings ignoring case. More...
|
|
int | elektraStrNCaseCmp (const char *s1, const char *s2, size_t n) |
| Compare Strings ignoring case up to a maximum length. More...
|
|
int | elektraMemCaseCmp (const char *s1, const char *s2, size_t size) |
| Compare two memory regions but make cmp chars uppercase before comparison. More...
|
|
size_t | elektraStrLen (const char *s) |
| Calculates the length in bytes of a string. More...
|
|
Helper for memory management.
Should be always preferred. Can be used for profiling and tracing.
- Copyright
- BSD License (see LICENSE.md or https://www.libelektra.org)
◆ elektraCalloc()
void* elektraCalloc |
( |
size_t |
size | ) |
|
Allocate memory for Elektra.
Memory will be set to 0.
- Parameters
-
- See also
- elektraMalloc
◆ elektraFree()
void elektraFree |
( |
void * |
ptr | ) |
|
Free memory of Elektra or its backends.
- Parameters
-
If ptr is NULL, no operation is performed.
- See also
- elektraMalloc
◆ elektraMalloc()
void* elektraMalloc |
( |
size_t |
size | ) |
|
Allocate memory for Elektra.
#if DEBUG
fprintf (stderr, "Allocation error");
#endif
}
- Parameters
-
This function is compatible to ANSI-C malloc
- See also
- elektraFree
-
elektraCalloc
◆ elektraMemCaseCmp()
int elektraMemCaseCmp |
( |
const char * |
s1, |
|
|
const char * |
s2, |
|
|
size_t |
size |
|
) |
| |
Compare two memory regions but make cmp chars uppercase before comparison.
- Parameters
-
s1 | The first string to be compared |
s2 | The second string to be compared |
size | to be compared |
- Returns
- a negative number if s1 is less than s2
- Return values
-
- Returns
- a positive number if s1 is greater than s2
◆ elektraRealloc()
int elektraRealloc |
( |
void ** |
buffer, |
|
|
size_t |
size |
|
) |
| |
Reallocate Storage in a save way.
#if DEBUG
fprintf (stderr, "Reallocation error\n");
#endif
buffer = 0;
}
- Parameters
-
buffer | is a pointer to a elektraMalloc |
size | is the new size for the memory |
- Return values
-
◆ elektraStrCaseCmp()
int elektraStrCaseCmp |
( |
const char * |
s1, |
|
|
const char * |
s2 |
|
) |
| |
Compare Strings ignoring case.
- Parameters
-
s1 | The first string to be compared |
s2 | The second string to be compared |
- Returns
- a negative number if s1 is less than s2
- Return values
-
- Returns
- a positive number if s1 is greater than s2
◆ elektraStrCmp()
int elektraStrCmp |
( |
const char * |
s1, |
|
|
const char * |
s2 |
|
) |
| |
Compare Strings.
- Parameters
-
s1 | The first string to be compared |
s2 | The second string to be compared |
- Returns
- a negative number if s1 is less than s2
- Return values
-
- Returns
- a positive number if s1 is greater than s2
◆ elektraStrDup()
char* elektraStrDup |
( |
const char * |
s | ) |
|
Copy string into new allocated memory.
You need to free the memory yourself.
- Note
- that size is determined at runtime. So if you have a size information, don't use that function.
- Parameters
-
s | the null-terminated string to duplicate |
- Returns
- 0 if out of memory, a pointer otherwise
- Precondition
- s must be a c-string.
- See also
- elektraFree
-
elektraStrLen
-
elektraStrNDup
◆ elektraStrLen()
size_t elektraStrLen |
( |
const char * |
s | ) |
|
Calculates the length in bytes of a string.
This function differs from strlen() because it is Unicode and multibyte chars safe. While strlen() counts characters and ignores the final NULL, elektraStrLen() count bytes including the ending NULL.
It must not be used to search for / in the name, because it does not consider escaping. Instead use the unescaped name.
- See also
- keyUnescapedName()
- Parameters
-
s | the string to get the length from |
- Returns
- number of bytes used by the string, including the final NULL.
◆ elektraStrNCaseCmp()
int elektraStrNCaseCmp |
( |
const char * |
s1, |
|
|
const char * |
s2, |
|
|
size_t |
n |
|
) |
| |
Compare Strings ignoring case up to a maximum length.
- Parameters
-
s1 | The first string to be compared |
s2 | The second string to be compared |
n | The maximum length to be compared |
- Returns
- a negative number if s1 is less than s2
- Return values
-
- Returns
- a positive number if s1 is greater than s2
◆ elektraStrNCmp()
int elektraStrNCmp |
( |
const char * |
s1, |
|
|
const char * |
s2, |
|
|
size_t |
n |
|
) |
| |
Compare Strings up to a maximum length.
- Parameters
-
s1 | The first string to be compared |
s2 | The second string to be compared |
n | The maximum length to be compared |
- Returns
- a negative number if s1 is less than s2
- Return values
-
- Returns
- a positive number if s1 is greater than s2
◆ elektraStrNDup()
char* elektraStrNDup |
( |
const char * |
s, |
|
|
size_t |
l |
|
) |
| |
Copy buffer into new allocated memory.
You need to free the memory yourself.
This function also works with \0 characters in the buffer. The length is taken as given, it must be correct.
- Returns
- 0 if out of memory, a pointer otherwise
- Parameters
-
s | must be an allocated buffer |
l | the length of s |
◆ elektraVFormat()
char char* elektraVFormat |
( |
const char * |
format, |
|
|
va_list |
arg_list |
|
) |
| |
Does string formatting in fresh allocated memory.
- Parameters
-
format | as in vprintf() |
arg_list | as in vprintf() |
- Returns
- new allocated memory (free with elektraFree)
int elektraRealloc(void **buffer, size_t size)
Reallocate Storage in a save way.
Definition: internal.c:232
void elektraFree(void *ptr)
Free memory of Elektra or its backends.
Definition: internal.c:304
void * elektraMalloc(size_t size)
Allocate memory for Elektra.
Definition: internal.c:272