char * getenv(const char *name) { HKEY key; wchar_t *wname; LONG res; DWORD type; DWORD disposition; DWORD size = PATH_MAX; if (!name || !*name) return NULL; if ((res = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Efl\\Environment"), 0, NULL, REG_OPTION_VOLATILE, 0, NULL, &key, &disposition)) != ERROR_SUCCESS) { _evil_error_display(__FUNCTION__, res); return NULL; } wname = evil_char_to_wchar(name); if (!wname) { if ((res = RegCloseKey (key)) != ERROR_SUCCESS) _evil_error_display(__FUNCTION__, res); return NULL; } if ((res = RegQueryValueEx(key, wname, NULL, &type, (LPBYTE)&_evil_stdlib_getenv_buffer, &size)) != ERROR_SUCCESS) { if ((res = RegCloseKey (key)) != ERROR_SUCCESS) _evil_error_display(__FUNCTION__, res); free(wname); return NULL; } free(wname); if ((res = RegCloseKey (key)) != ERROR_SUCCESS) { _evil_error_display(__FUNCTION__, res); return NULL; } if (_evil_stdlib_getenv_buffer[0] == '\0') return NULL; else { return _evil_stdlib_getenv_buffer; } }
void * dlopen(const char* path, int mode __UNUSED__) { HMODULE module = NULL; if (!path) { module = GetModuleHandle(NULL); if (!module) get_last_error("GetModuleHandle returned: "); } else { char *new_path; size_t l; unsigned int i; /* according to MSDN, we must change the slash to backslash */ l = strlen(path); new_path = (char *)malloc(sizeof(char) * (l + 1)); if (!new_path) { if (dl_err) free(dl_err); dl_err = strdup("not enough resource"); dl_err_viewed = 0; return NULL; } for (i = 0; i <= l; i++) { if (path[i] == '/') new_path[i] = '\\'; else new_path[i] = path[i]; } #ifdef UNICODE { wchar_t *wpath; wpath = evil_char_to_wchar(new_path); module = LoadLibrary(wpath); free(wpath); } #else module = LoadLibraryEx(new_path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); #endif /* ! UNICODE */ if (!module) get_last_error("LoadLibraryEx returned: "); free(new_path); } return module; }
void * dlsym(void *handle, const char *symbol) { FARPROC fp = NULL; LPCTSTR new_symbol; if (!symbol || !*symbol) return NULL; #ifdef UNICODE new_symbol = evil_char_to_wchar(symbol); #else new_symbol = symbol; #endif /* UNICODE */ if (handle == RTLD_DEFAULT) { HMODULE modules[1024]; DWORD needed; DWORD i; /* TODO: use EnumProcessModulesEx() on Windows >= Vista */ if (!EnumProcessModules(GetCurrentProcess(), modules, sizeof(modules), &needed)) { #ifdef UNICODE _dl_get_last_error("EnumProcessModules returned: "); free((void *)new_symbol); #endif /* UNICODE */ return NULL; } for (i = 0; i < (needed / sizeof(HMODULE)); i++) { fp = GetProcAddress(modules[i], new_symbol); if (fp) break; } } else fp = GetProcAddress(handle, new_symbol); #ifdef UNICODE free((void *)new_symbol); #endif /* UNICODE */ if (!fp) _dl_get_last_error("GetProcAddress returned: "); return fp; }
int mkstemp(char *__template) { char *suffix; DWORD val; size_t length; int i; if (!__template) return 0; if (!_mkstemp_init(__template, &suffix, &length, &val)) return -1; for (i = 0; i < 32768; i++) { int fd; val = _mkstemp(suffix, val); #ifndef __MINGW32CE__ fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE); #else /* ! __MINGW32CE__ */ { FILE *f; wchar_t *wtemplate; wtemplate = evil_char_to_wchar(__template); if (!wtemplate) return -1; f = _wfopen(wtemplate, L"rwb"); free(wtemplate); if (!f) { errno = EEXIST; return -1; } fd = (int)_fileno(f); } #endif /* __MINGW32CE__ */ if (fd >= 0) return fd; } errno = EEXIST; return -1; }
/** * @brief Set the title of the given window. * * @param window The window to set the title. * @param title The new title. * * This function sets the title of @p window to @p title. If @p window * is @c NULL, or if @p title is @c NULL or empty, or on error, this * function does nothing. */ EAPI void ecore_wince_window_title_set(Ecore_WinCE_Window *window, const char *title) { wchar_t *wtitle; if (!window) return; if (!title || !title[0]) return; INF("setting window title"); wtitle = evil_char_to_wchar(title); if (!wtitle) return; if (!SetWindowText(window->window, wtitle)) { ERR("SetWindowText() failed"); } free(wtitle); }
int mkstemp(char *__template) { const char lookup[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; char *suffix; DWORD val; size_t length; int i; if (!__template) return 0; length = strlen(__template); if ((length < 6) || (strncmp (__template + length - 6, "XXXXXX", 6))) { #ifdef HAVE_ERRNO_H errno = EINVAL; #endif /* HAVE_ERRNO_H */ return -1; } suffix = __template + length - 6; val = GetTickCount(); val += GetCurrentProcessId(); for (i = 0; i < 32768; i++) { DWORD v; int fd; v = val; suffix[0] = lookup[v % 62]; v /= 62; suffix[1] = lookup[v % 62]; v /= 62; suffix[2] = lookup[v % 62]; v /= 62; suffix[3] = lookup[v % 62]; v /= 62; suffix[4] = lookup[v % 62]; v /= 62; suffix[5] = lookup[v % 62]; v /= 62; #ifndef __MINGW32CE__ fd = _open(__template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE); #else /* ! __MINGW32CE__ */ { FILE *f; wchar_t *wtemplate; wtemplate = evil_char_to_wchar(__template); if (!wtemplate) return -1; f = _wfopen(wtemplate, L"rwb"); free(wtemplate); if (!f) { # ifdef HAVE_ERRNO_H errno = EEXIST; # endif /* HAVE_ERRNO_H */ return -1; } fd = (int)_fileno(f); } #endif /* __MINGW32CE__ */ if (fd >= 0) return fd; val += 7777; } #ifdef HAVE_ERRNO_H errno = EEXIST; #endif /* HAVE_ERRNO_H */ return -1; }
int setenv(const char *name, const char *value, int overwrite) { #ifndef __MINGW32CE__ char *old_name; char *str; size_t length; int res; if (!name || !*name) return -1; /* if '=' is found, return EINVAL */ if (strchr (name, '=')) { #ifdef HAVE_ERRNO_H errno = EINVAL; #endif /* HAVE_ERRNO_H */ return -1; } /* if name is already set and overwrite is 0, we exit with success */ old_name = getenv(name); if (!overwrite && old_name) return 0; length = value ? strlen(value) : 0; length += strlen(name) + 2; str = (char *)malloc(length); if (!str) { #ifdef HAVE_ERRNO_H errno = ENOMEM; #endif /* HAVE_ERRNO_H */ return -1; } if (!value) sprintf(str, "%s=", name); else sprintf(str, "%s=%s", name, value); res = _putenv(str); free(str); return res; #else /* __MINGW32CE__ */ HKEY key; LONG res; DWORD disposition; wchar_t *wname; char *data; DWORD size; if (!name || !*name) return -1; /* if '=' is found, return an error */ if (strchr (name, '=')) return -1; if ((res = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Efl\\Environment"), 0, NULL, REG_OPTION_VOLATILE, 0, NULL, &key, &disposition)) != ERROR_SUCCESS) { _evil_error_display(__FUNCTION__, res); return -1; } /* if name is already set and overwrite is 0, we exit with success */ if (!overwrite && (disposition == REG_OPENED_EXISTING_KEY)) return 0; wname = evil_char_to_wchar(name); if (!wname) { if ((res = RegCloseKey (key)) != ERROR_SUCCESS) _evil_error_display(__FUNCTION__, res); return -1; } if (value) { size = strlen(value); data = malloc(sizeof(char) * (size + 1)); if (!data) return -1; memcpy((void *)data, value, size); data[size] = '\0'; } else { size = 0; data = malloc(sizeof(char)); if (!data) return -1; data[0] = '\0'; } if (!data) return -1; if ((res = RegSetValueEx(key, (LPCWSTR)wname, 0, REG_SZ, (const BYTE *)data, size + 1)) != ERROR_SUCCESS) { free(wname); _evil_error_display(__FUNCTION__, res); if ((res = RegCloseKey (key)) != ERROR_SUCCESS) _evil_error_display(__FUNCTION__, res); return -1; } free(data); free(wname); if ((res = RegCloseKey (key)) != ERROR_SUCCESS) { _evil_error_display(__FUNCTION__, res); return -1; } return 0; #endif /* ! __MINGW32CE__ */ }
void * dlsym(void *handle, const char *symbol) { FARPROC fp = NULL; LPCTSTR new_symbol; if (!symbol || !*symbol) return NULL; #ifdef UNICODE new_symbol = evil_char_to_wchar(symbol); #else new_symbol = symbol; #endif /* UNICODE */ if (handle == RTLD_DEFAULT) { #ifdef _WIN32_WCE HANDLE snapshot; MODULEENTRY32 module; snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPMODULE | TH32CS_GETALLMODS, 0); if (!snapshot) return NULL; module.dwSize = sizeof(module); if (Module32First(snapshot, &module)) do { fp = GetProcAddress(module.hModule, new_symbol); if (fp) break; } while (Module32Next(snapshot, &module)); CloseToolhelp32Snapshot(snapshot); #else HMODULE modules[1024]; DWORD needed; DWORD i; /* TODO: use EnumProcessModulesEx() on Windows >= Vista */ if (!EnumProcessModules(GetCurrentProcess(), modules, sizeof(modules), &needed)) return NULL; for (i = 0; i < (needed / sizeof(HMODULE)); i++) { fp = GetProcAddress(modules[i], new_symbol); if (fp) break; } #endif } else fp = GetProcAddress(handle, new_symbol); #ifdef UNICODE free((void *)new_symbol); #endif /* UNICODE */ if (!fp) get_last_error("GetProcAddress returned: "); return fp; }