Mail Archives: djgpp/2000/01/05/16:42:55
On Wed, 5 Jan 2000 11:19:40 +0200 (IST),
Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>
>On Tue, 4 Jan 2000, Mike Demoulin wrote:
>
>> In g++, I have used stat (), __file_exists (), and ifstream ().good ().
>> All of these can return false negatives under NT. What am I doing wrong?
>
>I have never heard about `stat' and `__file_exists' returning false
>negatives, in any environment. Please post the details (a short
>program and the directory listing by DIR would be nice).
Here is the directory listing:
C:\FT>dir C:\FT\FT4WIN\FTCOMINTEGRATED.OCX.ZIP
Volume in drive C has no label.
Volume Serial Number is F4DE-6D7B
Directory of C:\FT\FT4WIN
12/28/99 07:15p 58,134 FTCOMINTEGRATED.OCX.ZIP
1 File(s) 58,134 bytes
326,311,936 bytes free
Here is the test program:
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void TestFileExists (const string &file) {
cout << "Testing for \"" << file << "\"" << endl;
struct stat buff;
if (__file_exists (file.c_str ()))
cout << "__file_exists () found the file" << endl;
else
cout << "__file_exists () found the file" << endl;
if (!stat (file.c_str (), &buff))
cout << "stat () found the file" << endl;
else
perror ("stat () did not find the file");
if (ifstream (file.c_str (), ios::nocreate).good ())
cout << "ifstream found the file" << endl;
else
cout << "ifstream did not found the file" << endl;
}
int main (int, char *argv []) {
TestFileExists (argv [1]);
return 0;
}
Here are the results:
Testing for "C:\FT\FT4WIN\FTCOMINTEGRATED.OCX.ZIP"
__file_exists () found the file
stat () did not find the file: No such file or directory (ENOENT)
ifstream did not found the file
This time, __file_exists worked, but there have been times that it didn't.
>What version of DJGPP are you using, btw?
djdev202.
A few more details. I develope on a W95 machine, but this program is sent
to users who don't have DJGPP installed. The program run above is on an
NT machine, using the administrator account.
Thanks for the help.
- Raw text -