ECONF\_READFILE(3) libeconf Manual ECONF\_READFILE(3)

# [NAME](#NAME)

econf\_readFile - parse a configuration file

# [SYNOPSIS](#SYNOPSIS)

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

**econf\_err econf\_readFile(econf\_file \*\*result, const char \*file\_name, const char \*delim, const char \*comment);**

# [DESCRIPTION](#DESCRIPTION)

**econf\_readFile** reads and parses the configuration file specified by *file\_name*. The function allocates a new **econf\_file** object, populates it with the parsed data, and stores a pointer to it in *result*.

The *delim* argument specifies the character (or characters) used to separate keys from values (e.g., "=" or ":"). The *comment* argument specifies the character that introduces a comment (e.g., "#" or ";"). Lines starting with this character are ignored during parsing.

The caller is responsible for freeing the allocated memory by calling **econf\_free** on *result* when it is no longer needed.

# [RETURN VALUE](#RETURN_VALUE)

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

On failure, a non-zero error code of type **econf\_err** is returned.

# [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\_ARGUMENT\_IS\_NULL\_VALUE**

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

# [EXAMPLE](#EXAMPLE)

The following example demonstrates how to read a simple configuration file:

```


      #include <libeconf.h>


      #include <stdio.h>


      int main(void) {


          econf_file *conf = NULL;


          econf_err err;


          /* Read file with "=" as delimiter and "#" as comment */


          err = econf_readFile(&conf, "/etc/example.conf", "=", "#");


          if (err != ECONF_SUCCESS) {


              fprintf(stderr, "Failed to read file: %s\n", econf_errString(err));


              return 1;


          }


          /* ... Process configuration ... */


          econf_free(conf);


          return 0;


      }


    
```

# [APPLICATION USAGE](#APPLICATION_USAGE)

Default behaviour if entries have the same name in one file: The first hit will be returned. Further entries will be ignored. This can be changed by setting the environment variable JOIN\_SAME\_ENTRIES (see econf\_set\_opt). In that case entries with the same name will be joined to one single entry. Keys have to be unique per section. Otherwise the behaviour is undefined.

# [SEE ALSO](#SEE_ALSO)

[**libeconf**(3)](/man/os/libeconf/libeconf.3), [**econf\_free**(3)](/man/os/libeconf/econf_free.3), [**econf\_writeFile**(3)](/man/os/libeconf/econf_writeFile.3), [**econf\_errString**(3)](/man/os/libeconf/econf_errString.3) [**econf\_set\_opt**(3)](/man/os/libeconf/econf_set_opt.3).

2023-12-15 libeconf

---

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