ECONF_MERGEFILES(3)

NAME
econf_mergeFiles - Merge two libeconf file objects

SYNOPSIS

#include <libeconf.h>

econf_err econf_mergeFiles(econf_file ** result_file, econf_file * usr_file, econf_file * etc_file);

DESCRIPTION

The econf_mergeFiles function merges the content of two econf_file objects, usr_file and etc_file, into a new econf_file object pointed to by result_file.

The merge process typically treats usr_file as the base configuration (e.g., vendor defaults found in /usr) and etc_file as the overlay configuration (e.g., administrator changes found in /etc). Entries in etc_file with the same group and key as in usr_file will override the values from usr_file in the resulting object.

Comment and delimiter tag will be taken from usr_file. This can be changed by calling the functions econf_set_comment_tag and econf_set_delimiter_tag.

The newly created object in result_file must be freed by the user using econf_free. The original usr_file and etc_file objects remain unchanged and must be freed separately.

RETURN VALUE

On failure, an error code (of type econf_err) is returned.

ERRORS

ECONF_NOMEM
              Insufficient memory to allocate the new econf_file object.

ECONF_ARGUMENT_IS_NULL_VALUE
              One of the input parameters usr_file or etc_file is NULL, or result_file is NULL.

ECONF_ERROR
              General internal error during the merge process.

EXAMPLE

          econf_file *key_file_1 = NULL, *key_file_2 = NULL, *merged_file = NULL;
          econf_err error;
          /* Load two configuration files */
          econf_readFile(&key_file_1, "/usr/etc/test.conf", "=", "#");
          econf_readFile(&key_file_2, "/etc/test.conf", "=", "#");
          /* Merge them, with key_file_2 overriding key_file_1 */
          error = econf_mergeFiles(&merged_file, key_file_1, key_file_2);
          if (error != ECONF_SUCCESS) {
              fprintf(stderr, "Merge failed: %s\n", econf_errString(error));
          }
          /* Clean up */
          econf_free(key_file_1);
          econf_free(key_file_2);
          econf_free(merged_file);

SEE ALSO

libeconf(3), econf_readFile(3), econf_free(3), econf_errString(3).