TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Paul Edwards
from: Jonathan de Boyne Pollard
date: 1996-11-01 02:45:36
subject: file handles

PE>
  > I have a new theory.  The theory is that the MSC CRT has a fixed array of 2
  > FILE's.  Now instead of doing as I would have expected, ie
  > store the file number as one of the elements of the FILE
  > structure, and not have any restriction on the number
  > itself, e.g. 5975, what it is doing is getting the file
  > number from DosOpen, e.g. 7, and then going to the 7th
  > element of the array, and storing it there!
PE>

  If it's anything like Borland's RTL, there are *two* tables.

  The first table is a table of file descriptor flags, as used by the
  open(), read(), write(), close() library calls, which is indexed by the
  OS/2 file number returned by DosOpen().

  The second table is a table of FILE structures, as used by the fopen()
  and related functions, each of which has a `fileno' field that is an
  OS/2 file handle and an index into the first table.

  In Borland C++, when you fopen() a file, it calls open() internally to
  get a file descriptor, and allocates the first free FILE structure.  If
  a FILE structure cannot be allocated because the second table is full,
  close() is called to close the file descriptor, and the fopen() call
  fails.

  The open() call in turn calls DosOpen() and checks that the returned
  file descriptor is smaller than the size of the first table.  If it is
  too large, then DosClose() is called and open() returns -1.  If it is a
  valid table index, then open() returns it as the file descriptor.

  This means that you can

    1. Change the per-process OS/2 file handle table with DosSetRelMaxFH.

       This will allow you to DosOpen more files, but since the table used
       by open() is a fixed size, you cannot open() or fopen() more files.
       Even if the DosOpen succeeds, open() won't have enough table space
       and will immediately DosClose the file handle.

    2. Change the size of the _openfd[] table, as well.

       This will allow you to open() more files, but since the table ysed
       by fopen() is a fixed size, you cannot fopen() more files.  Even if
       the open() succeeds, fopen() won't have enough table space and will
       immediately close() the file descriptor.

    3. Change the size of the _streams[] table, as well as that.

       This will allow you to fopen() more files.

  > JdeBP <
___
 X MegaMail 2.10 #0:
--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)
SEEN-BY: 50/99 270/101 620/243 625/160 711/401 409 410 413 430 808 809 934
SEEN-BY: 711/955 712/407 515 624 628 713/317 800/1
@PATH: 440/4 141/209 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.