• Please review our updated Terms and Rules here

TurboC v2.01 - how many files open concurrently?

pgb

New Member
Joined
Aug 13, 2009
Messages
1
Location
Peterborough UK
Greetings

I'm trying to resolve a little puzzle with Borland TurboC 2.01 - how many files can a program have open at the same time?

I have the Reference Guide and User's Guide (books); if the answer's in either of these it must be hiding very well (!)

Looking in <stdio.h> I find
/* Number of files that can be open simultaneously
*/
#define OPEN_MAX 20 /* Total of 20 open files */
#define SYS_OPEN 20
which all seems quite clear... the only problem being, that it doesn't behave like that! Trying it out "for real" I get errors after 15 successful file opens (the 16th attempt gives the error).

Have tried using open() and tried using fopen() - same behaviour in each case.

(testing in various environments including "pure" DOS 6.22)

so, I've looked to the DOS environment and set files=20, fcbs=20, set all sorts of things which I thought might have a bearing - still can only have 15 files open before getting errors.

I tried "tweaking" the value in <stdio.h> to see whether that would make a difference - it didn't. Which makes me suspect that the limitation is coming from somewhere else...

What am I missing?

TIA, Peter.
 
Interesting. Sounds like you're doing things correctly. Did you set files= in the config.sys or just the environment? I imagine Microsoft being Microsoft they love to have things set up front vs live.

Could it also be including other files open at the time? i.e 20 files total, and it has x and y open but TSR'd as well as the TurboC gui and maybe some linked files?

Try setting it to 30 and see if you get past your 15 limit.

- John
 
Disclaimer: I own Borland C++ 2.0, but I don't use it.

I think you're misunderstanding the purpose of the #define in stdio.h (and the corresponding HANDLE_MAX in io.h).

The #defines are telling you what the runtime is compiled to support--you're not telling the runtime how many open files it has to support.

In other words, there are some fixed-sized tables in the C runtime and you're stuck with them, unless you want to recompile the runtime library. To their credit, Borland did make this available.

At least, that's my take.

Edit: If you're accessing the files in binary mode, you can bypass the runtime limitations by directly issuing your own MS-DOS calls to manipulate the files. Microsoft C allowed this with their dos.h interface (e.g. _dos_open(), _dos_read, etc.).
 
Last edited:
Set files=x in config.sys

Set files=x in config.sys

I used to use this version of turbo c lots at one time, and from memory I'm sure you have to set files= in config.sys.

Setting fcbs= should have no effect, as i'm pretty sure turbo c doesn't use them, since files= was introduced in Dos 2.0, virtually no applications used fcbs.

So in summary try setting files=20 in you config.sys and see if you can now open 20 files. You may find, btw, I'm not sure, that if you are running your compiled program from within turbo c, it may use up some of the open files, and therefor you need to factor this in as well.
 
So in summary try setting files=20 in you config.sys and see if you can now open 20 files. You may find, btw, I'm not sure, that if you are running your compiled program from within turbo c, it may use up some of the open files, and therefor you need to factor this in as well.

pgb said:
...so, I've looked to the DOS environment and set files=20, fcbs=20, set all sorts of things which I thought might have a bearing - still can only have 15 files open before getting errors.

The limitation isn't in DOS, but rather the Turbo runtime.
 
so, I've looked to the DOS environment and set files=20, fcbs=20, set all sorts of things which I thought might have a bearing - still can only have 15 files open before getting errors.

There are already 5 files open when your program starts (stdin, stdout, stderr, stdaux and stdprn).
 
Back
Top