🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1064

Re: detect how many files are open

#1064
From: Ed Mulroy [TeamB]
Date: Sat, 17 Nov 2007 13:27
46 lines
2211 bytes
For FILE* style files you might try something like this:

----------------------
#include <stdio.h>

#ifdef __cplusplus
using std::FILE;
using std::_streams;
#endif

int NumFilesOpen()
    {
    FILE *fp = &_streams[0];
    int num_open = 0;

    for (int i = 0; i < _NFILE_; ++i, ++fp)
        if (fp->fd != -1)
            ++num_open;

    return num_open;
    }
----------------------

Just remember that three files are going to be open at all times, stdin, 
stdout and stdprn.

.  Ed

> Josef Halder wrote in message
> news:473eca61$1@newsgroups.borland.com...
> Hi,
>
> is there a way to detect how many files are open at the moment?
> My problem is when the program is running two weeks or longer without
> restart then comes a point after that is not longer possible to open (to
> read or to write) a file. After that point any attempt to open a file,
> generates an error.
> I belive there is a situation a file is not closed. But the program is 
> very
> complex so it's difficult to find out.
>
> Example:
> At various times during the program is running I open files with   FILE *f 
> =
> fopen("Filename.TXT","rt");
> I read/write and after that I close with    fclose(f);
Technical Details
Message-ID: <473eec3e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <473eca61$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,da0bfab45ef29be4
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <473eca61$1@newsgroups.borland.com>
Subject: Re: detect how many files are open
Date: Sat, 17 Nov 2007 08:27:23 -0500
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 71.77.53.190
Message-ID: <473eec3e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1195306046 71.77.53.190 (17 Nov 2007 05:27:26 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail