FOPEN_MAX minimum value

Discussion in 'C Programming' started by Bas Wassink, Sep 4, 2005.

  1. Bas Wassink

    Bas Wassink Guest

    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?
     
    Bas Wassink, Sep 4, 2005
    #1
    1. Advertising

  2. Bas Wassink

    P.J. Plauger Guest

    "Bas Wassink" <> wrote in message
    news:p...

    > 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
     
    P.J. Plauger, Sep 4, 2005
    #2
    1. Advertising

  3. Bas Wassink

    Roger Leigh Guest

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

    Bas Wassink <> 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-----
     
    Roger Leigh, Sep 4, 2005
    #3
  4. 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
     
    Peter Nilsson, Sep 5, 2005
    #4
  5. Bas Wassink

    Bas Wassink Guest

    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...
     
    Bas Wassink, Sep 5, 2005
    #5
  6. Bas Wassink

    P.J. Plauger Guest

    "Bas Wassink" <> wrote in message
    news:p...

    > 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
     
    P.J. Plauger, Sep 5, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil
    Replies:
    4
    Views:
    826
    Ralf Hildebrandt
    Feb 22, 2004
  2. Porthos
    Replies:
    4
    Views:
    619
  3. Rui Maciel
    Replies:
    2
    Views:
    3,258
    AndrewDover
    Dec 1, 2009
  4. ravi

    FOPEN_MAX , SYS_OPEN

    ravi, Aug 7, 2010, in forum: C Programming
    Replies:
    6
    Views:
    757
    John Kelly
    Aug 8, 2010
  5. Pugi!
    Replies:
    2
    Views:
    117
    Steve
    Feb 12, 2007
Loading...

Share This Page