Changeset 16909


Ignore:
Timestamp:
2008-08-20T10:30:21+12:00 (16 years ago)
Author:
davidb
Message:

Switched from using setenv to putenv, as former doesn't appear to be part of Visual Studio whereas latter is. putenv() is a bit more fiddly to work with, as it requires you to keep around the char* used in the call as the char * is live in the environment. Changing the char* has an immediate effect on what is represented in the environment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/common-src/src/lib/gsdltools.cpp

    r16895 r16909  
    169169
    170170static bool gsdl_setenv_done = false;
     171static char* retain_gsdlosc   = NULL;
     172static char* retain_gsdlhomec = NULL;
     173static char* retain_pathc     = NULL;
    171174
    172175bool set_gsdl_env_vars (const text_t& gsdlhome)
     
    207210  } 
    208211
    209   // these will be cleaned up in the destructor
    210   char* gsdlosc = gsdlos.getcstr();
    211   char* gsdlhomec = gsdlhome.getcstr();
    212   char* pathc = path.getcstr();
     212  text_t putpath     = "PATH=" + path;
     213  text_t putgsdlos   = "GSDLOS=" + gsdlos;
     214  text_t putgsdlhome = "GSDLHOME=" + gsdlhome;
     215
     216  retain_gsdlosc   = putgsdlos.getcstr();
     217  retain_gsdlhomec = putgsdlhome.getcstr();
     218  retain_pathc     = path.getcstr();
    213219 
    214   if ((setenv("GSDLOS",gsdlosc,1)!=0)
    215       || (setenv("GSDLHOME",gsdlhomec,1)!=0)
    216       || (setenv("PATH",pathc,1)!=0))
     220  if ((putenv(retain_gsdlosc)!=0) || (putenv(retain_gsdlhomec)!=0) 
     221  || (putenv(retain_pathc)!=0))
    217222    {
    218       perror("Setting Greenstone environment variables");
     223      perror("Setting Greenstone environment variables with putenv()");
    219224      return false;
    220225    }
    221226
    222   delete [] gsdlosc;
    223   delete [] gsdlhomec;
    224   delete [] pathc;
     227  // Need to keep memory allocated setgsdlosc, setgsdlhomec or pathc around
     228  // (i.e. can't delete them).  This is because putenv() doesn't take
     229  // a copy, but places them in the actual environment. 
    225230
    226231  gsdl_setenv_done = true;
Note: See TracChangeset for help on using the changeset viewer.