home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / RANDBLK.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  3.8 KB  |  109 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - randblk.cas
  3.  *
  4.  * function(s)
  5.  *        randbrd - random block read
  6.  *        randbwr - random block write
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*[]------------------------------------------------------------[]*/
  10. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <dos.h>
  22.  
  23. /*-----------------------------------------------------------------------*
  24.  
  25. Name            randbrd - random block read
  26.  
  27. Usage           #include <dos.h>
  28.                 int randbrd(struct fcb *fcbptr, int reccnt);
  29.  
  30. Related
  31. functions usage int randbwr(struct fcb *fcbptr, int reccnt);
  32.  
  33. Prototype in    dos.h
  34.  
  35. Description     randbrd reads reccnt number of records using the
  36.                 open FCB pointed to by fcbptr. The records are read into memory
  37.                 at the current disk transfer address. They are read from the
  38.                 disk record indicated in the random record field of the FCB.
  39.                 This is accomplished by calling DOS system call 0x27.
  40.  
  41.                 randbwr performs essentially the same function as randbrd,
  42.                 except that data is written to disk instead of read from disk.
  43.                 This is accomplished using DOS system call DOS 0x28. If reccnt
  44.                 is 0, the file is truncated to the length indicated by the
  45.                 random record field.
  46.  
  47.                 The actual number of records read or written can be determined
  48.                 by examining the random record field of the FCB. The random
  49.                 record field will be advanced by the number of records actually
  50.                 read or written.
  51.  
  52. Return value    The following values are returned, depending upon
  53.                 the result of the randbrd or randbwr operation:
  54.  
  55.                         0       All records are read or written.
  56.  
  57.                         1       End-of-file is reached and the last record
  58.                                 read is complete.
  59.  
  60.                         2       Reading records would have wrapped around
  61.                                 address 0xFFFF (as many records as possible
  62.                                 are read).
  63.  
  64.                         3       End-of-file is reached with the last record
  65.                                 incomplete.
  66.  
  67.                 randbwr returns 1 if there is not enough disk space to write
  68.                 the records (no records are written).
  69.  
  70. *------------------------------------------------------------------------*/
  71. int randbrd(struct fcb *fcb, int rcnt)
  72. {
  73.     pushDS_
  74. asm    mov    ah, 027h
  75. asm    mov    cx, rcnt
  76. asm    LDS_    dx, fcb
  77. asm    int    021h
  78. asm     cbw
  79.         popDS_
  80.  
  81.         return( _AX );
  82. }
  83.  
  84.  
  85. /*-----------------------------------------------------------------------*
  86.  
  87. Name            randbwr - random block write
  88.  
  89. Usage           #include <dos.h>
  90.                 int randbwr(struct fcb *fcbptr, int reccnt);
  91.  
  92. Prototype in    dos.h
  93.  
  94. Description     see randbrd above
  95.  
  96. *------------------------------------------------------------------------*/
  97. int randbwr(struct fcb *fcb, int rcnt)
  98. {
  99.     pushDS_
  100. asm    mov    ah, 028h
  101. asm    mov    cx, rcnt
  102. asm    LDS_    dx, fcb
  103. asm    int    021h
  104. asm     cbw
  105.     popDS_
  106.  
  107.         return( _AX );
  108. }
  109.