Home > Archive > Unix Programming > May 2006 > AIX5.1 FSTREAM BUG? who can tell me why?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
AIX5.1 FSTREAM BUG? who can tell me why?
|
|
| horneye 2006-05-24, 4:11 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?
| |
| joe@invalid.address 2006-05-25, 4:04 am |
| "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
| |
| horneye 2006-05-25, 4:04 am |
| sorry,it's my fault, it's actually std::ios::out, would you please tell
me why?
| |
| joe@invalid.address 2006-05-25, 7:04 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
| |
| horneye 2006-05-25, 10:01 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.
|
|
|
|
|