ECONF\_READCONFIG(3) libeconf Manual ECONF\_READCONFIG(3)

# [NAME](#NAME)

econf\_readConfig - evaluate configuration files for a specific project

# [SYNOPSIS](#SYNOPSIS)

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

**econf\_err econf\_readConfig(econf\_file \*\*key\_file, const char \*project, const char \*usr\_subdir, const char \*config\_name, const char \*config\_suffix, const char \*delim, const char \*comment);**

# [DESCRIPTION](#DESCRIPTION)

**econf\_readConfig** evaluats key/values of a given configuration by reading and merging all needed/available files from different directories. Order is:

/etc/*project*/*config\_name*.*config\_suffix* does exist:

\* /etc/*project*/*config\_name*.*config\_suffix*  
\* *usr\_subdir*/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*  
\* /run/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*  
\* /etc/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*

/etc/*project*/*config\_name*.*config\_suffix* does NOT exist:

/run/*project*/*config\_name*.*config\_suffix* does exist:

\* /run/*project*/*config\_name*.*config\_suffix*  
\* *usr\_subdir*/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*  
\* /run/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*  
\* /etc/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*

/run/*project*/*config\_name*.*config\_suffix* does NOT exist:

\* *usr\_subdir*/*project*/*config\_name*.*config\_suffix*  
\* *usr\_subdir*/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*  
\* /run/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*  
\* /etc/*project*/*config\_name*.*config\_suffix*.d/\*.*config\_suffix*

No main *config\_name*.*config\_suffix* file is defined or must not be parsed:

\* *usr\_subdir*/*project*.d/\*.*config\_suffix*  
\* /run/*project*.d/\*.*config\_suffix*  
\* /etc/*project*.d/\*.*config\_suffix*

*project* name of the project used as subdirectory, can be NULL.

If *config\_name* is NULL, drop-ins without a main configuration file will be parsed only.

*config\_suffix* can also be NULL.

The *delim* parameter specifies the character used to separate keys from values (e.g., "="). If *delim* contains space characters AND none space characters, multiline values are not parseable. The *comment* parameter specifies an array of characters which define the start of a comment (e.g., "#").

If *key\_file* is NULL, the parsed and merged configuration is stored in a newly allocated *econf\_file* structure, which is returned through *key\_file*. Otherwise, the results are directly stored in *key\_file* without validating its memory allocation.

# [RETURN VALUE](#RETURN_VALUE)

**ECONF\_NOFILE**

The specified *file\_name* does not exist.

**ECONF\_NOMEM**

Insufficient memory to allocate the *result* structure.

**ECONF\_MISSING\_BRACKET**  
**ECONF\_TEXT\_AFTER\_SECTION**  
**ECONF\_EMPTY\_SECTION\_NAME**  
**ECONF\_MISSING\_DELIMITER**

The file contains syntax errors and could not be parsed successfully.

**ECONF\_ARGUMENT\_IS\_NULL\_VALUE**

One of the required arguments (such as *result* or *file\_name*) is NULL.

# [EXAMPLE](#EXAMPLE)

Reading content in different cases in following order:

/etc/foo/example.conf does exist:

\* /etc/foo/example.conf  
\* /usr/lib/foo/example.conf.d/ \*.conf  
\* /run/foo/example.conf.d/ \*.conf  
\* /etc/foo/example.conf.d/ \*.conf

/etc/foo/example.conf does NOT exist:

/run/foo/example.conf does exist:

\* /run/foo/example.conf  
\* /usr/lib/foo/example.conf.d/ \*.conf  
\* /run/foo/example.conf.d/ \*.conf  
\* /etc/foo/example.conf.d/ \*.conf

/run/foo/example.conf does NOT exist:

\* /usr/lib/foo/example.conf  
\* /usr/lib/foo/example.conf.d/ \*.conf  
\* /run/foo/example.conf.d/ \*.conf  
\* /etc/foo/example.conf.d/ \*.conf

```
#include <libeconf.h>
#include <stdio.h>
int main(void) {


    econf_file *conf = NULL;


    econf_err err;


    /*


     * Reading


     */


    err = econf_readConfig(&conf,


                           "foo",                 /* project name */


                           "/usr/lib",            /* vendor directory */


                           "example",             /* config name */


                           "conf",                /* suffix */


                           "=",                   /* delimiter */


                           "#");                  /* comment */


    if (err != ECONF_SUCCESS) {


        fprintf(stderr, "Failed to read config: %d\n", err);


        return 1;


    }


    /* Use econf_get... functions here to access values */


    econf_free(conf);


    return 0;
}
```

# [SEE ALSO](#SEE_ALSO)

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

2023-10-25 libeconf

---

Document: econf_readConfig(3) from libeconf 0.8.5-r0 (Chainguard OS)
Source: https://github.com/openSUSE/libeconf
