summary refs log tree commit diff
path: root/xdg.c
blob: b20642721ca14ede41a96771d28e59f4d22b1b0a (plain) (blame)
1
June McEnroe
2019-07-20Handle shotty output options more centrallyJune McEnroe
2019-07-17Add ^Q to ptee for MC sequenceJune McEnroe
2019-07-17Add Adulthood RitesJune McEnroe
2019-07-16Add catgirl shottyJune McEnroe
2019-07-16Fix SGRs 90 and 100June McEnroe
2019-07-15Add up -tJune McEnroe
2019-07-15Implement scrolling regionJune McEnroe
2019-07-14Add CSI names to shotty -dJune McEnroe
2019-07-14Ignore CSI tJune McEnroe
2019-07-14Add more info to shotty man pageJune McEnroe
2019-07-14Fix OSC PT handlingJune McEnroe
2019-07-14Handle OSC in shottyJune McEnroe
2019-07-14Add shotty -dJune McEnroe
2019-07-13Add shotty -cJune McEnroe
2019-07-13Add DL to shottyJune McEnroe
2019-07-12Color html rather than bodyJune McEnroe
2019-07-12Make author consistent and update URLsJune McEnroe
2019-07-12Move to www/text.causal.agencyJune McEnroe
2019-07-12) { *dirs = ""; return path; } *dirs = getenv(base.envDirs); if (!*dirs) *dirs = base.defDirs; const char *home = getenv("HOME"); const char *baseHome = getenv(base.envHome); if (baseHome) { snprintf(buf, sizeof(buf), "%s/" SUBDIR "/%s", baseHome, path); } else if (home) { snprintf( buf, sizeof(buf), "%s/%s/" SUBDIR "/%s", home, base.defHome, path ); } else { errx(EX_CONFIG, "HOME unset"); } return buf; } const char *configPath(const char **dirs, const char *path) { return basePath(Config, dirs, path); } const char *dataPath(const char **dirs, const char *path) { return basePath(Data, dirs, path); } FILE *configOpen(const char *path, const char *mode) { const char *dirs = NULL; for (const char *abs; NULL != (abs = configPath(&dirs, path));) { FILE *file = fopen(abs, mode); if (file) return file; if (errno != ENOENT) warn("%s", abs); } dirs = NULL; warn("%s", configPath(&dirs, path)); return NULL; } void dataMkdir(const char *path) { const char *dirs = NULL; path = dataPath(&dirs, path); int error = mkdir(path, S_IRWXU); if (error && errno != EEXIST) warn("%s", path); } FILE *dataOpen(const char *path, const char *mode) { const char *dirs = NULL; for (const char *abs; NULL != (abs = dataPath(&dirs, path));) { FILE *file = fopen(abs, mode); if (file) return file; if (errno != ENOENT) warn("%s", abs); } if (mode[0] != 'r') dataMkdir(""); dirs = NULL; path = dataPath(&dirs, path); FILE *file = fopen(path, mode); if (!file) warn("%s", path); return file; }