LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Too many files open error

I am using Labwindows 8.1

 

After running several tests in this project I am working on, the program needs to go out and open and read an .ini file. It works fine opening and reading it a few times, but after awhile it fails to open. I look at the errno and it states that "Too many files Open". I went back to the previous tests run before opening the .ini file and I am sure that all other files are closed properly. In the stdio.h, the max file open is set to 255. I don't think there are 255 files open.

 

1. Is there a way to find out how many files are actually open?

2. Is there a way to close all files at once before trying to open the .ini file?

3. What else can I do to figure out what's going on?

 

This is what I am doing:

 

    /* Set up the pathName for the .ini file */
    GetProjectDir (dirName);
    MakePathname (dirName, "vatsplatforms.ini", pathName);

    /* create object for holding the value/tag pairs */
    iniText = Ini_New (TRUE); /* TRUE for automatic sorting */

    /* read in the tag/value pairs */
    error = Ini_ReadFromFile (iniText, pathName);

 

error returned is the errno (which is 24) which translates to "Too many files open"

 

Any help would be greatly appreciated.

 

Thanks!

John W.

 

0 Kudos
Message 1 of 9
(4,881 Views)

Ini_ReadFromFile does not return errno, it returns a user interface error code instead.

The return code is an error only if negative.

 

So, what exactly is the value of 'error' after the function call?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,876 Views)

Thanks for the response

 

Yes, I temporarily changed Ini_ReadFromFile to return the errno.

First I called perror:

perror("Error is");

This resulted on the Standard output: "Error is: Too many files open"

I then put errno into the return variable:

error = errno; result is equal to 24

In errno.h, 24 is equal to "Too many files open"

 

//Modified Ini_ReadFromFile

int CVIFUNC Ini_ReadFromFile(IniText theIniText, const char pathName[])
{
    int         error = UIENoError;
    FILE        *file = NULL;
    LineFile    lineFile = NULL;
    char errorMsg[1000];
 

    if( !theIniText )
        return UIENullPointerPassed;

 

    file = fopen (pathName, "rb");


    if (file == NULL)
   {
     perror(pathName);
     error = errno;
     return (error);
   }

   nullChk (lineFile = LineFile_New(LineFile_ReadFromFile, (void *)file));

   errChk (Ini_ReadGeneric (theIniText, Ini_LineFileInputFunction, (void *)lineFile));

 

   return error;

}

 

The limit for open files is set to 255. I'm pretty certain I don't have that many files open. This is a huge project that I inherited with a lot of opening and closing of files, but it sure looks like all files that are opened are closed.

 

Is there a way to close all files with a single command such as fcloseall()?

Also is there a way to know exactly how many files are open? 

 

Thanks!

John W.

0 Kudos
Message 3 of 9
(4,862 Views)

About how many files are you opening at once? I don't think there is a way to close all files with one command, but I'll double check.

Rohama K.
0 Kudos
Message 4 of 9
(4,837 Views)

That's my problem, I'm almost certain that I am closing all files that I have opened. I am certain that I don't have 255 files opened.

0 Kudos
Message 5 of 9
(4,831 Views)

Have you tried using a counter that increments every time fopen is called and decrements when fclose is called? That could be one way to to track how many files are opened.

Rohama K.
Message 6 of 9
(4,827 Views)

Yes, I think I will try that. Only problem is that this project is huge and there are hundreds of opens and closes. But I'll give it a shot.

 

Thanks
JW

 

0 Kudos
Message 7 of 9
(4,824 Views)

jwinterb, how did you make out with this?  I have a very similar situation that I've not figured out how to solve (see here: http://forums.ni.com/t5/LabWindows-CVI/network-access-to-INI-files/m-p/2478464#M62799).

 

In my case, I am reading and writing INI files located on a mapped network drive.  Ocassionally, I get the "Too many files open" error too.  I have been entertaining the idea of doing all my INI work locally to each computer and then at the end moving the files to the network location.

 

Just curious how you worked through this...

0 Kudos
Message 8 of 9
(4,667 Views)

Hey ElectroLund,

 

It may be worth it to make a new forum post regarding this issue. This post is from about a year ago so many users may ignore it. On that new post, be sure to include how many files you are opening, how your are opening them, how you are determining, and if the the error occurs when you open them locally. 

Kurt P
Automated Test Software R&D
0 Kudos
Message 9 of 9
(4,627 Views)