FOPEN_MAX minimum value

B

Bas Wassink

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?
 
P

P.J. Plauger

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
 
R

Roger Leigh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bas Wassink said:
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-----
 
P

Peter Nilsson

Bas said:
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?
 
B

Bas Wassink

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...
 
P

P.J. Plauger

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top