AIX5.1 FSTREAM BUG? who can tell me why?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > AIX5.1 FSTREAM BUG? who can tell me why?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    AIX5.1 FSTREAM BUG? who can tell me why?  
horneye


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 06:20 AM

-----------------------------------------example1
begin-----------------------------------------------------
#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include <pthread.h>
#include <stdio.h>

char m_controlFile[200 + 1] = "./log/control.ini";
std::fstream m_controlStream;
int readfile(int pid);

int main(int argc, char* argv[])
{
readfile(2);
}

int readfile(int pid)
{
int ret = 5;

m_controlStream.open(m_controlFile, std::ios:ut);
printf("pid %d: opened up\n", pid, ret);

if (m_controlStream.fail())
{
printf("pid %d: open fail.\n", pid);
return -1;
}
else if (m_controlStream.bad())
{
printf("pid %d: open bad.\n", pid);
return -1;
}
else if (m_controlStream.eof())
{
printf("pid %d: open eof.\n", pid);
return -1;
}
else
{
m_controlStream << ret;
}

printf("pid %d: output is %d\n", pid, ret);
m_controlStream.close();
printf("pid %d: close\n", pid, ret);

for (int i = 0; i < 2; i++)
{
m_controlStream.open(m_controlFile);
printf("pid %d: opened up\n", pid, ret);

if (m_controlStream.fail())
{
printf("pid %d: open fail.\n", pid);
return -1;
}
else if (m_controlStream.bad())
{
printf("pid %d: open bad.\n", pid);
return -1;
}
else if (m_controlStream.eof())
{
printf("pid %d: open eof.\n", pid);
return -1;
}
else
{
m_controlStream >> ret;
}

printf("pid %d: output is %d\n", pid, ret);
m_controlStream.close();
printf("pid %d: close\n", pid, ret);
}
}
-----------------------------------------example1
end-----------------------------------------------------


-----------------------------------------example2
begin-----------------------------------------------------

#include <sys/types.h>
#include <unistd.h>
#include <fstream>
#include <pthread.h>
#include <stdio.h>

char m_controlFile[200 + 1] = "./log/control.ini";
std::fstream m_controlStream;
int readfile(int pid);

int main(int argc, char* argv[])
{
readfile(2);
}

int readfile(int pid)
{
int ret = 5;

m_controlStream.open(m_controlFile);
printf("pid %d: opened up\n", pid, ret);

if (m_controlStream.fail())
{
printf("pid %d: open fail.\n", pid);
return -1;
}
else if (m_controlStream.bad())
{
printf("pid %d: open bad.\n", pid);
return -1;
}
else if (m_controlStream.eof())
{
printf("pid %d: open eof.\n", pid);
return -1;
}
else
{
m_controlStream << ret;
}

printf("pid %d: output is %d\n", pid, ret);
m_controlStream.close();
printf("pid %d: close\n", pid, ret);

for (int i = 0; i < 2; i++)
{
m_controlStream.open(m_controlFile);
printf("pid %d: opened up\n", pid, ret);

if (m_controlStream.fail())
{
printf("pid %d: open fail.\n", pid);
return -1;
}
else if (m_controlStream.bad())
{
printf("pid %d: open bad.\n", pid);
return -1;
}
else if (m_controlStream.eof())
{
printf("pid %d: open eof.\n", pid);
return -1;
}
else
{
m_controlStream >> ret;
}

printf("pid %d: output is %d\n", pid, ret);
m_controlStream.close();
printf("pid %d: close\n", pid, ret);
}
}
-----------------------------------------example2
end-----------------------------------------------------
under AIX5.1 run example2,output is:
pid 2: opened up
pid 2: output is 5
pid 2: close
pid 2: opened up
pid 2: output is 5
pid 2: close
pid 2: opened up
pid 2: output is 5
pid 2: close

under AIX5.1 run example2,output is:
pid 2: opened up
pid 2: output is 5
pid 2: close
pid 2: opened up
pid 2: output is 5
pid 2: close
pid 2: opened up
pid 2: open eof.


check the source of example1 and example2, we found the difference is:
Example1:m_controlStream.open(m_controlFile, ios:ut);
Example2:m_controlStream.open(m_controlFile);

who can tell me why?






[ Post a follow-up to this message ]



    Re: AIX5.1 FSTREAM BUG? who can tell me why?  
joe@invalid.address


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-25-06 12:18 PM

"horneye" <horneye_zhou@yahoo.com.cn> writes:

> check the source of example1 and example2, we found the difference is:
> Example1:m_controlStream.open(m_controlFile, ios:ut);
> Example2:m_controlStream.open(m_controlFile);
>
> who can tell me why?

I'm surprised the first example even compiled. That should be
std::ios::out, not std::ios:ut.

Joe





[ Post a follow-up to this message ]



    Re: AIX5.1 FSTREAM BUG? who can tell me why?  
horneye


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-25-06 12:18 PM

sorry,it's my fault, it's actually std::ios::out, would you please tell
me why?






[ Post a follow-up to this message ]



    Re: AIX5.1 FSTREAM BUG? who can tell me why?  
joe@invalid.address


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-06 10:32 PM

"horneye" <horneye_zhou@yahoo.com.cn> writes:

> sorry,it's my fault, it's actually std::ios::out, would you please
> tell me why?

Why what? Why your code didn't work? Since you didn't post what you
ran it's hard to say.

hint: copy and paste, don't retype.

Joe





[ Post a follow-up to this message ]



    Re: AIX5.1 FSTREAM BUG? who can tell me why?  
horneye


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-06 10:32 PM

as we see, after example2 run in AIX5.1, system display "open eof", but
example1 don't.

and i test example2 in solaris9, system don't display "open eof", too.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:48 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register