| Elektra 0.11.0

Functions
functional.c File Reference

Functional helper. More...

`#include <kdb.h>`
`#include <errno.h>`
`#include <limits.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`

## Functions
int | elektraKsFilter (KeySet *result, KeySet *input, int(*filter)(const Key *k, void *argument), void *argument)
| return only those keys from the given keyset that pass the supplied filter function with the supplied argument
int | elektraKsToMemArray (KeySet *ks, Key **buffer)
| Builds an array of pointers to the keys in the supplied keyset.

## Detailed Description

Functional helper.

Copyright
  BSD License (see LICENSE.md or https://www.libelektra.org)

## Function Documentation

## ◆ elektraKsFilter()

int elektraKsFilter | ( | KeySet * | result,
|  | KeySet * | input,
|  | int(*)(const Key *k, void *argument) | filter,
|  | void * | argument
| ) |  |

return only those keys from the given keyset that pass the supplied filter function with the supplied argument

Parameters

  result | the keyset that should contain the filtered keys
  input | the keyset whose keys should be filtered
  filter | a function pointer to a function that will be used to filter the keyset. A key will be taken if the function returns a value greater than 0.
  argument | an argument that will be passed to the filter function each time it is called

Returns
  the number of filtered keys if the filter function always returned a positive value, -1 otherwise

Return values

  NULL | on NULL pointer

## ◆ elektraKsToMemArray()

int elektraKsToMemArray | ( | KeySet * | ks,
|  | Key ** | buffer
| ) |  |

Builds an array of pointers to the keys in the supplied keyset.

The keys are not copied, calling keyDel may remove them from the keyset.

The size of the buffer can be easily allocated via ksGetSize. Example:

KeySet *ks = somekeyset;
Key **keyArray = calloc (ksGetSize(ks), sizeof (Key *));
elektraKsToMemArray (ks, keyArray);
... work with the array ...
elektraFree (keyArray);
elektraKsToMemArray
int elektraKsToMemArray(KeySet *ks, Key **buffer)
Builds an array of pointers to the keys in the supplied keyset.
Definition functional.c:84
ksGetSize
ssize_t ksGetSize(const KeySet *ks)
Return the number of Keys that ks contains.
Definition keyset.c:791

Parameters

  ks | the keyset object to work with
  buffer | the buffer to put the result into

Returns
  the number of elements in the array if successful
  a negative number on null pointers or if an error occurred