I'm using the following code in OSX and in Windows Vista:
#include <stdio.h>
#include <string.h>
extern char **environ;
int
main(int argc, char **argv)
{
int i;
for (i = 0; environ[i] != NULL; i++)
{
printf("var = %s - %d\n", environ[i], (int)strlen(environ[i]));
}
return 0;
}
On OSX compile it with cc
, on Windows - with 'cl' from Windows SDK 7.1 (with Redistributable Packages: Microsoft Visual C++ 2010 in it).
I define the same ENV variables in both OS in Russian language: MY_ENV='russian letters goes here'. And have got a difference about 2 times in a length of a strings.
This length I'm planning to use in malloc
and want them be the same. How can I get the same lengths correctly, in CRT way?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.