home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / streams / handles / code.doc < prev    next >
Encoding:
Text File  |  1992-02-16  |  2.4 KB  |  92 lines

  1.  
  2. This information is included for interest. It works, but the code in
  3. "close.c" is more universal.
  4.  
  5. ---------------------------------------------------------------------
  6.  
  7. Here is some alternative code for the 
  8.            void    increase_handles(void)
  9.   function:
  10.  
  11.  
  12. ----------------- code for small-data models ------------------------
  13.  
  14. /* We use assembler here to get access to the byte swap instruction
  15.    and to make the access to DOS functions cleaner.
  16.    It also saves some bytes and a few microseconds...
  17.  */
  18.  
  19. /* WARNING: This code will prevent the subsequent use of far-data
  20.    memory allocation, e.g. by farmalloc() etc.
  21.  */
  22.  
  23. asm    {
  24.     mov    ah, 0x30    /* Get the DOS version. */
  25.     int    0x21
  26.     xchg    al, ah        /* Swap the byte order */
  27.                 /* to allow easy comparison. */
  28.     cmp    ax, 0x0303
  29.     jb    done        /* Exit if the DOS version is not
  30.                    at least 3.3 */
  31.  
  32.     mov    ax, 0x6700    /* Increase the size of the handle table */
  33.     mov    bx, MAX_FD    /* to this value. */
  34.     int    0x21
  35.     jnc    done        /* Exit if no errors */
  36.     }
  37.  
  38.         {
  39.         /* Whoops! we should never get here! */
  40.         printf("DOS error %d for service 0x67\n", _AX);
  41.         exit(1);
  42.         }
  43.  
  44. done:    ;
  45.  
  46.  
  47.  
  48.  
  49. ------------------ Code for large-data models ------------------
  50.  
  51. /* Unfortunately, the Turbo C large data models handle memory
  52.    allocation differently and the memory fragmentation caused
  53.    by the DOS service 0x67 call above will cause malloc() etc
  54.    to fail!
  55.    So, for the large data models, we take care of the nitty-
  56.    gritty details ourselves...
  57.  */
  58.  
  59.   
  60. #if MAX_FD <= 20
  61. #error "MAX_FD must be > 20"
  62. #endif
  63.  
  64. #if !defined(__COMPACT__) && !defined(__LARGE__) && !defined(__HUGE__)
  65. #error "This code will cause crashes with small-data models"
  66. #endif
  67.  
  68. char    *newblock;
  69.  
  70. /* Get space for the file_table from the Turbo C allocation scheme. */
  71. if ( (newblock = malloc(MAX_FD+15)) == NULL )
  72.     abort();
  73.  
  74. /* Start on a paragraph */
  75. newblock = MK_FP(FP_SEG(newblock)+1, FP_OFF(newblock) & 0xfff0);
  76.  
  77. memcpy(newblock, MK_FP(_psp, 0x18), 20);    /* Copy the existing table. */
  78. memset(newblock+20, 0xff, MAX_FD-20);    /* Make the extra entries invalid. */
  79. *((long far *)MK_FP(_psp, 0x34)) = (long)newblock;    /* Point to the table. */
  80. *((int far *)MK_FP(_psp, 0x32)) = MAX_FD;    /* Set its size. */
  81.  
  82.  
  83. ------------------------------------------------------------------------------
  84.  
  85.  
  86.  
  87. -------------
  88. 16th feb 1992
  89.  
  90. W. Metzenthen
  91. apm233m@vaxc.cc.monash.edu.au
  92.