home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / DBAPI.ZIP / DBFCLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-25  |  977 b   |  45 lines

  1. #include <fcntl.h>
  2. #include <io.h>
  3. #include <stdlib.h>
  4. #include <mem.h>
  5. #include <errno.h>
  6. #include <dos.h>
  7. #include "dbapi.h"
  8.  
  9. /*man*************************************************************
  10. NAME
  11.     dbfclose
  12.  
  13. SYNOPSIS
  14.     #include "dbapi.h"
  15.  
  16.     void dbfclose(DBFFILE *dbf)
  17.  
  18. DESCRIPTION
  19.     closes dbase opened with dbfopen or created with dbfcreate.
  20.     if dbfwrite has been used on the dbase then file header is
  21.     updated as well.
  22. *****************************************************************/
  23. void dbfclose(DBFFILE *dbf)
  24. {
  25. struct date d;
  26.     if (dbf->written) {
  27.         getdate(&d);
  28.         dbf->update.year=d.da_year%100;
  29.         dbf->update.month=d.da_mon;
  30.         dbf->update.day=d.da_day;
  31.     }
  32.     fseek(dbf->fp,1,SEEK_SET);
  33.     if (dbf->ver==2) {
  34.         fwrite(&dbf->nrecords,2,1,dbf->fp);
  35.         fwrite(&dbf->update,3,1,dbf->fp);
  36.     }
  37.     else {
  38.         fwrite(&dbf->update,3,1,dbf->fp);
  39.         fwrite(&dbf->nrecords,4,1,dbf->fp);
  40.     }
  41.     fclose(dbf->fp);
  42.     dbkillflds(dbf->fields);
  43.     free(dbf);
  44. }
  45.