On 30-May-2003 Garry Williams wrote:
> On Fri, May 30, 2003 at 09:16:54 -0500, [EMAIL PROTECTED] wrote:
>>    I have a local C library that I interfaced with XS.  The library
>>    has an open function that looks for arguments that are sent in to
>>    the function.  If the arguments are Null, the function will check
>>    env variables for the values.  When calling this function from
>>    perl, the env variables are never set.   
> 
> So set the environment variables before calling the function from
> perl: 
> 
>   $ENV{ENV_VAR} = 'value';

    ..The problem is that the c function is not getting the vars from 
      the env, when running under Perl.  The getenv() does not seem to
      work.  If I set the variables $ENV{PROJECT} = 9999 and $ENV{SERVICE} = 1,
      call the function OpenLog(Arg, Arg, "", ""), the function will see the
      2 empty strings and attemt to read the values from the env.  These env
      variables could be set by a shell script before the perl is run.  The perl
      code could be last in a series of utilities that use these env vars.  It works
      if the actual arguments are sent to the function, but I would like to have 
      the interface behave as the C calls do.  Here is some of the C code if my 
      explaination is to vague,


int OpenDotsLog(
    const char *program, 
    DOTS_DISP is_display, 
    DOTS_ACT not_set, 
    const char *inproject,
    const char *inservice,
    const char *inuser, 
    const char *inclient
)
{
    char chrOutput[500]="";
    sprintf(DotsLog.FileName, "%sXXXXXX", LOGPATH);

    /* Check the parameters */
    DotsLog.Project = GETENV(inproject, "PROJECTNUM");
    DotsLog.Service = GETENV(inservice, "SERVICENUM");
    DotsLog.UserID = GETENV(inuser, "NEWUSER");
    DotsLog.ClientName = GETENV(inclient, "CLIENTNAME");

    /* Set the default values if the environment is not set */
    if (DotsLog.Project == NULL || strcmp(DotsLog.Project, "NO PROJECT")==0)
        DotsLog.Project = strdup(DEFAULT_PROJECTNUM);

    if (DotsLog.Service == NULL || strcmp(DotsLog.Service, "NO SERVICE")==0)
        DotsLog.Service = strdup(DEFAULT_SERVICENUM);

    if (DotsLog.ClientName == NULL)
        DotsLog.ClientName = strdup(DEFAULT_CLIENTNAME);

 
    if (DotsLog.UserID == NULL)
    {
        DotsLog.UserID = getenv(DEFAULT_USER);
        if (DotsLog.UserID == NULL)
            DotsLog.UserID = strdup("UNKNOWN");
  }


   ..I didn't write the library, and we intend on rewriting it, but for now I need to 
     interface this library.  Is this any clearer????
 
 
   
> 
> or supply the arguments needed to the function.  
> 
>>    The function uses this macro,
>> 
>>    #define GETENV(var, env) ( (var) == NULL ? getenv((env)) : (var) )
>> 
>>    , this is used to fill a structure that holds the values.  If I
>>    send in non-null arguments the values are set correctly.  I
>>    cannot get the env variables to populate the C structure.  I can
>>    easily interface the env through %ENV, but this is needed
>>    internally by the C function.  
> 
> Huh?  getenv(3) returns the strings in %ENV.

      ..the function is filling a internal structure that is used to 
        create log files.  So it cannot access %ENV from the  
> 
>>    Any ideas or suggestions?
> 
> -- 
> Garry Williams, Zvolve Systems, Inc., +1 770 551-4504

----------------------------------
E-Mail: [EMAIL PROTECTED]
Date: 02-Jun-2003
Time: 09:58:56
----------------------------------

Reply via email to