~nytpu/xdgbasedir.c

ref: e0344cc04c7ed83928dce5abbe002f63477d78a1 xdgbasedir.c/xdgbasedir.h -rw-r--r-- 2.7 KiB
e0344cc0nytpu fix license issue 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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