home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / c_all592.arj / TI870.ASC < prev   
Text File  |  1992-04-20  |  6KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  870
  9.   VERSION  :  3.0
  10.        OS  :  DOS
  11.      DATE  :  April 20, 1992                           PAGE  :  1/3
  12.  
  13.     TITLE  :  Increasing The Number Of Available File Handles
  14.  
  15.  
  16.  
  17.  
  18.   QUESTION:
  19.        How do I increase the number of FILES available to my
  20.        program under Borland C++ 3.0?
  21.  
  22.  
  23.   ANSWER:
  24.        Increasing the number of FILES available to a program in
  25.        Borland C++ involves changing 3 FILES from the RTL (Run-Time
  26.        Library):  _NFILE.H, files.C, and FILES2.C.  The only change
  27.        you actually need to make is in _NFILE.H, where you redefine
  28.        the macro _NFILE_.  The FILES files.C and FILES2.C just need
  29.        to be recompiled to reflect the changes to this macro.
  30.        Assigning a value to this macro will set the maximum number
  31.        of FILES available to your program including the 5 standard
  32.        FILES ( stdin, stdout, stderr, stdaux, stdprn ).
  33.  
  34.        The changes can be made in two different ways.  One, you can
  35.        simply recompile files.C and FILES2.C in the appropriate
  36.        memory model and link them in with your program.  In the
  37.        IDE, this means adding the two .C FILES to your project.  On
  38.        the command line, this means adding them to your BCC line.
  39.  
  40.        For example:
  41.             BCC myprog.c FILES.c files2.c
  42.  
  43.        The effect of this will be that you redefine the symbols in
  44.        the two FILES which have been previously defined in the
  45.        standard libraries, and precedence will go to yours.  You
  46.        can ignore the warnings you will get from the linker if you
  47.        have the Warn Duplicate Symbols option set (/d).
  48.  
  49.        The other way is to replace the files.C and FILES2.C in the
  50.        standard library with your own.  The advantage of doing this
  51.        is if you always want to have access to more than 20 FILES
  52.        in your programs, you will not always have to add those two
  53.        FILES to your project.  You can replace them by first
  54.        recompiling the FILES using BCC like this:
  55.  
  56.             BCC -c -mX FILES.c files2.c
  57.  
  58.        where the X in -mX refers to the memory model of the library
  59.        you want to replace them in ( you will have to do this
  60.        repeatedly if you want to replace all the memory models ).
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  870
  75.   VERSION  :  3.0
  76.        OS  :  DOS
  77.      DATE  :  April 20, 1992                           PAGE  :  2/3
  78.  
  79.     TITLE  :  Increasing The Number Of Available File Handles
  80.  
  81.  
  82.  
  83.  
  84.        This will result in files.OBJ and FILES2.OBJ which you can
  85.        then add to the appropriate library in the LIB directory
  86.        using TLIB.  For the large model it would look like this:
  87.  
  88.             TLIB ml.lib +-files.obj +-files2.obj
  89.  
  90.        Below is the source for the three FILES you need to replace,
  91.        if you do not already have the RTL for Borland C++ 3.0 ( in
  92.        your \BORLANDC\CLIB dir ).  If you choose to add the FILES
  93.        directly to your program, you can merge them into one FILE
  94.        if you choose.  It is not required that the variables be
  95.        defined in separate FILES, this is just how it is done in
  96.        the RTL.
  97.  
  98.        One final note is that if you want this to be extended to
  99.        Windows programs, you will have to add a call to the Windows
  100.        API funciton SetHandleCount to tell Windows that your
  101.        program needs more FILE HANDLES.
  102.  
  103.  
  104.   SOURCE:
  105.        // _NFILE.H
  106.        // Copyright (C) 1992 Borland International, Inc.
  107.        // All Rights Reserved
  108.  
  109.        // Maximum number of open FILES
  110.        #define _NFILE_ 20
  111.        //..........................................................
  112.  
  113.  
  114.        // FILES.C
  115.        // Copyright (C) 1992 Borland International, Inc.
  116.        // All Rights Reserved
  117.  
  118.        #include <stdio.h>
  119.        #include <_nfile.h>
  120.  
  121.        #define _F_STDIN    (_F_READ | _F_TERM | _F_LBUF)
  122.        #define _F_STDOUT   (_F_WRIT | _F_TERM | _F_LBUF)
  123.        #define _F_STDERR   (_F_WRIT | _F_TERM)
  124.        #define _F_STDAUX   (_F_RDWR | _F_TERM | _F_BIN)
  125.        #define _F_STDPRN   (_F_WRIT | _F_TERM | _F_BIN)
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  870
  141.   VERSION  :  3.0
  142.        OS  :  DOS
  143.      DATE  :  April 20, 1992                           PAGE  :  3/3
  144.  
  145.     TITLE  :  Increasing The Number Of Available File Handles
  146.  
  147.  
  148.  
  149.  
  150.        #if !defined( _RTLDLL )
  151.  
  152.        file _streams [_NFILE_] =
  153.        {
  154.            {0, _F_STDIN,  0, 0, 0, NULL, NULL, 0, (short) stdin},
  155.            {0, _F_STDOUT, 1, 0, 0, NULL, NULL, 0, (short) stdout},
  156.            {0, _F_STDERR, 2, 0, 0, NULL, NULL, 0, (short) stderr},
  157.            {0, _F_STDAUX, 3, 0, 0, NULL, NULL, 0, (short) stdaux},
  158.            {0, _F_STDPRN, 4, 0, 0, NULL, NULL, 0, (short) stdprn}
  159.        };
  160.  
  161.        #endif  // _RTLDLL
  162.        //..........................................................
  163.  
  164.  
  165.        // FILES2.C
  166.        // Copyright (C) 1992 Borland International, Inc.
  167.        // All Rights Reserved
  168.  
  169.        #include <io.h>
  170.        #include <fcntl.h>
  171.        #include <_nfile.h>
  172.  
  173.        unsigned _nfile = _NFILE_;
  174.  
  175.        unsigned int _openfd[_NFILE_] =
  176.        {
  177.             O_RDONLY | O_DEVICE | O_TEXT,
  178.             O_WRONLY | O_DEVICE | O_TEXT,
  179.             O_WRONLY | O_DEVICE | O_TEXT,
  180.             O_RDWR   | O_DEVICE | O_BINARY,
  181.             O_WRONLY | O_DEVICE | O_BINARY
  182.        };
  183.        //..........................................................
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.