home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbase_c.zip / DBWRITE.C < prev   
Text File  |  1989-03-20  |  1KB  |  29 lines

  1.  
  2. #include  "libc.h"
  3. #include  "dbase.h"
  4.  
  5.  
  6. /*************************************************************************
  7. * db_write writes out n records from buffer to the DBASE file mapped at  *
  8. * db_ptr.   It  returns  -1  for an  error and the  number of characters *
  9. * written if the write is sucessful                                      *
  10. *************************************************************************/
  11. db_write(db_ptr,buffer,records)
  12.    DBASE_FILE  *db_ptr;
  13.    int         records;
  14.    char        buffer[];
  15.    {  int      length, char_wrt; 
  16.       char     eofileb = 0x1A ; 
  17.  
  18.       length = records * db_ptr->rec_len ;
  19.       if( (char_wrt = write(db_ptr->file_ptr,buffer,length )) == length )   /* write successful          */
  20.          db_ptr->curr_rec++ ;                                   /* update the file pointer   */
  21.       if( db_ptr->curr_rec > db_ptr->rec_num ) {
  22.          write(db_ptr->file_ptr,&eofileb,1);                    /* write a new end-of-file    */
  23.          lseek(db_ptr->file_ptr,-1L,1);                         /* and return to position     */
  24.          db_ptr->rec_num = db_ptr->curr_rec ;                   /* update the file descriptor */
  25.          db_ptr->chng_ind = TRUE ;                              /* as necessary               */
  26.       }
  27.       return(char_wrt);
  28.    }
  29.