/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/



#include	"r64_types.h"

int
_new_ce(R64_FILE * f)
{
R64_CACHE_ENT * ce1;
	if ( f->free_list ) {
		ce1 = f->free_list;
		f->free_list = ce1->next;
	}
	else {
		ce1 = f->cache[0].prev;
		if ( ce1->flags&EF_DIRTY )
			if ( _r64_flush(f,ce1) < 0 )
				return -1;
		ce1->prev->next = ce1->next;
		ce1->next->prev = ce1->prev;
	}
	ce1->prev = &f->cache[0];
	ce1->next = f->cache[0].next;
	ce1->prev->next = ce1;
	ce1->next->prev = ce1;
	return 0;
}
