static char *get_aux_path(void) { const char *key = "SOFTWARE\\ev-i\\hpgs"; DWORD len; HKEY hkey; char *ret; const char *prg; if ((RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS || RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS )&& RegQueryValueEx(hkey,"prefix",NULL,NULL,NULL,&len) == ERROR_SUCCESS) { ret = malloc(len+2); if (RegQueryValueEx(hkey,"prefix",NULL,NULL,ret,&len) != ERROR_SUCCESS) { free (ret); ret = 0; } RegCloseKey(hkey); return ret; } prg = getenv("PROGRAMFILES"); if (prg) return hpgs_sprintf_malloc("%s\\EV-i",prg); return strdup("C:\\Programme\\EV-i"); }
/*! Constructs a filename on the heap for a file located in the installation path passed to \c hpgs_init. Returns 0, if the system is out of memory. */ char *hpgs_share_filename(const char *rel_filename) { return hpgs_sprintf_malloc("%s%cshare%chpgs%c%s", hpgs_get_prefix(), HPGS_PATH_SEPARATOR, HPGS_PATH_SEPARATOR, HPGS_PATH_SEPARATOR, rel_filename); }
/*! Prepends the error message of the current thread with the given string. this is useful, if you want to push context information to the error message. Always returns -1. */ int hpgs_verror_ctxt(const char *fmt, va_list ap) { char *x; #ifdef WIN32 x = (char *)TlsGetValue(tls_handle); if (!fmt) return -1; char * new_p = vsprintf_hHeap(fmt,ap); if (!new_p) return -1; if (x) { char *tmp = sprintf_hHeap("%s: %s",new_p,x); HeapFree(hHeap,0,new_p); if (!tmp) return -1; HeapFree(hHeap,0,x); new_p = tmp; } TlsSetValue(tls_handle,new_p); #else x = (char *)pthread_getspecific (key); char * new_p = hpgs_vsprintf_malloc(fmt,ap); if (!new_p) return -1; if (x) { char *tmp = hpgs_sprintf_malloc("%s: %s",new_p,x); free(new_p); if (!tmp) return -1; free(x); new_p = tmp; } pthread_setspecific (key,new_p); #endif return -1; }