** Implementation of the POSIX getenv() function using the Win32 API. ** This function is not thread-safe. */
| 1218 | ** This function is not thread-safe. |
| 1219 | */ |
| 1220 | const char *windirent_getenv( |
| 1221 | const char *name |
| 1222 | ){ |
| 1223 | static char value[32768]; /* Maximum length, per MSDN */ |
| 1224 | DWORD dwSize = sizeof(value) / sizeof(char); /* Size in chars */ |
| 1225 | DWORD dwRet; /* Value returned by GetEnvironmentVariableA() */ |
| 1226 | |
| 1227 | memset(value, 0, sizeof(value)); |
| 1228 | dwRet = GetEnvironmentVariableA(name, value, dwSize); |
| 1229 | if( dwRet==0 || dwRet>dwSize ){ |
| 1230 | /* |
| 1231 | ** The function call to GetEnvironmentVariableA() failed -OR- |
| 1232 | ** the buffer is not large enough. Either way, return NULL. |
| 1233 | */ |
| 1234 | return 0; |
| 1235 | }else{ |
| 1236 | /* |
| 1237 | ** The function call to GetEnvironmentVariableA() succeeded |
| 1238 | ** -AND- the buffer contains the entire value. |
| 1239 | */ |
| 1240 | return value; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | /* |
| 1245 | ** Implementation of the POSIX opendir() function using the MSVCRT. |