catopen()在某些情况下失败时不设置errno

catopen()在某些情况下失败时不设置errno,c,solaris,opensolaris,C,Solaris,Opensolaris,catopen无法使用相同的设置在不同的服务器中打开相同的cat文件 当errno为0时,表示我的理解没有错误 请告诉我以前是否有人见过这种情况。 如果有人知道这件事发生的原因,那将对我很有帮助 我编写的示例代码 int main() { nl_catd cat; string fileName; cout<<"Enter the cat file name: "; cin>>fileName; cat = catopen(file

catopen无法使用相同的设置在不同的服务器中打开相同的cat文件

当errno为0时,表示我的理解没有错误

请告诉我以前是否有人见过这种情况。 如果有人知道这件事发生的原因,那将对我很有帮助

我编写的示例代码

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);

}
intmain()
{
nl_猫;
字符串文件名;
coutfileName;
cat=catopen(fileName.c_str(),0);
如果(cat==(nl_catd)-1)
{

cerr当您将字符串
无法打开目录:
写入
cerr
时,您清除了
errno

您必须立即保存
errno
的值

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);
} 
cat=catopen(fileName.c_str(),0);
如果(cat==(nl_catd)-1)
{ 
int errno_catopen=errno;

cerr是一个文件名的问题,还是多个文件名的问题?如果只有一个文件,可能它已损坏?这可能是问题所在,但错误号不应通过成功调用重置,而应通过失败调用重置。Posix函数和C std库函数不再应将
errno
设置为零。该规则仅适用于C notC++或Inc.流或FSKIPs。您仍然不能假定任何其他函数,包括<代码> CURR操作符。 ./a.out Enter the cat file name: ehap_ac_in.epod.cat Unable to open catalogue: ehap_ac_in.epod.cat0
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);
}