This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Truncated Environment Variables? - using Cygwin + GetEnvironmentStrings() WIN32 API


Hi,

	I'm working on an app which attempts to get
the environment of running cygwin apps.  It does this
by running the GetEnvironmentStrings() win32 api call
in the context of the running cygwin app (code injection).
However the result that comes back as a truncated version of
the environment - only 4 values PATH, SYSTEMDRIVE, SYSTEMROOT,
WINDIR.

	You can reproduce this by compiling envs.c attached.
(gcc -o envs-gcc.exe envs-gcc.c).  If you run the resulting exe
in cmd.exe (win xp) you get the full env in both cases but
if you run it under bash then the windows version is truncated.

	I saw the article below which seems relevant but I
was confused because my understanding of it would mean that
the call using win32 api should fail when run under both cmd.exe
and bash.exe which is not the case.

http://cygwin.com/ml/cygwin/2006-01/msg00938.html
	

	I would be most grateful if someone could tell me
why this might be happening and what possible alternative
paths I could follow.

thanks in advance + kind regards,

Kaveh.

PS. I've attached the output of "cygcheck -s -v -r > cygcheck.out"
and am running Windows XP Professional SP2
cygcheck -s -v -r
#include <stdio.h>
#include <unistd.h>
#include <windows.h>

int main ( int argc, char * argv[] , char *envp[] )
{
   int i = 0 ;
   int j = 0 ;
   char * envw = NULL ;
   printf ("====================== GCC Environment ==============\n") ;
   i = 0 ;
   while ( envp[i] != NULL )
      {
      printf ("%s\n", envp[i++] ) ;
      }
   //   printf ("&argv=0x%x 0x%x, &environ=0x%x\n", argv, argv, environ ) ;

   printf ("\n\n====================== Windows GetEnvironmentStrings Environment ==============\n") ;
   envw =  GetEnvironmentStrings();
   while ( strlen (envw) > 0 )
     {
     j++ ;
     printf ("%s\n",envw);
     envw += strlen(envw) + 1;
     }

   printf ("\n\nWindows Env Strings: %d, Cygwin Env Strings Count: %d\n\n", j, i) ;

}

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]