AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  AIX5.1 FSTREAM BUG? who can tell me why?

    Posted Sat May 27, 2006 02:37 AM

    Originally posted by: SystemAdmin


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

    char m_controlFile200 + 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:out);
    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_controlFile200 + 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?


    #AIX-Forum


  • 2.  Nope

    Posted Tue May 30, 2006 05:06 PM

    Originally posted by: nagger


    Sorry, I can't tell you why but it seems the answer to lots of forum questions are have you tested this on the latest version of AIX and the latest maintenance level.

    I note you are using AIX 5.1 - this release of AIX is so old it is not supported any longer without special additional service contracts.

    Are you on the latest maintenance level? If not it could all be fixed already but don't forget to upgrade your firmware first.

    #AIX-Forum