🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5575

Re: How to change Number of Open Files

#5575
From: Dwayne Bailey
Date: Tue, 02 Apr 1991 14:24
98 lines
4637 bytes
In article <1991Mar31.011139.8147@news.arc.nasa.gov> chu@pioneer.arc.nasa.gov (Susie Chu RCS) writes:
>Can someone tell me how to change the number of files that can 
>be open simutaaneously?
>My system is runing MSDOS 4.1 and I am using Turbo C 2.0.
>I have a program that needs to open more than 20 files. I
>have tried to
>(1) in config.sys, change FILES=35
>(2) in Turbo C 2.0 include/stdio.h, change
>    #define OPEN_MAX  35
>    #define SYS_OPEN 355
>(3) in Turbo C 2.0 include/dos.h, change
>    #define NFDS 35
>It doesn't help.  I still failed in openning 21st file.  I suspect
>it is in the libc.  But I don't know how to check and modify it.
>
>If you do know, please tell me.  I will appreciate very much.
>Thanks in advance.
>---Susie Chu
>

Two things are probably biting you.  One is that MS-DOS gives each and
every process EXACTLY 20 file handles at startup, no matter what is in
CONFIG.SYS.  The FILES= line controls the TOTAL number of files open, not
the number of files for one process.  Thus, your TSRs can have files open
without interfering with the 20 file handles of your main program.

The other problem is that thos #defines you changed had very little effect,
if any.  They tell your program the size of some external arrays.  You lied
to your program about those arrays, BUT YOU DIDN'T ACTUALLY CHANGE THEIR
SIZE!  To do that, you would need access to the source code for the Runtime
Library, and recompile with your changes.

There are workarounds.  The DOS limit is easy, since you are using 4.0
This code will only work in DOS 3.3 and higher.

/* Routine to set the maximum handles allowed to other than 20 */
/* Returns 0 on success, DOS Error number on failure */

int SetHandleLimit(int MaxHandles)
{
	int Result = 0;

	asm
		{
		mov	ah,67h	; This might need to be 0x67.  I can't
				; remember which style HEX number TC
				; wants here.
		mov	bx,MaxHandles
		int	21h	; Ditto the above comment

		jnc	NoError

		mov	Result,ax
NoError:
		}

	return Result;
}

Add a line like "SetHandleLimit(25);" to increase the limit to 35.  The only
reason this should fail is if there is not enough memory for DOS to allocate
a 35 byte table for the new handles.

BTW, this can be dome is versions of DOS below 3.3, but it's ugly.  There is
no function to do it for you.  You have to allocate the table youself, then
set the far pointer to the table in you PSP at offset 34h.  The word at
32h must also be set to the number of entries on the new table.

Now for Turbo C:
If you don't need stream IO (FILE * type files), then
you can get around the Runtime library by using just the low-level calls.
I would use _dos_open() to open the files, rather than open(), just to be
sure you are at a low enough level to get past the runtime library.

If you DO need stream IO, you might be able to do the same thing.  You would
just need some extra steps.  Be warned, this paragraph is total conjecture
on my part.  I have not tried is, and make no warranties, expressed or
implied!  That said, the following MIGHT work:
	1.  Open the file(s) using _dos_open().
	2.  Use fdopen() to associate the file handle with a stream.
	3.  Process the file as before.
	4.  Close the file.
This doesn't give you more than 20 streams at one time, but as long as you
aren't swapping back and forth between files TOO much, the performance hit
shouldn't be too bad.  You could also try using a call to dup() to make a
copy of the file handle after set 1.  That way, the close in step 4 will not
close the file completely, just remove its association with the stream 
pointer.  If this works, I suspect it will meet your needs the best.
However, I still recomment that, if at all possible, use only low level
calls, and avoid a ton of headaches.  Or buy the Runtime Library source.
The money spent will most likely be saved in time and aggravation!

========================================================================
..!uunet!basfpac!stratsft!dwayne

Dwayne Bailey      +  Strategic Software is ME, so my opinions ARE those
Strategic Software +  of my company!
========================================================================
Technical Details
Message-ID: <130@stratsft.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!basfpac!stratsft!dwayne
References: <1991Mar31.011139.8147@news.arc.nasa.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!basfpac!stratsft!dwayne
From: dwayne@stratsft.UUCP (Dwayne Bailey)
Newsgroups: comp.os.msdos.programmer
Subject: Re: How to change Number of Open Files
Message-ID: <130@stratsft.UUCP>
Date: 2 Apr 91 14:24:28 GMT
References: <1991Mar31.011139.8147@news.arc.nasa.gov>
Organization: Strategic Software, Allen Park, MI
Lines: 98