This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Limit on number of fopen in CCS?

Other Parts Discussed in Thread: CCSTUDIO

Hi,

Is there a maximum limit on number of fopen, in CCS?
I am using CCS3.2 with CG Tools version 6.0.15. I found that I cannot have more than 7 files open at a time.
The 8th fopen returns a NULL handle. I have verified that it does not depend on the files and their opening mode (read and/or write).

Is there any fix to this?
Is this a known problem? If so, what is the reason?

Regards,
Akshatha

  • This is a limit of the run time support (RTS) library, or rather a limit of the default settings of the run time support library such as to make the library more compact/efficient than it would be if there was a larger limit on the number of files you can open.

    You can adjust this by modifying some header files and recompiling the run time support library. Within stdio.h the value of _NFILE which provides the value of FOPEN_MAX will determine the number of files it will allow to be opened. The default value of _NFILE is set to 10, however since stdout, stdin, and stderr take up a file each that leaves you with the 7 possible open files you are seeing. In addition to _NFILE you must also increase the value of _NSTREAM within file.h as this is used by the open() call underneath the fopen() call. Both of these header files can be found in your code generation tools directory (i.e. something like c:/ccstudio_v3.3/c6000/cgtools/include). Rebuilding the library can be done with the mk6x utility included with the code generation tools, in particular a command like 'mk6x rts.src -l rts.lib' should rebuild it with default options.

  • Hi Bernie,

     

    one of our customers needs to open 8 files :-) and we learnt from some support teams that we could possible do a fclose() for stderr and stdin etc and that could spare more file handles. 

    Given a possibility like that, we did not want to get into maintaining a new RTS library. i tried that but it did not work. Is "fclose(stderr)" kind of usage supposed to work in CCS?

     

    i am using Codegen version v4.6.3 with CortexM3 sim

    thanks,

    vishal

  • Vishal Goel said:
    i tried that but it did not work. Is "fclose(stderr)" kind of usage supposed to work in CCS?

    I am not sure, I have only used and recommended modifying the RTS, since it is such a simple one line change, and you normally want to have the other i/o available for debug.

    You may want to ask this question over in the compiler forum, I believe the RTS falls under their jurisdiction so they could probably give you a better idea of if it should work and why it might not.

    My opinion is that you simply cannot close the stderr, stdin, or stdout, looking at the RTS source it seems like these are defined statically with #define statements, not to mention that various RTS functions use them and may fail if they are no longer available. I am sure you could get rid of them, but you might have to modify the RTS to allow them to not exist which negates the purpose of trying to close them in the first place. On the other hand I have only used the C6000 RTS, so I am not familiar with the CortexM3 tool set, so there may be something in there that is different. At least this is my 5 minute analysis of looking at the RTS regarding this, the compiler folks in the other forum can probably give you a better answer.

  • The best option is to change _NFILE in stdio.h and rebuild the RTS.  Details on rebuilding the RTS are in the section titled "Library Build Process" in the compiler book http://www.ti.com/lit/pdf/spru187 .

    Thanks and regards,

    -George