Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > FOPEN_MAX minimum value

Reply
Thread Tools

FOPEN_MAX minimum value

 
 
Bas Wassink
Guest
Posts: n/a
 
      09-04-2005
Hi there,

I was wondering what the standard (C89) states what the minimum value of
FOPEN_MAX should be? K&R just state that FOPEN_MAX is
implementation-defined and when googling for an answer I found that GNU's
libc defines FOPEN_MAX to be at least 8, including stdin, stdout and
stderr.
Does GNU's definition reflect the standard, or is it their
implementation of the standard?


 
Reply With Quote
 
 
 
 
P.J. Plauger
Guest
Posts: n/a
 
      09-04-2005
"Bas Wassink" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...

> I was wondering what the standard (C89) states what the minimum value of
> FOPEN_MAX should be? K&R just state that FOPEN_MAX is
> implementation-defined and when googling for an answer I found that GNU's
> libc defines FOPEN_MAX to be at least 8, including stdin, stdout and
> stderr.
> Does GNU's definition reflect the standard, or is it their
> implementation of the standard?


It's still 8 in C99, including the three standard streams.
Many implementations I know make this value considerably larger,
however.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


 
Reply With Quote
 
 
 
 
Roger Leigh
Guest
Posts: n/a
 
      09-04-2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bas Wassink <(E-Mail Removed)> writes:

> I was wondering what the standard (C89) states what the minimum
> value of FOPEN_MAX should be?


[C99, ยง7.19.3#15] "The value of FOPEN_MAX shall be at least eight,
including the three standard text streams."

> K&R just state that FOPEN_MAX is implementation-defined and when
> googling for an answer I found that GNU's libc defines FOPEN_MAX to
> be at least 8, including stdin, stdout and stderr. Does GNU's
> definition reflect the standard, or is it their implementation of
> the standard?


Both.

[Using GNU libc 2.3.5]

$ rgrep FOPEN_MAX /usr/include
/usr/include/bits/stdio_lim.h:#if defined __need_FOPEN_MAX || defined _STDIO_H
/usr/include/bits/stdio_lim.h:# undef FOPEN_MAX
/usr/include/bits/stdio_lim.h:# define FOPEN_MAX 16
/usr/include/stdio.h: FOPEN_MAX Minimum number of files that can be open at once.

So the *minimum* is 16 with my version. The actual maximum depends on
the system configuration. On a typical GNU/Linux system this will be
unlimited, but may be limited using RLIMIT_NOFILE; see getrlimit(2)
and setrlimit(2) (but this is standardised by POSIX/SUS, not C).


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFDGyaWVcFcaSW/uEgRAmTrAJ4n2rZoXGbuSgYp7t+qZ3dWEihXxQCg7IQ4
C+rylg27sgPjeeYedwuXme0=
=iu90
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      09-05-2005
Bas Wassink wrote:
>
> I was wondering what the standard (C89) states what the minimum value
> of FOPEN_MAX should be?


Yes, 8, but I'm curious as to why you care?

Either a file is going to open or it isn't. Are you thinking of
writing code that's going to stop opening files when it hits
FOPEN_MAX open streams? If so, why?

--
Peter

 
Reply With Quote
 
Bas Wassink
Guest
Posts: n/a
 
      09-05-2005
On Sun, 04 Sep 2005 22:54:22 -0700, Peter Nilsson wrote:

> Bas Wassink wrote:
>>
>> I was wondering what the standard (C89) states what the minimum value
>> of FOPEN_MAX should be?

>
> Yes, 8, but I'm curious as to why you care?
>
> Either a file is going to open or it isn't. Are you thinking of
> writing code that's going to stop opening files when it hits
> FOPEN_MAX open streams? If so, why?


I'm writing a cross-assembler for 65xx-based systems. The parser should
support #include statements, but since the minimum value of FOPEN_MAX is
way too little (even my C64 can do better), I'll have to rewrite my code.

Right now, my code just opens a new file when hitting an #include
statement. I'm going to have to change that so it'll store the position in
the current file, close it, open the new file, parse it (maybe hitting
another #include), close it, reopen the previous file, restore the
position in the file and continue parsing.

Hopefully this clarifies my reasons for wanting to know...


 
Reply With Quote
 
P.J. Plauger
Guest
Posts: n/a
 
      09-05-2005
"Bas Wassink" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...

> On Sun, 04 Sep 2005 22:54:22 -0700, Peter Nilsson wrote:
>
>> Bas Wassink wrote:
>>>
>>> I was wondering what the standard (C89) states what the minimum value
>>> of FOPEN_MAX should be?

>>
>> Yes, 8, but I'm curious as to why you care?
>>
>> Either a file is going to open or it isn't. Are you thinking of
>> writing code that's going to stop opening files when it hits
>> FOPEN_MAX open streams? If so, why?

>
> I'm writing a cross-assembler for 65xx-based systems. The parser should
> support #include statements, but since the minimum value of FOPEN_MAX is
> way too little (even my C64 can do better), I'll have to rewrite my code.
>
> Right now, my code just opens a new file when hitting an #include
> statement. I'm going to have to change that so it'll store the position in
> the current file, close it, open the new file, parse it (maybe hitting
> another #include), close it, reopen the previous file, restore the
> position in the file and continue parsing.
>
> Hopefully this clarifies my reasons for wanting to know...


And it's a good reason. We had to do the same thing to the Whitesmiths
C compiler twenty years ago, once X3J11 settled on this small minimum
maximum for FOPEN_MAX.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FOPEN_MAX , SYS_OPEN ravi C Programming 6 08-08-2010 07:53 PM
stl map: get the <key,value> pair which has the minimum value Rui Maciel C++ 2 12-01-2009 11:21 PM
strange outcome when comparing int value against a give minimum and maximum value Pugi! Javascript 2 02-12-2007 09:10 PM
finding the minimum value of a set of data Porthos XML 4 01-31-2005 04:48 PM
Comparator and minimum value address sunil VHDL 4 02-22-2004 08:10 PM



Advertisments