Beispiel #1
0
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;
}
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
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()