This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project. See the Cygwin home page for more information.
Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: putenv does not put env into win32?


Eugene Kanter <eugene@bgs.com> writes:
> 
> cygwin
> 
> adding DIRDLL to the PATH (getenv/putenv) and calling
> LoadLibrary("DIRDLL/DLLA") (or dlopen("DIRDLL/DLLA",RTLD_NOW)) fails
> ONLY if current directory (chdir()) is not DIRDLL.

I can now confirm that adding to PATH in Cygwin process and then trying
to load a DLL using LoadLibrary doesn't work expected. dlopen works since
it explicitly searches in PATH for the library and uses LoadLibrary with
the complete pathname of the DLL.

Cygwin DLL doesn't seem to sync the environment variables with Win32
using SetEnvironment (or whatever it's called) in putenv(), and that's
the reason.

Please try the following untested code (note the explicit adding to win32 
env as well):

  int 
  add_path (const char *newdir)  
  {   
    char newpath[1024];  
  #if __CYGWIN__
    char scratch[1024];  
  #endif /* __CYGWIN__ */
    const char *pathvar = getenv ("PATH");  
    sprintf (newpath, "PATH=%s:%s", newdir, pathvar);  
    putenv (newpath);  
    printf ("New path: %s\n", newpath);  
      
  #if __CYGWIN__
    /* now do the win32 path. */  
    cygwin32_posix_to_win32_path_list (pathvar, scratch);  
    sprintf (newpath, "%s;%s", newdir, scratch);  
    SetEnvironmentVariable ("PATH", newpath);  
    printf ("New path: %s\n", newpath);  
  #endif /* __CYGWIN__ */
    return 0;  
  }

If this works, you can use something like it.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com