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?
That configuration directory is specified by the XDG Base Directory Specification standard.
The answer to your question is in the Environment variables section:
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 viagetuid(2)
and usegetpwuid(3)
to extract the home directory.It's part of the XDG Base Directory Specification: