home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP24.EXE / CHP2417.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  887 b   |  40 lines

  1. /*
  2.    Listing 24.17  Buffered read/write
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. #define BUFFER_SIZE  4096
  14.  
  15. STATIC buffer :=""
  16.  
  17. function bread(nHandle,nBytes)
  18. LOCAL tmp
  19. if nBytes > len(buffer)
  20.    tmp := buffer
  21.    buffer := space(BUFFER_SIZE)
  22.    fread(nHandle,@buffer,BUFFER_SIZE)
  23.    buffer := tmp+buffer
  24. endif
  25. tmp := substr(buffer,1,nBytes)
  26. buffer := substr(buffer,nBytes+1,BUFFER_SIZE)
  27. return tmp
  28.  
  29.  
  30. function bwrite(nHandle,cString)
  31. LOCAL x:=.T.
  32. buffer := buffer+cString
  33. if len(buffer) >= BUFFER_SIZE
  34.    x := (fwrite(nHandle,buffer)=len(buffer))
  35.    buffer:=""
  36. endif
  37. return x
  38.  
  39. // end of file CHP2417.PRG
  40.