static YAP_Bool p_tmpdir(void) { #if defined(__MINGW32__) || _MSC_VER char buf[512]; DWORD out = GetTempPath(512, buf); if (!out) { return (YAP_Unify(YAP_ARG2, WinError())); } if (out > 511) { char *nbuf = malloc(out + 1); if (!nbuf) return YAP_Unify(YAP_ARG2, YAP_MkAtomTerm(YAP_LookupAtom("no malloc memory"))); out = GetTempPath(512, nbuf); if (!out) { return YAP_Unify(YAP_ARG2, WinError()); } return YAP_Unify(YAP_ARG1, YAP_MkAtomTerm(YAP_LookupAtom(nbuf))); } return YAP_Unify(YAP_ARG1, YAP_MkAtomTerm(YAP_LookupAtom(buf))); #else char *s; if ((s = getenv("TMPDIR"))) return YAP_Unify(YAP_ARG1, YAP_MkAtomTerm(YAP_LookupAtom(s))); #ifdef P_tmpdir return YAP_Unify(YAP_ARG1, YAP_MkAtomTerm(YAP_LookupAtom(P_tmpdir))); #endif return YAP_Unify(YAP_ARG1, YAP_MkAtomTerm(YAP_LookupAtom("/tmp"))); #endif }
/***************************************************************************** * FlushComm (USER.215) */ INT16 WINAPI FlushComm16(INT16 cid,INT16 fnQueue) { DWORD queue; struct DosDeviceStruct *ptr; TRACE("cid=%d, queue=%d\n", cid, fnQueue); if ((ptr = GetDeviceStruct(cid)) == NULL) { FIXME("no cid=%d found!\n", cid); return -1; } switch (fnQueue) { case 0: queue = PURGE_TXABORT; ptr->obuf_tail = ptr->obuf_head; break; case 1: queue = PURGE_RXABORT; ptr->ibuf_head = ptr->ibuf_tail; break; default: WARN("(cid=%d,fnQueue=%d):Unknown queue\n", cid, fnQueue); return -1; } if (!PurgeComm(ptr->handle,queue)) { ptr->commerror = WinError(); return -1; } else { ptr->commerror = 0; return 0; } }
/***************************************************************************** * CloseComm (USER.207) */ INT16 WINAPI CloseComm16(INT16 cid) { struct DosDeviceStruct *ptr; TRACE("cid=%d\n", cid); if ((ptr = GetDeviceStruct(cid)) == NULL) { FIXME("no cid=%d found!\n", cid); return -1; } if (!(cid&FLAG_LPT)) { /* COM port */ UnMapLS( COM[cid].seg_unknown ); USER16_AlertableWait--; CancelIo(ptr->handle); /* free buffers */ HeapFree( GetProcessHeap(), 0, ptr->outbuf); HeapFree( GetProcessHeap(), 0, ptr->inbuf); /* reset modem lines */ SetCommState16(&COM[cid].dcb); } if (!CloseHandle(ptr->handle)) { ptr->commerror = WinError(); /* FIXME: should we clear ptr->handle here? */ return -1; } else { ptr->commerror = 0; ptr->handle = 0; return 0; } }
PVOID HiddenFunctions::CheckPointerErrFuncVoid(PVOID ptr) { if (!ptr) { DWORD err = ::GetLastError(); throw WinError(err); } return ptr; }
/***************************************************************************** * EscapeCommFunction (USER.214) */ LONG WINAPI EscapeCommFunction16(UINT16 cid,UINT16 nFunction) { struct DosDeviceStruct *ptr; TRACE("cid=%d, function=%d\n", cid, nFunction); switch(nFunction) { case GETMAXCOM: TRACE("GETMAXCOM\n"); return 4; /* FIXME */ case GETMAXLPT: TRACE("GETMAXLPT\n"); return FLAG_LPT + 3; /* FIXME */ case GETBASEIRQ: TRACE("GETBASEIRQ\n"); /* FIXME: use tables */ /* just fake something for now */ if (cid & FLAG_LPT) { /* LPT1: irq 7, LPT2: irq 5 */ return (cid & 0x7f) ? 5 : 7; } else { /* COM1: irq 4, COM2: irq 3, COM3: irq 4, COM4: irq 3 */ return 4 - (cid & 1); } } if ((ptr = GetDeviceStruct(cid)) == NULL) { FIXME("no cid=%d found!\n", cid); return -1; } switch (nFunction) { case RESETDEV: case CLRDTR: case CLRRTS: case SETDTR: case SETRTS: case SETXOFF: case SETXON: if(EscapeCommFunction(ptr->handle,nFunction)) return 0; else { ptr->commerror = WinError(); return -1; } case CLRBREAK: case SETBREAK: default: WARN("(cid=%d,nFunction=%d): Unknown function\n", cid, nFunction); } return -1; }
void CControlError::ThrowReport() { if( doreport ) { WinError(); throw CErrExcept(); } doreport = TRUE; }
/* execute a command as a detached process */ static YAP_Bool plwait(void) { long int pid = YAP_IntOfTerm(YAP_ARG1); #if defined(__MINGW32__) || _MSC_VER HANDLE proc = OpenProcess(STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE, FALSE, pid); DWORD ExitCode; if (proc == NULL) { return (YAP_Unify(YAP_ARG3, WinError())); } if (WaitForSingleObject(proc, INFINITE) == WAIT_FAILED) { return (YAP_Unify(YAP_ARG3, WinError())); } if (GetExitCodeProcess(proc, &ExitCode) == 0) { return (YAP_Unify(YAP_ARG4, WinError())); } CloseHandle(proc); return (YAP_Unify(YAP_ARG2, YAP_MkIntTerm(ExitCode))); #else do { int status; /* check for interruptions */ if (waitpid(pid, &status, 0) == -1) { if (errno) { if (errno == EINTR) { continue; } return YAP_Unify(YAP_ARG3, YAP_MkIntTerm(errno)); } } if (WIFEXITED(status)) { return YAP_Unify(YAP_ARG2, YAP_MkIntTerm(WEXITSTATUS(status))); } else if (WIFSIGNALED(status)) { return YAP_Unify(YAP_ARG3, YAP_MkAtomTerm(YAP_LookupAtom("signalled"))) && YAP_Unify(YAP_ARG4, YAP_MkIntTerm(WTERMSIG(status))); } else /* WIFSTOPPED(status) */ { return YAP_Unify(YAP_ARG3, YAP_MkAtomTerm(YAP_LookupAtom("stopped"))) && YAP_Unify(YAP_ARG4, YAP_MkIntTerm(WSTOPSIG(status))); } } while (TRUE); #endif }
static YAP_Bool p_kill(void) { #if defined(__MINGW32__) || _MSC_VER /* Windows does not support cross-process signals, so we shall do the SICStus thing and assume that a signal to a process will always kill it */ HANDLE proc = OpenProcess(STANDARD_RIGHTS_REQUIRED | PROCESS_TERMINATE, FALSE, YAP_IntOfTerm(YAP_ARG1)); if (proc == NULL) { return (YAP_Unify(YAP_ARG3, WinError())); } if (TerminateProcess(proc, -1) == 0) { return (YAP_Unify(YAP_ARG3, WinError())); } CloseHandle(proc); #else if (kill(YAP_IntOfTerm(YAP_ARG1), YAP_IntOfTerm(YAP_ARG2)) < 0) { /* return an error number */ return (YAP_Unify(YAP_ARG3, YAP_MkIntTerm(errno))); } #endif /* defined(__MINGW32__) || _MSC_VER */ return (TRUE); }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int WINS_Broadcast( int socket, byte *buf, int len ){ int ret; if ( socket != net_broadcastsocket ) { if ( net_broadcastsocket != 0 ) { WinError( "Attempted to use multiple broadcasts sockets\n" ); } ret = WINS_MakeSocketBroadcastCapable( socket ); if ( ret == -1 ) { WinPrint( "Unable to make socket broadcast capable\n" ); return ret; } } return WINS_Write( socket, buf, len, &broadcastaddr ); } //end of the function WINS_Broadcast
static YAP_Bool host_name(void) { #if defined(__MINGW32__) || _MSC_VER char name[MAX_COMPUTERNAME_LENGTH + 1]; DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1; if (GetComputerName(name, &nSize) == 0) { return (YAP_Unify(YAP_ARG2, WinError())); } #else #if HAVE_GETHOSTNAME char name[256]; if (gethostname(name, 256) == -1) { /* return an error number */ return (YAP_Unify(YAP_ARG2, YAP_MkIntTerm(errno))); } #endif #endif /* defined(__MINGW32__) || _MSC_VER */ return (YAP_Unify(YAP_ARG1, YAP_MkAtomTerm(YAP_LookupAtom(name)))); }
static int win_exec(size_t len, const wchar_t *cmd, UINT show) { GET_LD STARTUPINFOW startup; PROCESS_INFORMATION info; int rval; wchar_t *wcmd; memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.wShowWindow = show; /* ensure 0-terminated */ wcmd = PL_malloc((len+1)*sizeof(wchar_t)); memcpy(wcmd, cmd, len*sizeof(wchar_t)); wcmd[len] = 0; rval = CreateProcessW(NULL, /* app */ wcmd, NULL, NULL, /* security */ FALSE, /* inherit handles */ 0, /* flags */ NULL, /* environment */ NULL, /* Directory */ &startup, &info); /* process info */ PL_free(wcmd); if ( rval ) { CloseHandle(info.hProcess); CloseHandle(info.hThread); succeed; } else { term_t tmp = PL_new_term_ref(); return ( PL_unify_wchars(tmp, PL_ATOM, len, cmd) && PL_error(NULL, 0, WinError(), ERR_SHELL_FAILED, tmp) ); } }
static int get_hsz(DWORD ddeInst, term_t data, HSZ *rval) { wchar_t *s; size_t len; if ( PL_get_wchars(data, &len, &s, CVT_ALL|CVT_EXCEPTION) ) { HSZ h; assert(s[len] == 0); /* Must be 0-terminated */ DEBUG(2, Sdprintf("Get HSZ for %Ws ...\n", s)); if ( (h=DdeCreateStringHandleW(ddeInst, s, CP_WINUNICODE)) ) { DEBUG(2, Sdprintf("\tHSZ = %p\n", h)); *rval = h; succeed; } return PL_error(NULL, 0, WinError(), ERR_SYSCALL, "DdeCreateStringHandleW"); } fail; }
/***************************************************************************** * GetCommState (USER.202) */ INT16 WINAPI GetCommState16(INT16 cid, LPDCB16 lpdcb) { struct DosDeviceStruct *ptr; DCB dcb; TRACE("cid %d, ptr %p\n", cid, lpdcb); if ((ptr = GetDeviceStruct(cid)) == NULL) { FIXME("no handle for cid = %0x!\n",cid); return -1; } if (!GetCommState(ptr->handle,&dcb)) { ptr->commerror = WinError(); return -1; } lpdcb->Id = cid; COMM16_DCBtoDCB16(&dcb,lpdcb); lpdcb->EvtChar = ptr->evtchar; ptr->commerror = 0; return 0; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int WINS_Init( void ){ int i; struct hostent *local; char buff[MAXHOSTNAMELEN]; struct sockaddr_s addr; char *p; /* linux doesn't have anything to initialize for the net "Windows .. built for the internet .. the internet .. built with unix" */ #if 0 WORD wVersionRequested; wVersionRequested = MAKEWORD( 2, 2 ); r = WSAStartup( wVersionRequested, &winsockdata ); if ( r ) { WinPrint( "Winsock initialization failed.\n" ); return -1; } #endif /* i = COM_CheckParm ("-udpport"); if (i == 0)*/ net_hostport = DEFAULTnet_hostport; /* else if (i < com_argc-1) net_hostport = Q_atoi (com_argv[i+1]); else Sys_Error ("WINS_Init: you must specify a number after -udpport"); */ // determine my name & address gethostname( buff, MAXHOSTNAMELEN ); local = gethostbyname( buff ); if(local && local->h_addr_list && local->h_addr_list[0]) myAddr = *(int *)local->h_addr_list[0]; else myAddr = inet_addr("127.0.0.1"); // if the quake hostname isn't set, set it to the machine name // if (Q_strcmp(hostname.string, "UNNAMED") == 0) { // see if it's a text IP address (well, close enough) for ( p = buff; *p; p++ ) if ( ( *p < '0' || *p > '9' ) && *p != '.' ) { break; } // if it is a real name, strip off the domain; we only want the host if ( *p ) { for ( i = 0; i < 15; i++ ) if ( buff[i] == '.' ) { break; } buff[i] = 0; } // Cvar_Set ("hostname", buff); } //++timo WTF is that net_controlsocket? it's sole purpose is to retrieve the local IP? if ( ( net_controlsocket = WINS_OpenSocket( 0 ) ) == SOCKET_ERROR ) { WinError( "WINS_Init: Unable to open control socket\n" ); } ( (struct sockaddr_in *)&broadcastaddr )->sin_family = AF_INET; ( (struct sockaddr_in *)&broadcastaddr )->sin_addr.s_addr = INADDR_BROADCAST; ( (struct sockaddr_in *)&broadcastaddr )->sin_port = htons( (u_short)net_hostport ); WINS_GetSocketAddr( net_controlsocket, &addr ); strcpy( my_tcpip_address, WINS_AddrToString( &addr ) ); p = strrchr( my_tcpip_address, ':' ); if ( p ) { *p = 0; } WinPrint( "Winsock Initialized\n" ); return net_controlsocket; } //end of the function WINS_Init
HANDLE WINAPI EXP_NAME(OpenPlugin)(int openFrom, INT_PTR item) { PCTSTR filePath; auto_ptr<wchar_t> cmdLine; auto_ptr<PluginPanelItem> panelItem; switch(openFrom) { case OPEN_COMMANDLINE: { if(!item) return INVALID_HANDLE_VALUE; #ifdef FAR3 cmdLine.reset(_wcsdup(((OpenCommandLineInfo*)item)->CommandLine)); filePath = cmdLine.get(); #else filePath = (PCTSTR)item; #endif if(!filePath || !*filePath) return INVALID_HANDLE_VALUE; if(*filePath == '\"') { PTSTR p1 = const_cast<PTSTR>(filePath) + _tcslen(filePath) - 1; if(*p1 == '\"') *p1 = 0; memmove(const_cast<PTSTR>(filePath), filePath + 1, (p1 - filePath + 1) * sizeof(TCHAR)); } } break; case OPEN_PLUGINSMENU: { //assert(item->) filePath = JsonPlugin::ClipboardName; /*panelItem.reset(GetCurrentItem()); panelItem->FileName; if(!filePath || !*filePath) return INVALID_HANDLE_VALUE;*/ } break; #ifdef FAR3 case OPEN_SHORTCUT: if(!item) return INVALID_HANDLE_VALUE; filePath = ((OpenShortcutInfo*)item)->HostFile; break; #endif default: return INVALID_HANDLE_VALUE; } //SaveScreen ss; //PCTSTR Items[]={_T(""),GetMsg(MLoading)}; //Message(0,NULL,Items,_countof(Items),0); // These command lines are possible: // file.json // c:\dir\file.json //??? http://site.com/url tstring sFilePath( #ifdef FAR3 openFrom == OPEN_SHORTCUT ? ((OpenShortcutInfo*)item)->HostFile : #endif filePath); tstring sSubDir; if(openFrom == OPEN_COMMANDLINE) { tstring sCommandLine(filePath); size_t colon = sCommandLine.find(':'); if(colon != tstring::npos) { tstring s1 = sCommandLine.substr(0, colon); if(GetFileAttributes(s1.c_str()) != 0xffffffff) { // file before 1st colon exists, get the rest sFilePath = s1; sSubDir = sCommandLine.substr(colon+1); } else { colon = sCommandLine.find(':', colon+1); sFilePath = sCommandLine.substr(0, colon); if(colon != tstring::npos) // second colon exists, get the rest sSubDir = sCommandLine.substr(colon+1); } } TCHAR absPath[MAX_PATH]; #ifdef UNICODE if(!wcschr(sFilePath.c_str(), ':')) // if rel path, convert it { StartupInfo.FSF->ConvertPath(CPM_FULL, sFilePath.c_str(), absPath, _countof(absPath)); #else if(GetFileAttributes(sFilePath.c_str()) != 0xffffffff) { // if local file exists, use its abs path _tfullpath(absPath, sFilePath.c_str(), _countof(absPath)); #endif sFilePath = absPath; } } JsonPlugin* plugin; try { plugin = new JsonPlugin(sFilePath.c_str()); } catch(WinExcept ex) { WinError(ex); return INVALID_HANDLE_VALUE; } if(plugin->HasParseError()) { auto error = plugin->GetParseError(); auto eroffs = plugin->GetErrorOffset(); delete plugin; tstring err(GetMsg(error + MParseErrorNone - kParseErrorNone)); err += '\n'; LPCTSTR err2 = GetMsg(MParseOffset); vector<TCHAR> err3(_tcslen(err2) + 20); _sntprintf(&err3[0], err3.size()-1, err2, eroffs); err3[err3.size()-1] = 0; err += &err3[0]; WinError(err.c_str()); return INVALID_HANDLE_VALUE; } if(!sSubDir.empty()) try { plugin->SetDirectory(sSubDir.c_str(),0); } catch(...) {} return plugin; } #ifdef FAR3 HANDLE WINAPI AnalyseW(const AnalyseInfo *info) { HANDLE h = OpenFilePluginW(info->FileName, (BYTE*)info->Buffer, (int)info->BufferSize, (int)info->OpMode); return h == INVALID_HANDLE_VALUE ? NULL : h; }
/***************************************************************************** * SetCommState (USER.201) */ INT16 WINAPI SetCommState16(LPDCB16 lpdcb) { struct DosDeviceStruct *ptr; DCB dcb; TRACE("cid %d, ptr %p\n", lpdcb->Id, lpdcb); if ((ptr = GetDeviceStruct(lpdcb->Id)) == NULL) { FIXME("no handle for cid = %0x!\n",lpdcb->Id); return -1; } memset(&dcb,0,sizeof(dcb)); dcb.DCBlength = sizeof(dcb); /* * according to MSDN, we should first interpret lpdcb->BaudRate as follows: * 1. if the baud rate is a CBR constant, interpret it. * 2. if it is greater than 57600, the baud rate is 115200 * 3. use the actual baudrate * steps 2 and 3 are equivalent to 16550 baudrate divisor = 115200/BaudRate */ switch(lpdcb->BaudRate) { case CBR_110: dcb.BaudRate = 110; break; case CBR_300: dcb.BaudRate = 300; break; case CBR_600: dcb.BaudRate = 600; break; case CBR_1200: dcb.BaudRate = 1200; break; case CBR_2400: dcb.BaudRate = 2400; break; case CBR_4800: dcb.BaudRate = 4800; break; case CBR_9600: dcb.BaudRate = 9600; break; case CBR_14400: dcb.BaudRate = 14400; break; case CBR_19200: dcb.BaudRate = 19200; break; case CBR_38400: dcb.BaudRate = 38400; break; case CBR_56000: dcb.BaudRate = 56000; break; case CBR_128000: dcb.BaudRate = 128000; break; case CBR_256000: dcb.BaudRate = 256000; break; default: if(lpdcb->BaudRate>57600) dcb.BaudRate = 115200; else dcb.BaudRate = lpdcb->BaudRate; } dcb.ByteSize=lpdcb->ByteSize; dcb.StopBits=lpdcb->StopBits; dcb.fParity=lpdcb->fParity; dcb.Parity=lpdcb->Parity; dcb.fOutxCtsFlow = lpdcb->fOutxCtsFlow; if (lpdcb->fDtrflow || lpdcb->fRtsflow) dcb.fRtsControl = TRUE; if (lpdcb->fDtrDisable) dcb.fDtrControl = TRUE; ptr->evtchar = lpdcb->EvtChar; dcb.fInX = lpdcb->fInX; dcb.fOutX = lpdcb->fOutX; if (!SetCommState(ptr->handle,&dcb)) { ptr->commerror = WinError(); return -1; } else { ptr->commerror = 0; return 0; } }
/* execute a command as a detached process */ static YAP_Bool execute_command(void) { YAP_Term ti = YAP_ARG2, to = YAP_ARG3, te = YAP_ARG4; int res; YAP_Term AtomNull = YAP_MkAtomTerm(YAP_LookupAtom("null")); #if defined(__MINGW32__) || _MSC_VER HANDLE inpf, outf, errf; DWORD CreationFlags = 0; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInformation; inpf = get_handle(ti, STD_INPUT_HANDLE); if (inpf == INVALID_HANDLE_VALUE) { return (YAP_Unify(YAP_ARG6, WinError())); } outf = get_handle(to, STD_OUTPUT_HANDLE); if (outf == INVALID_HANDLE_VALUE) { close_handle(ti, inpf); return (YAP_Unify(YAP_ARG6, WinError())); } errf = get_handle(te, STD_OUTPUT_HANDLE); if (errf == INVALID_HANDLE_VALUE) { close_handle(ti, inpf); close_handle(to, outf); return (YAP_Unify(YAP_ARG6, WinError())); } if (!YAP_IsIntTerm(ti) && !YAP_IsIntTerm(to) && !YAP_IsIntTerm(te)) { /* we do not keep a current stream */ CreationFlags = DETACHED_PROCESS; } StartupInfo.cb = sizeof(STARTUPINFO); StartupInfo.lpReserved = NULL; StartupInfo.lpDesktop = NULL; /* inherit */ StartupInfo.lpTitle = NULL; /* we do not create a new console window */ StartupInfo.dwFlags = STARTF_USESTDHANDLES; StartupInfo.cbReserved2 = 0; StartupInfo.lpReserved2 = NULL; StartupInfo.hStdInput = inpf; StartupInfo.hStdOutput = outf; StartupInfo.hStdError = errf; /* got stdin, stdout and error as I like it */ if (CreateProcess(NULL, (char *)YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)), NULL, NULL, TRUE, CreationFlags, NULL, NULL, &StartupInfo, &ProcessInformation) == FALSE) { close_handle(ti, inpf); close_handle(to, outf); close_handle(te, errf); return (YAP_Unify(YAP_ARG6, WinError())); } close_handle(ti, inpf); close_handle(to, outf); close_handle(te, errf); res = ProcessInformation.dwProcessId; return (YAP_Unify(YAP_ARG5, YAP_MkIntTerm(res))); #else /* UNIX CODE */ int inpf, outf, errf; /* process input first */ if (ti == AtomNull) { inpf = open("/dev/null", O_RDONLY); } else { int sd; if (YAP_IsIntTerm(ti)) sd = YAP_IntOfTerm(ti); else sd = YAP_StreamToFileNo(ti); if (sd == 0) inpf = 0; else inpf = dup(sd); } if (inpf < 0) { /* return an error number */ return (YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno))); } /* then output stream */ if (to == AtomNull) { outf = open("/dev/zero", O_WRONLY); } else { int sd; if (YAP_IsIntTerm(to)) sd = YAP_IntOfTerm(to); else sd = YAP_StreamToFileNo(to); if (sd == 1) outf = 1; else outf = dup(sd); } if (outf < 0) { /* return an error number */ if (inpf != 0) close(inpf); return (YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno))); } /* then error stream */ if (te == AtomNull) { errf = open("/dev/zero", O_WRONLY); } else { int sd; if (YAP_IsIntTerm(te)) sd = YAP_IntOfTerm(te); else sd = YAP_StreamToFileNo(te); if (sd == 2) errf = 2; else errf = dup(sd); } if (errf < 0) { /* return an error number */ if (inpf != 0) close(inpf); if (outf != 1) close(outf); return (YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno))); } YAP_FlushAllStreams(); /* we are now ready to fork */ if ((res = fork()) < 0) { /* close streams we don't need */ if (inpf != 0) close(inpf); if (outf != 1) close(outf); if (errf != 2) close(errf); /* return an error number */ return (YAP_Unify(YAP_ARG6, YAP_MkIntTerm(errno))); } else if (res == 0) { char *argv[4]; /* child */ /* close current streams, but not std streams */ YAP_CloseAllOpenStreams(); if (inpf != 0) { close(0); if (dup(inpf) != 0) exit(1); close(inpf); } if (outf != 1) { close(1); if (dup(outf) != 1) exit(1); close(outf); } if (errf != 2) { close(2); if (dup(errf) != 2) exit(2); close(errf); } argv[0] = "sh"; argv[1] = "-c"; argv[2] = (char *)YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1)); argv[3] = NULL; execv("/bin/sh", argv); exit(127); /* we have the streams where we want them, just want to execute now */ } else { if (inpf != 0) close(inpf); if (outf != 1) close(outf); if (errf != 2) close(errf); return (YAP_Unify(YAP_ARG5, YAP_MkIntTerm(res))); } #endif /* UNIX code */ }
int YMSPlugin::WinError(DWORD error) { if(error) ::SetLastError(error); return WinError(); }