static struct placefile * placefile_create(const struct place *from, const char *name, bool fromsystemdir) { struct placefile *pf; const char *s; size_t len; pf = domalloc(sizeof(*pf)); pf->includedfrom = *from; s = strrchr(name, '/'); len = (s == NULL) ? 0 : s - name; pf->dir = dostrndup(name, len); pf->name = dostrdup(name); pf->fromsystemdir = fromsystemdir; if (from->file != NULL) { pf->depth = from->file->depth + 1; } else { pf->depth = 1; } return pf; }
char *getconfigfile(const char *path, const char *fname) { char *cfgpath = getconfigpath(path); char result[PATH_MAX]; sprintf(result, "%s%s", cfgpath, fname); free(cfgpath); return dostrdup(result); } // getconfigfile()
char *getconfigpath(const char *pname) { char userhome[PATH_MAX]; char *enval = getenv("USER"); sprintf(userhome, "/home/%s/.config/%s/", enval, pname); return dostrdup(userhome); } // getconfigpath()
char *gettmpfn(const char *aname) { char tfn[NAME_MAX]; char *user = getenv("LOGNAME"); if (!user) { user = getenv("USER"); if (!user) { fputs("Unable to get user or login name.\n", stderr); exit(EXIT_FAILURE); } } pid_t myid = getpid(); sprintf(tfn, "/tmp/%s%i%s", user, myid, aname); return dostrdup(tfn); } // gettmpfn()