/**********************************************************************
 
	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	<fcntl.h>
#include	"memory_debug.h"
#include	"pdb.h"
#include	"fa.h"
#include	"utils.h"

PDB*
open_pdb(char * filename,int oflags,int mode,int flags)
{
PDB * p;
int fid;
char * _f;
	_f = change_delim_str(filename);
	fid = u_open(_f,oflags,mode);
	if ( fid < 0 ) {
		p = 0;
		goto end;
	}
	p = d_alloc(sizeof(*p),2);
	p->fid = fid;
	p->flags = flags;
	u_lseek(fid,0,SEEK_SET);
	p->fofs = 0;
	p->request = 0;
	p->next_request = 0;
	p->cache = new_file(filename);

	p->buf_ptr = -1;
	p->buf_len = 0;
	p->seek_ptr = 0;
	p->freelist_work = 0;
end:
	if ( _f != filename )
		d_f_ree(_f);
	return p;
}

