Exemplo n.º 1
0
/*
 * open rcfile and load its content, if already open - return previous handle
 */
int
rc_open(const char *filename, const char *mode,struct rcfile **rcfile)
{
	struct rcfile *rcp;
	FILE *f;
	rcp = rc_find(filename);
	if (rcp) {
		*rcfile = rcp;
		return (0);
	}
	f = fopen (filename, mode);
	if (f == NULL)
		return errno;
	rcp = malloc(sizeof(struct rcfile));
	if (rcp == NULL) {
		fclose(f);
		return ENOMEM;
	}
	bzero(rcp, sizeof(struct rcfile));
	rcp->rf_name = strdup(filename);
	rcp->rf_f = f;
	SLIST_INSERT_HEAD(&pf_head, rcp, rf_next);
	rc_parse(rcp);
	*rcfile = rcp;
	return (0);
}
Exemplo n.º 2
0
int
rc_merge(char *filename,struct rcfile **rcfile) {
	struct rcfile *rcp = *rcfile;
	FILE *f, *t;
	
	if (rcp == NULL) {
		return rc_open(filename,"r",rcfile);
	}
	f = fopen (filename, "r");
	if (f==NULL)
		return errno;
	t = rcp->rf_f;
	rcp->rf_f = f;
	rc_parse(rcp);
	rcp->rf_f = t;
	fclose(f);
	return 0;
}