static DeviceState *fdt_create_qdev_from_compat(char *compat, char **dev_type) { DeviceState *ret = NULL; char *c = g_strdup(compat); ret = qdev_try_create(NULL, c); if (!ret) { /* QEMU substitutes "."s for ","s in device names, so try with that * substitutution */ substitute_char(c, ',', '.'); ret = qdev_try_create(NULL, c); } if (!ret) { /* try again with the version string trimmed */ trim_version(c); ret = qdev_try_create(NULL, c); } if (dev_type) { *dev_type = c; } else { g_free(c); } return ret; }
char* which(char* cmd) { #ifndef HAVE_WINDOWS_H char* which_cmd=cat("command -v \"",cmd,"\"",NULL); #else if((cmd[0]=='.' && cmd[1]=='/')|| /* relative path */ position_char("/:",cmd)!=-1) { /* have no path element */ cmd=substitute_char('\\','/',q(cmd)); return truename(cmd); } char* which_cmd=cat("cmd /c where ",cmd,"",NULL); #endif cond_printf(1,"which cmd:%s\n",which_cmd); char* p=system_(which_cmd); cond_printf(1,"which result:%s\n",p); p=substitute_char('\0','\r',substitute_char('\0','\n',p)); char* p2=p?remove_char("\r\n",p):q(""); s(p),s(which_cmd); return p2; }
char* uname_m(void) { #if defined(_WIN64) return q("x86-64"); #endif #ifdef __CYGWIN__ return q("x86"); #endif #ifndef HAVE_WINDOWS_H char *p=system_("uname -m"); char *p2; p2=remove_char("\r\n",p); s(p); if(strcmp(p2,"i686")==0) { s(p2); return q("x86"); } if(strcmp(p2,"amd64")==0) { s(p2); return q("x86-64"); } if(strcmp(p2,"armv6l")==0 || strcmp(p2,"armv7l")==0) { char* result=system_("readelf -A /proc/self/exe |grep Tag_ABI_VFP_args|wc -l"); char* result2=remove_char("\r\n",result); s(result); if(strcmp(result2,"0")!=0) { s(result2); return q("armel"); }else { s(result2); return q("armhf"); } } return substitute_char('-','_',p2); #else #if _WIN64 return q("x86-64"); #elif _WIN32 BOOL isWow64 = FALSE; LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process"); if(fnIsWow64Process) { if (!fnIsWow64Process(GetCurrentProcess(), &isWow64)) return q("x86"); if(isWow64) return q("x86-64"); else return q("x86"); } else return q("x86"); #endif #endif }
char* extract_command_str(int flags,const char *filename,int do_extract,const char* outputpath,char* type) { char* str; char* _uname_m=uname_m(); char* _uname=uname(); char* _homedir=configdir(); char* exe=s_escape_string(cat(_homedir,"impls",SLASH,_uname_m,SLASH,_uname,SLASH,"7za",SLASH,"9.20",SLASH,"7za.exe",NULL)); char *outputpath2=q(outputpath); char *filename2=q(filename); substitute_char('\\','/',outputpath2); outputpath2=s_escape_string(outputpath2); filename2=s_escape_string(filename2); ensure_directories_exist(outputpath2); if(strcmp(type,"gzip")==0 || strcmp(type,"bzip2")==0 || strcmp(type,"xz")==0) { str=cat("cmd /c \"",exe," ",do_extract?"x ":"l ",filename2," -so |",exe," x -ttar -si -y -o",outputpath2,"\"",NULL); }else if(strcmp(type,"7za")==0) { ensure_directories_exist(outputpath2); str=cat(exe," ",do_extract?"x":"t"," -y -o",outputpath2," ",filename2,NULL); } s(outputpath2),s(filename2),s(_homedir),s(_uname),s(_uname_m); return str; }
char* _getenv(const char* name) { char* name_=substitute_char('_','.',q(name)); char* ret=getenv(name_); s(name_); return ret; }