GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Functions
gp_app_cfg.h File Reference

Utility functions for application config files. More...

#include <core/gp_compiler.h>

Go to the source code of this file.

Functions

char * gp_app_cfg_path (const char *app_name, const char *cfg_filename)
 Prepares a path to a config file.
 
int gp_app_cfg_mkpath (const char *app_name)
 Creates a path for a config files, if it does not exists.
 
int gp_app_cfg_scanf (const char *app_name, const char *cfg_filename, const char *fmt,...)
 Does a single scanf() from a config file.
 
int gp_app_cfg_printf (const char *app_name, const char *cfg_filename, const char *fmt,...)
 Does a simple printf() to a config file.
 

Detailed Description

Utility functions for application config files.

Definition in file gp_app_cfg.h.

Function Documentation

◆ gp_app_cfg_mkpath()

int gp_app_cfg_mkpath ( const char *  app_name)

Creates a path for a config files, if it does not exists.

The path is constructed as "$HOME/.config/$APP_NAME/".

Works exactly the same as 'mkdir -p'.

Parameters
app_nameAn application name
Returns
Zero on success, non-zero otherwise and errno is set.

◆ gp_app_cfg_path()

char * gp_app_cfg_path ( const char *  app_name,
const char *  cfg_filename 
)

Prepares a path to a config file.

The path is constructed as "$HOME/.config/$APP_NAME/$CFG_FILENAME".

Parameters
app_nameAn application name
cfg_filenameA config filename
Returns
A newly allocated buffer with path or NULL in a case of a failure.

◆ gp_app_cfg_printf()

int gp_app_cfg_printf ( const char *  app_name,
const char *  cfg_filename,
const char *  fmt,
  ... 
)

Does a simple printf() to a config file.

Simplified interface for cases when we can write the config with single printf.

Parameters
app_nameAn application name
cfg_filenameA config filename
fmtA printf format string
...A printf parameters
Returns
Returns -1 on error and errno is set.

◆ gp_app_cfg_scanf()

int gp_app_cfg_scanf ( const char *  app_name,
const char *  cfg_filename,
const char *  fmt,
  ... 
)

Does a single scanf() from a config file.

Simplified interface for cases when we can read the config with single scanf.

Parameters
app_nameAn application name
cfg_filenameA config filename
fmtA scanf format string
...A scanf parameters
Returns
Returns -1 if the config file does not exists otherwise the return value from the final scanf().