Is .config called other things for different system languages?

I'm making an application that reads/writes to files in the ~/.config folder; however, I want to make sure it works under all systems. Is .config called other things for different system languages? Is there a better way of accessing its value than using a hardcoded .config string? (a la an environment variable)

What is the best practice for this? If there is no established best practice, what is the simplest approach that guarantees the desired result?


Solution 1:

That configuration directory is specified by the XDG Base Directory Specification standard.

The answer to your question is in the Environment variables section:

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

Be sure to also read Basics, to ensure that you are using the right directories for the right files.

You may also want to know what to do when $HOME is not set. This is not specified by XDG, however what some applications do is to throw an error and exit. Alternatively, you can get the current user ID via getuid(2) and use getpwuid(3) to extract the home directory.

Solution 2:

It's part of the XDG Base Directory Specification:

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.