Set disk transfer area address

From , 2 Years ago, written in C, viewed 203 times.
URL https://pastebin.vip/view/ffedf5be
  1. #include <process.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <dos.h>
  5.  
  6. int main(void)
  7. {
  8.    char line[80], far *save_dta;
  9.    char buffer[256] = "SETDTA test!";
  10.    struct fcb blk;
  11.    int result;
  12.  
  13.    /* get new file name from user */
  14.    printf("Enter a file name to create:");
  15.    gets(line);
  16.  
  17.    /* parse the new file name to the dta */
  18.    parsfnm(line, &blk, 1);
  19.    printf("%d %s\n", blk.fcb_drive, blk.fcb_name);
  20.  
  21.    /* request DOS services to create file */
  22.    if (bdosptr(0x16, &blk, 0) == -1)
  23.    {
  24.       perror("Error creating file");
  25.       exit(1);
  26.    }
  27.  
  28.    /* save old dta and set new dta */
  29.    save_dta = getdta();
  30.    setdta(buffer);
  31.  
  32.    /* write new records */
  33.    blk.fcb_recsize = 256;
  34.    blk.fcb_random = 0L;
  35.    result = randbwr(&blk, 1);
  36.    printf("result = %d\n", result);
  37.  
  38.    if (!result)
  39.       printf("Write OK\n");
  40.    else
  41.    {
  42.       perror("Disk error");
  43.       exit(1);
  44.    }
  45.  
  46.    /* request DOS services to close the file */
  47.    if (bdosptr(0x10, &blk, 0) == -1)
  48.    {
  49.       perror("Error closing file");
  50.       exit(1);
  51.    }
  52.  
  53.    /* reset the old dta */
  54.    setdta(save_dta);
  55.    return 0;
  56. }

Reply to "Set disk transfer area address"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website