/*
 * dbclose.c
 * File revision 0
 * Close database files.
 * (c) 2000 Jacob Lundberg, jacob@chaos2.org
 */


/*
 * 2000.10.24	Initial implementation
 */


#include <stdio.h>
#include <errno.h>
#include "db.h"


int db_close(DB_FILE *db_fp) {
/*
 * db_close()
 * Close an open database by descriptor struct.
 */

   int retval = 0;

   if(db_fp) {
      /* Close the file i/o stream. */
      if(fclose(db_fp->file)) --retval;

      /* We should be the last to touch the database so whack anybody who does after us. */
      db_fp->file = NULL;
      ((char *)db_fp)[0] = '\0';

      /* Free the memory. */
      free(db_fp);
   } else {
      /* Let people know if they try to close an unopened database. */
      errno = EINVAL;
      --retval;
   }

   return(retval);

}

