FreeBSD/usr.sbin/nandsim/nandsim_rcfile.c
/*
 * open rcfile and load its content, if already open - return previous handle
 */
open rcfile and load its content, if already open - return previous handle
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);
}
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 ) ; }
open rcfile and load its content, if already open - return previous handle
open rcfile and load its content if already open - return previous handle