home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbase_c.zip / DBASE_C.LBR / DBCREATE.C < prev    next >
Text File  |  1989-03-20  |  1KB  |  38 lines

  1. #include    "libc.h"
  2. #include    "dbase.h"
  3.  
  4. /***************************************************************
  5. *  db_create(filename)  creates a new  DBASE file  header for  *
  6. * output.  A pointer to the DBASE file description block is    *
  7. * returned if there is sufficient memory.  If not, the ERROR   *
  8. * value is returned.                                           *
  9. *                                                              *
  10. * Richard Hoffbeck                                  (c) 1983   *
  11. ***************************************************************/
  12. db_create(filename)
  13.    char            filename[];
  14.    {int         *inptr ;
  15.     DBASE_FILE  *db_ptr ;   
  16.  
  17.    /*------- allocate memory for the file desc. block -----*/
  18.    if( (db_ptr=alloc(DB_HDR_SZ)) == ERROR ){
  19.       printf("\nInsufficient HEAP space to create file descriptor");
  20.       printf("\nCalled from db_create");
  21.       exit();
  22.    }
  23.  
  24.    /*----- initialize the file description block -----*/
  25.    if( (inptr=open(filename,O_TRUNC+O_RDWR)) == ERROR ){
  26.       printf("\nUnable to open file %s",filename);
  27.       printf("Called from db_create");
  28.       return( ERROR );
  29.    }
  30.  
  31.    clear(db_ptr,DB_HDR_SZ,0) ;
  32.    db_ptr->file_ptr = inptr ;
  33.    db_ptr->version  = 02 ;
  34.    db_ptr->chng_ind = TRUE ;
  35.  
  36.    return( db_ptr ) ;
  37. }
  38.