home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dbase_c.zip / DBREAD.C < prev    next >
Text File  |  1989-03-20  |  2KB  |  31 lines

  1. #include    "libc.h"
  2. #include    "dbase.h"
  3.  
  4. /**************************************************************************
  5. *  db_read reads the next n records from the database at db_ptr into the  *
  6. * buffer.  It returns a read error if it is unsucessful.                  *
  7. **************************************************************************/
  8. db_read(db_ptr,buffer,n)
  9.   DBASE_FILE   *db_ptr ;
  10.   char         buffer[] ;
  11.   int          n ;
  12.   {    int  char_transfered, length ;
  13.        length = n * db_ptr->rec_len ;
  14.        char_transfered = read(db_ptr->file_ptr,buffer,length) ;  /* read n records             */
  15.        if( char_transfered == length){                           /* mark the end of the string */
  16.           buffer[char_transfered] = '\0' ;                       /* if the read is successful  */
  17.           db_ptr->curr_rec++ ;                                   /* update the file pointer    */
  18.           return( char_transfered );
  19.           }
  20.        else {
  21.           if( char_transfered == EOF) {
  22.              buffer[0] = '\0' ;                           /* clear out the buffer              */
  23.              return(EOF);                                 /* read error number                 */
  24.              }
  25.           else {
  26.              buffer[char_transfered] = '\0' ;             /* set the end of the buffer         */
  27.              return( char_transfered/db_ptr->rec_len);    /* return the number of records read */
  28.              }
  29.           }
  30.   }
  31.