getenv problem

Discussion in 'C Programming' started by jain-neeraj, Jun 27, 2003.

  1. jain-neeraj

    jain-neeraj Guest

    Hi everyone,

    I came across a strange problem today while doing putenv() and
    getenv(). It seems that getenv() is doing "something" with the
    variables exported using putenv().

    Immediately after putenv(), each variable is available; However after
    putenv() of all of them, some get messed up (getenv problem???). This
    does not look like to be a heap problem, because putenv() is always
    successful. Also, the actual results show that they are intially "put"
    into the env successfully. It is more mystifying because the alternate
    values are getting "lost".

    Any suggestions will be of great help. Following is a snippet
    alongwith the actual results.

    int some_function()
    {
    char env_str[500];

    if (! (user_connected))
    {
    sprintf (env_str,"ORA_USER=%s", g_env.username);
    if (putenv (env_str) != 0)
    {
    ERR_StdReportAndReturn_1 (SA_PUTENV_ERROR,
    "ORA_USER");
    }
    printf("\n ORA_USER=%s",getenv("ORA_USER"));

    sprintf (env_str,"ORA_PASS=%s", g_env.password);
    if (putenv (env_str) != 0)
    {
    ERR_StdReportAndReturn_1 (SA_PUTENV_ERROR,
    "ORA_PASS");
    }
    printf("\n ORA_PASS=%s",getenv("ORA_PASS"));

    sprintf (env_str,"ORA_INST=%s", g_env.db_instance);
    if (putenv (env_str) != 0)
    {
    ERR_StdReportAndReturn_1 (SA_PUTENV_ERROR,
    "ORA_INST");
    }
    printf("\n ORA_INST=%s",getenv("ORA_INST"));

    sprintf (env_str,"ORA_INST_NODE=%s",
    g_env.db_instance_node);
    if (putenv (env_str) != 0)
    {
    ERR_StdReportAndReturn_1 (SA_PUTENV_ERROR,
    "ORA_INST_NODE");
    }
    printf("\n ORA_INST_NODE=%s",getenv("ORA_INST_NODE"));

    printf ("\n inside block");
    printf("\n ORA_USER=%s",getenv("ORA_USER"));
    printf("\n ORA_PASS=%s",getenv("ORA_PASS"));
    printf("\n ORA_INST=%s",getenv("ORA_INST"));
    printf("\n ORA_INST_NODE=%s",getenv("ORA_INST_NODE"));

    } //end-if

    printf ("\n outside block");
    printf("\n ORA_USER=%s",getenv("ORA_USER"));
    printf("\n ORA_PASS=%s",getenv("ORA_PASS"));
    printf("\n ORA_INST=%s",getenv("ORA_INST"));
    printf("\n ORA_INST_NODE=%s",getenv("ORA_INST_NODE"));

    // call 3rd party product which needs these variables

    } // end some_function()

    output:

    ORA_USER=neeraj
    ORA_PASS=jain
    ORA_INST=njinst
    ORA_INST_NODE=njnode
    inside block
    ORA_USER=
    ORA_PASS=jain
    ORA_INST=
    ORA_INST_NODE=njnode
    outside block
    ORA_USER=
    ORA_PASS=jain
    ORA_INST=
    ORA_INST_NODE=njnode

    Thanks in advance,
    Neeraj.
     
    jain-neeraj, Jun 27, 2003
    #1
    1. Advertisements

  2. jain-neeraj

    Micah Cowan Guest

    Erm, yes it is. (POSIX).

    -Micah
     
    Micah Cowan, Jun 28, 2003
    #2
    1. Advertisements

  3. jain-neeraj

    jain-neeraj Guest

    Thanks for your co-operation.

     
    jain-neeraj, Jun 28, 2003
    #3
  4. jain-neeraj

    jain-neeraj Guest

    Thanks Emmanuel, your advice was absolutely to-the-point. I found the solution.
     
    jain-neeraj, Jun 28, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.