void xdg_init() { const char *basedir; char *path; struct stat buf; mode_t process_mask; handle = g_new(xdgHandle, 1); handle = xdgInitHandle(handle); /* check if we have the required path */ basedir = xdgConfigHome(handle); path = g_build_filename(basedir, PREFIX, NULL); printf("Config dir:%s\n", path); if (stat(path, &buf)) { xdgMakePath(path, S_IRWXU | S_IRWXG); printf("Creating Config dir: %s\n", path); } g_free(path); basedir = xdgDataHome(handle); path = g_build_filename(basedir, PREFIX, NULL); printf("Data dir:%s\n", path); if (stat(path, &buf)) { xdgMakePath(path, S_IRWXU | S_IRWXG); printf("Creating Data dir: %s\n", path); } g_free(path); }
char* data_get_path(const char *filename) { char *basedir; char *path; basedir = xdgDataHome(handle); path = g_build_filename(basedir, PREFIX, filename, NULL); return path; }
std::string cXdg::GetHomeDataDirectory() { std::string sDirectory = xdgDataHome(&handle); if (sDirectory.empty() || (sDirectory[0] == 0)) { const std::string sHome = GetHomeDirectory(); sDirectory = sHome + "/.local/share"; } return sDirectory; }
void init_directories(xdgHandle *xdg) { /* create luakit directory */ globalconf.base_cache_directory = g_build_filename(xdgCacheHome(xdg), "luakit", NULL); globalconf.base_config_directory = g_build_filename(xdgConfigHome(xdg), "luakit", NULL); globalconf.base_data_directory = g_build_filename(xdgDataHome(xdg), "luakit", NULL); g_mkdir_with_parents(globalconf.base_cache_directory, 0771); g_mkdir_with_parents(globalconf.base_config_directory, 0771); g_mkdir_with_parents(globalconf.base_data_directory, 0771); }
int main(int argc, char* argv[]) { const char * const * item; xdgHandle handle; if (!xdgInitHandle(&handle)) return 1; printf("${XDG_DATA_HOME:-$HOME/.local/share}=%s\n", xdgDataHome(&handle)); printf("${XDG_CONFIG_HOME:-$HOME/.config}=%s\n", xdgConfigHome(&handle)); printf("${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}="); for (item = xdgDataDirectories(&handle); *item; item++) printf("%s%c", *item, (item[1] ? ':' : '\n')); printf("${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}="); for (item = xdgSearchableDataDirectories(&handle); *item; item++) printf("%s%c", *item, (item[1] ? ':' : '\n')); printf("${XDG_CONFIG_DIRS:-/etc/xdg}="); for (item = xdgConfigDirectories(&handle); *item; item++) printf("%s%c", *item, (item[1] ? ':' : '\n')); printf("${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}="); for (item = xdgSearchableConfigDirectories(&handle); *item; item++) printf("%s%c", *item, (item[1] ? ':' : '\n')); printf("${XDG_CACHE_HOME:-$HOME/.cache}=%s\n", xdgCacheHome(&handle)); xdgWipeHandle(&handle); return 0; }