Borland C++ reference

randbwr

raw OCR

Writes random block.

Defined in header <dos.h>

Syntax

#include <dos.h>
int randbwr(struct   fcb *fcb, int rent);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

randbwr writes rent number of records to disk using the open file control block (FCB) pointed to by feb. This is accomplished using DOS system call 0x28. If rent is 0, the file is truncated to the length indicated by the random record field.

The actual number of records written can be determined by examining the random record field of the FCB. The random record field is advanced by the number of records actually written.

Return value

The following values are returned, depending upon the result of the randbwr operation:

0 All records are written. 1 There is not enough disk space to write the records (no records are written).

2 Writing records would have wrapped around address 0xFFFF (as many records as possible are written).

See also

Example

#include <process.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
int main(void)
{
   char far *save_dta;
   char line [80];
   char buffer [256] = "RANDBWR test!";
   struct fcb blk;
   int result;

   /* get new file name  from user */
   printf( "Enter a file name to create (no path - ie. a:file'.dat\n");
   gets(line);

   /* parse the new file name  to the dta */
   parsfnm(line,&blk;, 1);
   printf( "Drive #%d File:  %s\n", blk.fcb_drive, bl]<;.fcb_name);

   /* request DOS services to  create file */
   if (bdosptr(0xl6, &bllc, 0) == -1) {
      perror("Error creating  file");
      exit(l);
   }
   /* save old dta and set new  dta */
   save_dta = getdtaO;
   setdta(buffer);

   /* write new records */
   bllc.fcb_recsize = 256;
   bl]<;.fcb_random = 0L;
   result = randbwr (&bll<;, 1);

   if (Iresult)
      printf("Write OK\n");
   else {
      perror("Dislc error");
      exit(l);
   }
   /* request DOS services to  close the file */
   if (bdosptr(OxlO, &bl]*, 0) -= -1) {
      perror("Error closing  file");
      exit(l);
}
/* reset the old dta */
setdta(save_dta);
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.