Elektra  0.8.16
Functions
kdbhelper.h File Reference

Helper for memory management. More...

#include "kdbconfig.h"
#include <kdbtypes.h>
#include <stdarg.h>
#include <stddef.h>
Include dependency graph for kdbhelper.h:
This graph shows which files directly or indirectly include this file:

Functions

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...
 
char * elektraStrDup (const char *s)
 Copy string into new allocated memory. More...
 
int elektraRealloc (void **buffer, size_t size)
 Reallocate Storage in a save way. More...
 
char * elektraFormat (const char *format,...)
 Does string formating in fresh allocated memory. More...
 
char * elektraVFormat (const char *format, va_list arg_list)
 Does string formating in fresh allocated memory. More...
 
int elektraStrCmp (const char *s1, const char *s2)
 Compare Strings. More...
 
int elektraStrCaseCmp (const char *s1, const char *s2)
 Compare Strings ignoring case. More...
 
int elektraMemCaseCmp (const char *s1, const char *s2, size_t size)
 Compare two memory regions but make cmp chars uppercase before comparision. More...
 
size_t elektraStrLen (const char *s)
 Calculates the length in bytes of a string. More...
 

Detailed Description

Helper for memory management.

Should be always preferred. Can be used for profiling and tracing.

Function Documentation

void* elektraCalloc ( size_t  size)

Allocate memory for Elektra.

Memory will be set to 0.

Parameters
sizethe requested size
See also
elektraMalloc
char* elektraFormat ( const char *  format,
  ... 
)

Does string formating in fresh allocated memory.

Parameters
formatas in printf()
...as in printf()
Returns
new allocated memory (free with elektraFree)
void elektraFree ( void *  ptr)

Free memory of elektra or its backends.

Parameters
ptrthe pointer to free
See also
elektraMalloc
void* elektraMalloc ( size_t  size)

Allocate memory for Elektra.

1 if ((buffer = elektraMalloc (length)) == 0) {
2  // here comes the failure handler
3  // no allocation happened here, so don't use buffer
4 #if DEBUG
5  fprintf (stderr, "Allocation error");
6 #endif
7  // return with error
8 }
Parameters
sizethe requested size

This function is compatible to ANSI-C elektraMalloc

See also
elektraFree
elektraCalloc
int elektraMemCaseCmp ( const char *  s1,
const char *  s2,
size_t  size 
)

Compare two memory regions but make cmp chars uppercase before comparision.

Parameters
s1The first string to be compared
s2The second string to be compared
sizeto be compared
Returns
a negative number if s1 is less than s2
Return values
0if s1 matches s2
Returns
a positive number if s1 is greater than s2
int elektraRealloc ( void **  buffer,
size_t  size 
)

Reallocate Storage in a save way.

1 if (elektraRealloc ((void **) & buffer, new_length) < 0) {
2  // here comes the failure handler
3  // you can still use the old buffer
4 #if DEBUG
5  fprintf (stderr, "Reallocation error\n");
6 #endif
7  elektraFree (buffer);
8  buffer = 0;
9  // return with error
10 }
Parameters
bufferis a pointer to a elektraMalloc
sizeis the new size for the memory
Return values
-1on failure
0on success
int elektraStrCaseCmp ( const char *  s1,
const char *  s2 
)

Compare Strings ignoring case.

Parameters
s1The first string to be compared
s2The second string to be compared
Returns
a negative number if s1 is less than s2
Return values
0if s1 matches s2
Returns
a positive number if s1 is greater than s2
int elektraStrCmp ( const char *  s1,
const char *  s2 
)

Compare Strings.

Parameters
s1The first string to be compared
s2The second string to be compared
Returns
a negative number if s1 is less than s2
Return values
0if s1 matches s2
Returns
a positive number if s1 is greater than s2
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
sthe 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
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
sthe string to get the length from
Returns
number of bytes used by the string, including the final NULL.
char* elektraVFormat ( const char *  format,
va_list  arg_list 
)

Does string formating in fresh allocated memory.

Parameters
formatas in vprintf()
arg_listas in vprintf()
Returns
new allocated memory (free with elektraFree)