Example #1
0
bool
c_setenv(const char *variable, const char *value, bool overwrite)
{
    c_utf16_t *var, *val;
    bool result;
    var = u8to16(variable);
    val = u8to16(value);
    result = (SetEnvironmentVariableW(var, val) != 0) ? true : false;
    c_free(var);
    c_free(val);
    return result;
}
Example #2
0
GModule *
g_module_open (const gchar *file, GModuleFlags flags)
{
	GModule *module;
	module = g_malloc (sizeof (GModule));
	if (module == NULL)
		return NULL;

	if (file != NULL) {
		gunichar2 *file16;
		file16 = u8to16(file); 
		module->main_module = FALSE;
		module->handle = LoadLibrary (file16);
		g_free(file16);
		if (!module->handle) {
			g_free (module);
			return NULL;
		}
			
	} else {
		module->main_module = TRUE;
		module->handle = GetModuleHandle (NULL);
	}

	return module;
}
Example #3
0
const char *
c_getenv(const char *variable)
{
    c_utf16_t *var, *buffer;
    char *val = NULL;
    int32_t buffer_size = 1024;
    int32_t retval;
    var = u8to16(variable);
    buffer = c_malloc(buffer_size * sizeof(c_utf16_t));
    retval = GetEnvironmentVariableW(var, buffer, buffer_size);
    if (retval != 0) {
        if (retval > buffer_size) {
            c_free(buffer);
            buffer_size = retval;
            buffer = c_malloc(buffer_size * sizeof(c_utf16_t));
            retval = GetEnvironmentVariableW(var, buffer, buffer_size);
        }
        val = u16to8(buffer);
    } else {
        if (GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
            val = c_malloc(1);
            *val = 0;
        }
    }
    c_free(var);
    c_free(buffer);
    return val;
}
Example #4
0
void
c_unsetenv(const char *variable)
{
    c_utf16_t *var;
    var = u8to16(variable);
    SetEnvironmentVariableW(var, L"");
    c_free(var);
}
Example #5
0
static void
write_string (MonoCompile *cfg, const char *str)
{
	size_t len = strnlen (str, 0x2000);
	write_int (cfg, (int) len);

	gunichar2 *u = u8to16 (str);
	for (int i = 0; i < len; i++)
		write_short (cfg, u[i]);
}
Example #6
0
gboolean
g_file_test (const gchar *filename, GFileTest test)
{
    gunichar2* utf16_filename = NULL;
    DWORD attr;

    if (filename == NULL || test == 0)
        return FALSE;

    utf16_filename = u8to16 (filename);
    attr = GetFileAttributesW (utf16_filename);
    g_free (utf16_filename);

    if (attr == INVALID_FILE_ATTRIBUTES)
        return FALSE;

    if ((test & G_FILE_TEST_EXISTS) != 0) {
        return TRUE;
    }

    if ((test & G_FILE_TEST_IS_EXECUTABLE) != 0) {
        size_t len = strlen (filename);
        if (len > 4 && strcmp (filename + len-3, "exe"))
            return TRUE;

        return FALSE;
    }

    if ((test & G_FILE_TEST_IS_REGULAR) != 0) {
        if (attr & (FILE_ATTRIBUTE_DEVICE|FILE_ATTRIBUTE_DIRECTORY))
            return FALSE;
        return TRUE;
    }

    if ((test & G_FILE_TEST_IS_DIR) != 0) {
        if (attr & FILE_ATTRIBUTE_DIRECTORY)
            return TRUE;
    }

    /* make this last in case it is OR'd with something else */
    if ((test & G_FILE_TEST_IS_SYMLINK) != 0) {
        return FALSE;
    }

    return FALSE;
}
Example #7
0
int mkstemp (char *tmp_template)
{
    int fd;
    gunichar2* utf16_template;

    utf16_template  = u8to16 (tmp_template);

    fd = -1;
    utf16_template = _wmktemp( utf16_template);
    if (utf16_template && *utf16_template) {
        /* FIXME: _O_TEMPORARY causes file to disappear on close causing a test to fail */
        fd = _wopen( utf16_template, _O_BINARY | _O_CREAT /*| _O_TEMPORARY*/ | _O_RDWR | _O_EXCL, _S_IREAD | _S_IWRITE);
    }

    /* FIXME: this will crash if utf16_template == NULL */
    sprintf (tmp_template + strlen (tmp_template) - 6, "%S", utf16_template + wcslen (utf16_template) - 6);

    g_free (utf16_template);
    return fd;
}