extern "C" int close(int fd) { if (dmtcp::ProtectedFDs::isProtected(fd)) { JTRACE("blocked attempt to close protected fd") (fd); errno = EBADF; return -1; } #ifdef EXTERNAL_SOCKET_HANDLING dmtcp::ConnectionIdentifier conId; if (dmtcp::WorkerState::currentState() == dmtcp::WorkerState::RUNNING && dmtcp::DmtcpWorker::waitingForExternalSocketsToClose() == true && dup2(fd,fd) != -1) { conId = dmtcp::KernelDeviceToConnection::instance().retrieve(fd).id(); } int rv = _real_close(fd); if (rv == 0) { processClose(conId); } #else int rv = _real_close(fd); #endif return rv; }
void closeAll() { if(processedProgram != NULL) free(processedProgram); if(stack != NULL) free(stack); processClose(); }
void process(FILE * file) { processedProgramMaxSize = PROCESSED_PROGRAM_BLOCK; processedProgram = (char *) malloc(processedProgramMaxSize * sizeof(char)); if(processedProgram == NULL) { error("Couldn't allocate preprocess memory!\n"); return; } processedProgramSize = 0; whitespace = TRUE; lineIsEmpty = TRUE; processedProgramStream(¤tOutStream); processFile(file); processAddChar(0); processClose(); }
bool processXml(FastXmlInterface *iface) { bool ret = true; #define MAX_ATTRIBUTE 2048 // can't imagine having more than 2,048 attributes in a single element right? mLineNo = 1; char *element; char *scan = mInputData; if ( *scan == '<' ) { scan++; while ( *scan ) { scan = skipNextData(scan); if ( *scan == 0 ) return ret; if ( *scan == '<' ) { scan++; } if ( *scan == '/' || *scan == '?' ) { while ( *scan && *scan != '>' ) scan++; scan++; } else { element = scan; NxI32 argc = 0; const char *argv[MAX_ATTRIBUTE]; bool close; scan = nextSoftOrClose(scan,close); if ( close ) { char c = *(scan-1); if ( c != '?' && c != '/' ) { c = '>'; } *scan = 0; scan++; scan = processClose(c,element,scan,argc,argv,iface); if ( !scan ) return false; } else { if ( *scan == 0 ) return ret; *scan = 0; // place a zero byte to indicate the end of the element name... scan++; while ( *scan ) { scan = skipNextData(scan); // advance past any soft seperators (tab or space) if ( mTypes[*scan] == CT_END_OF_ELEMENT ) { char c = *scan++; scan = processClose(c,element,scan,argc,argv,iface); if ( !scan ) return false; break; } else { if ( argc >= MAX_ATTRIBUTE ) { mError = "encountered too many attributes"; return false; } argv[argc] = scan; scan = nextSep(scan); // scan up to a space, or an equal if ( *scan ) { if ( *scan != '=' ) { *scan = 0; scan++; while ( *scan && *scan != '=' ) scan++; if ( *scan == '=' ) scan++; } else { *scan=0; scan++; } if ( *scan ) // if not eof... { scan = skipNextData(scan); if ( *scan == 34 ) { scan++; argc++; argv[argc] = scan; argc++; while ( *scan && *scan != 34 ) scan++; if ( *scan == 34 ) { *scan = 0; scan++; } else { mError = "Failed to find closing quote for attribute"; return false; } } else { //mError = "Expected quote to begin attribute"; //return false; // PH: let's try to have a more graceful fallback argc--; while (*scan != '/' && *scan != '>' && *scan != 0) scan++; } } } } } } } } } else { mError = "Expected the start of an element '<' at this location."; ret = false; // unexpected character!? } return ret; }