radare2/libr/util/xdg.c
pancake c2851a6f46 Use XDG instead of R2_HOME_CACHEDIR and R2_HOME_HISTORY ##core
* Implement and use the new `r_xdg` apis
* Remove R2_HOME_RC, R2_HOME_RC_DIR and R2_HOME_CONFIGDIR
* R2_HOME_THEMES, R2_HOME_ZIGNS R2_HOME_PDB R2_HOME_HUD R2_HOME_BINRC and R2_HOME_BIN
* Disable the bin-specific user scripts
* Massage the help messages and reduce and review all the env vars used
2022-09-29 17:33:21 +02:00

38 lines
954 B
C

/* radare2 - LGPL - Copyright 2022 - pancake */
// move into file.c ?
#include <r_util.h>
#if 0
macOS:
* ~/Library/radare2?
Windows
* %AppData% ?= XDG_DATA_HOME
* %LocalAppData% ?= XDG_CACHE_HOME
#endif
static char *xdg(const char *env, const char *a, const char *s) {
char *dir = r_sys_getenv (env);
if (R_STR_ISEMPTY (dir)) {
free (dir);
dir = r_str_home (a);
}
char *res = r_file_new (dir, "radare2", s, NULL);
free (dir);
return res;
}
// XDG_CONFIG_HOME User-specific configuration files ~/.var/app/<app-id>/config
R_API char *r_xdg_configdir(const char *s) {
return xdg ("XDG_CONFIG_HOME", ".config", s);
}
// XDG_DATA_HOME User-specific data ~/.var/app/<app-id>/data
R_API char *r_xdg_datadir(const char *s) {
return xdg ("XDG_DATA_HOME", ".local/share", s);
}
// XDG_CACHE_HOME Non-essential user-specific data ~/.var/app/<app-id>/cache
R_API char *r_xdg_cachedir(const char *s) {
return xdg ("XDG_CACHE_HOME", ".cache", s);
}