Reputation: 3
catopen is failing to open same cat file in different servers, with same setup.
When errno is 0 it means no error from my understanding.
Please tell me if anyone has seen like this before. If any one knows the reason why it is happening it will be very helpful for me
Sample code i wrote
int main()
{
nl_catd cat;
string fileName;
cout<<"Enter the cat file name: ";
cin>>fileName;
cat = catopen(fileName.c_str(), 0);
if (cat == (nl_catd)-1)
{
cerr << "Unable to open catalogue: " << fileName <<" ....and the Error number: "<<errno<<"\n";
exit(1);
}
printf("File opened...\n");
catclose( cat );
exit(0);
}
Output for above code
./a.out Enter the cat file name: LinkMonitor.epod.cat File opened...
./a.out Enter the cat file name: ehap_ac_in.epod.cat Unable to open catalogue: ehap_ac_in.epod.cat0
Here 0 is the error code.
Upvotes: 0
Views: 363
Reputation: 35653
You cleared errno
when you wrote the string "Unable to open catalogue: "
to cerr
.
You have to save the value of errno
straight away.
cat = catopen(fileName.c_str(), 0);
if (cat == (nl_catd)-1)
{
int errno_catopen = errno;
cerr << "Unable to open catalogue: " << fileName <<" ....and the Error number: "<<errno_catopen <<"\n";
exit(errno_catopen);
}
Upvotes: 2