ECONF\_READCONFIGWITHCALLBACK(3) libeconf Manual ECONF\_READCONFIGWITHCALLBACK(3)

# [NAME](#NAME)

econf\_readConfigWithCallback - evaluate configuration files for a specific project

# [SYNOPSIS](#SYNOPSIS)

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

**econf\_err econf\_readConfigWithCallback(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, bool (\*callback)(const char \*filename, const void \*data), const void \*callback\_data);**

# [DESCRIPTION](#DESCRIPTION)

**econf\_readConfigWithCallback** 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*

For each parsed file the user defined function *callback* will be called in order e.g. to check the correct file permissions. This user defined function has the pathname as parameter and returns true if this file can be parsed. If not, the parsing of all files will be aborted and ECONF\_PARSING\_CALLBACK\_FAILED will be returned.

*callback\_data* is a pointer which will be given to the *callback* function.

*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 ey\_file is NULL, the parsed and merged configuration is stored in a newly allocated conf\_file structure, which is returned through ey\_file. Otherwise, the results are directly stored in ey\_file without validating its memory allocation.

# [RETURN VALUE](#RETURN_VALUE)

On success, **econf\_readConfigWithCallback** returns **ECONF\_SUCCESS**.

On failure, a specific error code is returned as defined in **econf\_err**.

# [ERRORS](#ERRORS)

**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\_PARSING\_CALLBACK\_FAILED**

The user-provided *callback* returned false, aborting the operation.

**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>
bool checkFile(const char *filename, const void *data) {


  /* checking code which returns true or false */


  return true;
}
int main(void) {


     econf_file *conf = NULL;


     econf_err err;


     /*


      * Reading


      */


     err = econf_readConfigWithCallback(&conf,


                            "foo",                 /* project name */


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


                            "example",             /* config name */


                            "conf",                /* suffix */


                            "=",                   /* delimiter */


                            "#",                   /* comment */


                            checkFile,             /* callback */


                            NULL);                 /* no data for callback */


     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\_readConfig**(3)](/man/os/libeconf/econf_readConfig.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_readConfigWithCallback(3) from libeconf 0.8.4-r3 (Chainguard OS)
Source: https://github.com/openSUSE/libeconf
