Functions

KDB Backends :: Internal Helper for Elektra

Internal Methods for Elektra and Backends. More...

Functions

int elektraStrCmp (const char *s1, const char *s2)
int elektraStrCaseCmp (const char *s1, const char *s2)
int elektraRealloc (void **buffer, size_t size)
void elektraFree (void *ptr)
char * elektraStrDup (const char *s)
char * elektraStrNDup (const char *s, size_t l)
size_t elektraStrLen (const char *s)

Detailed Description

Internal Methods for Elektra and Backends.

To use them:

 #include <kdbbackend.h>

There are some areas where libraries have to reimplement some basic functions to archive support for non-standard systems, for testing purposes or to provide a little more convenience.


Function Documentation

void elektraFree ( void *  ptr  ) 

Free memory of elektra or its backends.

Parameters:
ptr the pointer to free
See also:
elektraMalloc
int elektraRealloc ( void **  buffer,
size_t  size 
)

Reallocate Storage in a save way.

if (elektraRealloc ((void **) & buffer, new_length) < 0) {
        // here comes the failure handler
        // you can still use the old buffer
#if DEBUG
        fprintf (stderr, "Reallocation error\n");
#endif
        free (buffer);
        buffer = 0;
        // return with error
}
 *
Parameters:
buffer is a pointer to a malloc
size is the new size for the memory
Returns:
-1 on failure
0 on success
int elektraStrCaseCmp ( const char *  s1,
const char *  s2 
)

Compare Strings ignoring case using kdb semantics.

TODO: semantics not correct Does not work with binary sort.

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
0 if s1 matches s2
a positive number if s1 is greater than s2
int elektraStrCmp ( const char *  s1,
const char *  s2 
)

Compare Strings using kdb semantics.

Parameters:
s1 The first string to be compared
s2 The second string to be compared

/ is handled special, it will always be prefered for any other character.

Returns:
a negative number if s1 is less than s2
a number less than, equal to or greater than zero if s1 is found, respectively, to be less than, to match, or be 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:
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
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.

Parameters:
s the string to get the length from
Returns:
number of bytes used by the string, including the final NULL.
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 a allocated buffer
l the length of s