delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/04/28/11:31:46

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Message-Id: <199904281530.KAA26761@modi.xraylith.wisc.edu>
X-Authentication-Warning: modi.xraylith.wisc.edu: localhost.xraylith.wisc.edu [127.0.0.1] didn't use HELO protocol
To: Eugene Kanter <eugene AT bgs DOT com>, cygwin AT sourceware DOT cygnus DOT com
Subject: Re: putenv does not put env into win32?
In-reply-to: Your message of "Wed, 28 Apr 1999 10:12:39 CDT."
<199904281512 DOT KAA25861 AT modi DOT xraylith DOT wisc DOT edu>
Date: Wed, 28 Apr 1999 10:30:19 -0500
From: Mumit Khan <khan AT xraylith DOT wisc DOT EDU>

Mumit Khan <khan AT xraylith DOT wisc DOT EDU> writes:
> 
> 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;  
>   }
> 

Ooops. Try this instead:
  
  #include <windows.h>

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

and you can now call add_path with Cygwin pathname that will get 
translated to win32 pathname correctly:
  
  add_path ("/usr/local/lib");

Now since dlopen essentially is the same as LoadLibrary (and returns
the same handle), you could just use dlopen and dlclose (which will
call the unload library routine). I don't know the details of who's
calling the unload routine, so I can't judge if that will work for
you.

Regards,
Mumit


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019