Chapter 38. Application identifiers and configuration directories

#include <x/appid.H>

std::string x::appid() noexcept
{
    return "example.libcxx.com";
}

std::string x::appver() noexcept
{
    return "1.0";
}

x::appid()'s returns the application's identifier. This is a string that uniquely identifies an application. The naming convention is to use an Internet domain name that the application owns. It's also acceptable to use mailbox@domain.com, formatted like an E-mail address, using an application-owned domain.

An application declares and defines x::appid() (in one of its translation units), as shown. If it's not declared LibCXX provides a weakly-defined default implementation that returns a string based on the executable's filename and localhost.localdomain.

Similarly, x::appver() declares the application's version. If it's not declared LibCXX provides a weakly-defined default version string from the application's executable's timestamp.

#include <x/config.H>

std::string configdir=x::configdir();

std::string configdir=x::configdir("example@libcxx.com");

x::configdir() calls x::appid() and creates the directory $HOME/.libcxx/appid if it does not exist already, and returns an absolute pathname to this directory. x::configdir() installs hidden symbolic links to the running process's executable in this directory; and ignores all of its other contents.

An overloaded x::configdir() function takes the application identifier as an explicit parameter.

x::configdir() makes periodic checks of all subdirectories in $HOME/.libcxx, and removes subdirectories with broken symbolic links. x::configdir()'s intended usage is to implement a per-user application configuration directories; with a mechanism that automatically purges configuration directories linked to uninstalled applications, as long as at least one LibCXX application gets run regularly.