// VERSION: 1.1.0
/* Return directories following the XDG Base Directory Specification. First
* searches the "single base directory" environment variables such as
* $XDG_DATA_HOME. If that variable doesn't exist or is empty, then returns
* the first directory in the "set" environment variables such as
* $XDG_DATA_DIRS. If the set variable doesn't exist or is empty, returns the
* default directory such as $HOME/.local/share.
*
* <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html>
*
*
* Copyright (c) 2021 nytpu <alex [at] nytpu.com>
* SPDX-License-Identifier: MPL-2.0
* The orginal source for this file is available at <https://git.sr.ht/~nytpu/xdgbasedir.c>.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
*/
#pragma once
#ifndef SMOLLIBS_XDGBASEDIR_H
#define SMOLLIBS_XDGBASEDIR_H
// Append a filename (or config directory name) to a base path, using realloc.
// For instance
// xdg_append_to_path("/home/user/.config", "program/program.conf")
// would result in
// /home/user/.config/program/program.conf
// being returned.
// Returns NULL if an error occurs.
// The returned string should be freed.
char *xdg_append_to_path(char *base_path, const char *file);
// Find a directory to store data---stored application data that is necessary
// to be preserved.
// Returns NULL if a directory is unable to be found or if an error occurs.
// The returned string should be freed.
char *xdg_get_data_dir(void);
// Find a directory to store configuration files---should be used for
// configuration only, not for any application-managed data.
// Returns NULL if a directory is unable to be found or if an error occurs.
// The returned string should be freed.
char *xdg_get_config_dir(void);
// Find a directory to store application state---things such as logs or undo
// history that may be reused after a restart but are not integral to the
// application's data.
// Returns NULL if a directory is unable to be found or if an error occurs.
// The returned string should be freed.
char *xdg_get_state_dir(void);
// Find a directory to store cache files---non-essential data that can be
// removed without any impact (as long as the application is not running).
// Returns NULL if a directory is unable to be found or if an error occurs.
// The returned string should be freed.
char *xdg_get_cache_dir(void);
// Find a directory to store runtime files---files such as sockets or named
// pipes.
// Returns NULL if a directory is unable to be found or if an error occurs.
// The returned string should be freed.
char *xdg_get_runtime_dir(void);
#endif // SMOLLIBS_XDGBASEDIR_H