#include <string.h>
#include <stdlib.h>
+#ifdef _WIN32
+#include <windows.h>
+#include <processenv.h>
+#endif
+
#include <orc/orcprogram.h>
#include <orc/orcdebug.h>
#include <orc/orconce.h>
{
return (const char *) VERSION;
}
+
+/* getenv() is deprecated on Windows and always returns NULL on UWP */
+#ifdef _WIN32
+char*
+_orc_getenv (const char *key)
+{
+ int len;
+ char check[1], *value;
+
+ /* Get the len */
+ len = GetEnvironmentVariableA (key, check, 1);
+ if (len == 0)
+ /* env var is not set or is "" (empty string) */
+ return NULL;
+
+ /* max size of len is 32767, cannot overflow */
+ value = malloc (sizeof (value) * len);
+
+ if (GetEnvironmentVariableA (key, value, len) != (len - 1)) {
+ free (value);
+ return NULL;
+ }
+
+ return value;
+}
+#else
+char*
+_orc_getenv (const char *key)
+{
+ char *value = getenv (key);
+
+ if (value)
+ value = strdup (value);
+
+ return value;
+}
+#endif
void
_orc_compiler_init (void)
{
- const char *envvar;
+ char *envvar;
- envvar = getenv ("ORC_CODE");
+ envvar = _orc_getenv ("ORC_CODE");
if (envvar != NULL) {
_orc_compiler_flag_list = strsplit (envvar, ',');
+ free (envvar);
}
_orc_compiler_flag_backup = orc_compiler_flag_check ("backup");
#include "config.h"
#endif
#include <orc/orcdebug.h>
+#include <orc/orcinternal.h>
#include <stdio.h>
#include <string.h>
void
_orc_debug_init(void)
{
- const char *envvar;
+ char *envvar;
- envvar = getenv ("ORC_DEBUG");
+ envvar = _orc_getenv ("ORC_DEBUG");
if (envvar != NULL) {
char *end = NULL;
int level;
if (end > envvar) {
_orc_debug_level = level;
}
+ free (envvar);
}
ORC_INFO ("orc-" VERSION " debug init");
void orc_compiler_emit_invariants (OrcCompiler *compiler);
int orc_program_has_float (OrcCompiler *compiler);
+
+char* _orc_getenv (const char *var);
#endif
ORC_END_DECLS