ECONF\_MERGEFILES(3) libeconf Manual ECONF\_MERGEFILES(3)

# [NAME](#NAME)

econf\_mergeFiles - Merge two libeconf file objects

# [SYNOPSIS](#SYNOPSIS)

```
#include <libeconf.h>
```

**econf\_err econf\_mergeFiles(econf\_file \** result\_file, econf\_file * usr\_file, econf\_file * etc\_file);**

# [DESCRIPTION](#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](#RETURN_VALUE)

On failure, an error code (of type **econf\_err**) is returned.

# [ERRORS](#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](#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](#SEE_ALSO)

[**libeconf**(3)](/man/os/libeconf/libeconf.3), [**econf\_readFile**(3)](/man/os/libeconf/econf_readFile.3), [**econf\_free**(3)](/man/os/libeconf/econf_free.3), [**econf\_errString**(3)](/man/os/libeconf/econf_errString.3).

2024-12-14 libeconf

---

Document: econf_mergeFiles(3) from libeconf 0.8.6-r3 (Chainguard OS)
Source: https://github.com/openSUSE/libeconf
