void XmlDocument::readQuotedString (String& result) { const juce_wchar quote = readNextChar(); while (! outOfData) { const juce_wchar c = readNextChar(); if (c == quote) break; --input; if (c == '&') { readEntity (result); } else { const String::CharPointerType start (input); for (;;) { const juce_wchar character = *input; if (character == quote) { result.appendCharPointer (start, input); ++input; return; } else if (character == '&') { result.appendCharPointer (start, input); break; } else if (character == 0) { outOfData = true; setLastError ("unmatched quotes", false); break; } ++input; } } } }
int readValueFromFile(char* fileName, char* buff, int len) { clearLastError(); int ret = -1; FILE *fp = fopen(fileName,"r"); if (fp == NULL) { setLastError("Unable to open file %s",fileName); return -1; } else { if (fread(buff, sizeof(char), len, fp)>0) { ret = 0; } } fclose(fp); return ret; }
NOINLINE_DECL void verifyFailed(const char *msg, const char *file, unsigned line) { assertionCount.condrollover( ++assertionCount.regular ); problem() << "Assertion failure " << msg << ' ' << file << ' ' << dec << line << endl; logContext(); setLastError(0,msg && *msg ? msg : "assertion failure"); stringstream temp; temp << "assertion " << file << ":" << line; AssertionException e(temp.str(),0); breakpoint(); #if defined(_DEBUG) || defined(_DURABLEDEFAULTON) || defined(_DURABLEDEFAULTOFF) // this is so we notice in buildbot log() << "\n\n***aborting after verify() failure as this is a debug/test build\n\n" << endl; abort(); #endif throw e; }
Status WriteCmd::checkAuthForCommand( ClientBasic* client, const std::string& dbname, const BSONObj& cmdObj ) { Status status( auth::checkAuthForWriteCommand( client->getAuthorizationSession(), _writeType, NamespaceString( parseNs( dbname, cmdObj ) ), cmdObj )); // TODO: Remove this when we standardize GLE reporting from commands if ( !status.isOK() ) { setLastError( status.code(), status.reason().c_str() ); } return status; }
bool QSQLite2Driver::rollbackTransaction() { if (!isOpen() || isOpenError()) return false; char* err; int res = sqlite_exec(d->access, "ROLLBACK", 0, this, &err); if (res == SQLITE_OK) return true; setLastError(QSqlError(tr("Unable to rollback transaction"), QString::fromAscii(err), QSqlError::TransactionError, res)); sqlite_freemem(err); return false; }
EXPORT void Hcsr04DeInit() { clearLastError(); struct HCSR04_resource res; res.gpio = -1; char *hcsr04Path = (char *) malloc(FILE_PATH_LENGTH); memset(hcsr04Path, 0, FILE_PATH_LENGTH); strcpy(hcsr04Path, HCSR04_PATH); char *resStr = (char *)&res; if (Hcsr04Write(hcsr04Path, resStr) == -1) { setLastError("Fail to write resource to hcsr04"); } free(hcsr04Path); }
//Send a block of data to the FPGA, raise the execution signal, wait for the execution // signal to be lowered, then read back up to values of results // startAddress: local address on FPGA input buffer to begin writing at // length: # of bytes to write // inData: data to be sent to FPGA // maxWaitTime: # of seconds to wait until execution timeout // outData: readback data buffer (if function returns successfully) // maxOutLength: maximum length of outData buffer provided // outputLength: number of bytes actually returned (if function returns successfully) // Returns true if entire process is successful. // If function fails for any reason, returns false. // Check error code with getLastError(). // error == FAILCAPACITY: The output was larger than provided buffer. Rather than the number of // bytes actually returned, the outputLength variable will contain the TOTAL number bytes the // function wanted to return (the number of bytes actually returned will be maxOutLength). // If this occurs, user should read back bytes {maxOutLength, outputLength - 1} manually // with a subsequent sendRead command. // error == FAILREADACK: The write and execution phases completed correctly, but we retried // the readback phase too many times. In this case, like the FAILCAPICITY error, outputLength // will contain the TOTAL number bytes the function wanted to return. The state of outData is unknown, // but some data has been partially written. The user could try calling sendRead // from {0, outputLength-1} manually if re-calling sendWriteAndRun is not easy // (for example, if inData and outData overlapped). // error == anything else: see normal error list BOOL PICO_SIRC::sendWriteAndRun(uint32_t startAddress, uint32_t inLength, uint8_t *inData, uint32_t maxWaitTimeInMsec, uint8_t *outData, uint32_t maxOutLength, uint32_t *outputLength) { setLastError( 0); //Check the input parameters if(!inData){ setLastError( INVALIDBUFFER); return false; } if(startAddress > OUTPUT_OFFSET){ setLastError( INVALIDADDRESS); return false; } if(inLength == 0 || startAddress + inLength > OUTPUT_OFFSET){ setLastError( INVALIDLENGTH); return false; } //Check the output parameters if(!outData){ setLastError( INVALIDBUFFER); return false; } if(maxOutLength == 0 || maxOutLength > OUTPUT_OFFSET){ setLastError( INVALIDLENGTH); return false; } //Send the data to the FPGA if (!sendWrite(startAddress,inLength,inData)){ return false; } //Send the run cmd if (!sendRun()){ return false; } //Wait till done if (!waitDone( maxWaitTimeInMsec)){ return false; } //Read back data //BUGBUG what about partial results?? if (!sendRead(0,maxOutLength,outData)){ return false; } *outputLength = maxOutLength; //and done return true; }
static int posix_close(SgObject self) { if (SG_FD(self)->fd == 0 || SG_FD(self)->fd == 1 || SG_FD(self)->fd == 2) { /* we never close standard fd */ return TRUE; } if (SG_FILE_VTABLE(self)->isOpen(self)) { const int isOK = close(SG_FD(self)->fd) != 0; setLastError(self); SG_FD(self)->fd = INVALID_HANDLE_VALUE; return isOK; } return FALSE; }
bool CExporter::exportMesh(const std::wstring& strFilename) { checkMeshExpType(); if (!buildMesh()) { return false; } for (DWORD i = 0; i < m_meshes.size(); ++i) { grp::MeshExporter* mesh = m_meshes[i]; if (mesh == NULL) { continue; } std::wstring strFilePath = strFilename; if (m_meshes.size() > 1) { strFilePath += L"_"; strFilePath += mesh->getName(); } strFilePath += FILE_EXT_MESH_SKIN; std::fstream file; file.open(strFilePath.c_str(), std::ios_base::out | std::ios_base::binary); if (!file.is_open()) { char szError[1024]; ::StringCchPrintf(szError, sizeof(szError), "Failed to open file [%s]", strFilePath.c_str()); setLastError(szError); return false; } if (!mesh->exportTo(file, (m_options.exportType & EXP_MESH_COMPRESS_POS) != 0, (m_options.exportType & EXP_MESH_COMPRESS_NORMAL) != 0, (m_options.exportType & EXP_MESH_COMPRESS_TEXCOORD) != 0, (m_options.exportType & EXP_MESH_COMPRESS_WEIGHT) != 0)) { file.close(); return false; } file.close(); } return true; }
/* * Enter/exit with stream mutex held. * On error, does not hold the stream mutex. */ static jint waitForData(SharedMemoryConnection *connection, Stream *stream) { jint error = SYS_OK; /* Assumes mutex is held on call */ while ((error == SYS_OK) && EMPTY(stream)) { CHECK_ERROR(leaveMutex(stream)); error = sysEventWait(connection->otherProcess, stream->hasData, 0); if (error == SYS_OK) { CHECK_ERROR(enterMutex(stream, connection->shutdown)); } else { setLastError(error); } } return error; }
void SpadesLogParser::parseErrOutput(const QString &partOfLog){ lastPartOfLog=partOfLog.split(QRegExp("(\n|\r)")); lastPartOfLog.first()=lastErrLine+lastPartOfLog.first(); lastErrLine=lastPartOfLog.takeLast(); foreach(QString buf, lastPartOfLog){ if(buf.contains("== Error == ") || buf.contains(" ERROR ")){ coreLog.error("Spades: " + buf); setLastError(buf); }else if (buf.contains("== Warning == ") || buf.contains(" WARN ")){ algoLog.info(buf); }else { algoLog.trace(buf); } } }
void Win32RedBookDevice::closeVolume() { setLastError(""); if(!mVolumeInitialized) return; if(mUsingMixer) { mMixerVolumeValue.dwValue = mOriginalVolume; mixerSetControlDetails(mVolumeDeviceId, &mMixerVolumeDetails, MIXER_SETCONTROLDETAILSF_VALUE); mixerClose((HMIXER)mVolumeDeviceId); } else auxSetVolume(mAuxVolumeDeviceId, mOriginalVolume); mVolumeInitialized = false; }
bool QSQLite2Driver::commitTransaction() { Q_D(QSQLite2Driver); if (!isOpen() || isOpenError()) return false; char* err; int res = sqlite_exec(d->access, "COMMIT", 0, this, &err); if (res == SQLITE_OK) return true; setLastError(QSqlError(tr("Unable to commit transaction"), QString::fromLatin1(err), QSqlError::TransactionError, res)); sqlite_freemem(err); return false; }
bool QMYSQLDriver::rollbackTransaction() { #ifndef CLIENT_TRANSACTIONS return FALSE; #endif if ( !isOpen() ) { #ifdef QT_CHECK_RANGE qWarning( "QMYSQLDriver::rollbackTransaction: Database not open" ); #endif return FALSE; } if ( mysql_query( d->mysql, "ROLLBACK" ) ) { setLastError( qMakeError("Unable to rollback transaction", QSqlError::Statement, d ) ); return FALSE; } return TRUE; }
//某文件是否是加密后zip文件 bool isEncryptedZipFile(const char* szFileName) { extern DWORD g_arrdwCrc32Table[256]; //打开文件 HANDLE hFile = ::CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_SEQUENTIAL_SCAN, 0); if(hFile == INVALID_HANDLE_VALUE) { setLastError(AXP_ERR_FILE_ACCESS, "File=%s, WinErr=%d", szFileName, ::GetLastError()); return false; } //Get File Size unsigned int nFileSize = ::GetFileSize(hFile, 0); //文件太小 if(nFileSize <= 2 ) { ::CloseHandle(hFile); return false; } unsigned char temp[8]; DWORD bytesReaded; ::ReadFile(hFile, temp, 2, &bytesReaded, 0); ::CloseHandle(hFile); // BYTE _1 = getZipEncryptXORKey(0); // BYTE _2 = getZipEncryptXORKey(1); // temp[0] ^ getZipEncryptXORKey(0) if( 'P' == (temp[0] ^ getZipEncryptXORKey(0))&& 'K' == (temp[1] ^ getZipEncryptXORKey(1)) ) { return true; } return false; }
int Sg_LockFile(SgObject file, enum SgFileLockType mode) { struct flock fl; int cmd = F_SETLKW; /* we lock the whole file */ fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; fl.l_type = F_RDLCK; /* default */ if (mode & SG_EXCLUSIVE) fl.l_type = F_WRLCK; if (mode & SG_DONT_WAIT) cmd = F_SETLK; if (fcntl(SG_FD(file)->fd, cmd, &fl)) { setLastError(file); return FALSE; } return TRUE; }
void QTrackerDirectSyncResult::waitForFinished() { if (queryRunner && isAsync) { driverPrivate->waitForConnectionOpen(); if (!driverPrivate->driver->isOpen()) { setLastError(QSparqlError(driverPrivate->error, QSparqlError::ConnectionError)); terminate(); return; } //if we can acquire the semaphore then run fetcher directly //if we can't then fetcher is in the threadpool, so we wait //for it to complete queryRunner->runOrWait(); } }
CIMIPlugin* CIMIPluginManager::createPlugin(std::string filename, TPluginTypeEnum pluginType) { std::stringstream error; clearLastError(); switch (pluginType) { case CIMI_PLUGIN_PYTHON: return new CIMIPythonPlugin(filename); case CIMI_PLUGIN_UNKNOWN: default: error << "Cannot detect type for " << filename; setLastError(error.str()); return NULL; } }
bool QPSQLDriver::open(const QString & db, const QString & user, const QString & password, const QString & host, int port, const QString& connOpts) { if (isOpen()) close(); QString connectString; if (!host.isEmpty()) connectString.append(QLatin1String("host=")).append(qQuote(host)); if (!db.isEmpty()) connectString.append(QLatin1String(" dbname=")).append(qQuote(db)); if (!user.isEmpty()) connectString.append(QLatin1String(" user="******" password="******" port=")).append(qQuote(QString::number(port))); // add any connect options - the server will handle error detection if (!connOpts.isEmpty()) { QString opt = connOpts; opt.replace(QLatin1Char(';'), QLatin1Char(' '), Qt::CaseInsensitive); connectString.append(QLatin1Char(' ')).append(opt); } d->connection = PQconnectdb(connectString.toLocal8Bit().constData()); if (PQstatus(d->connection) == CONNECTION_BAD) { setLastError(qMakeError(tr("Unable to connect"), QSqlError::ConnectionError, d)); setOpenError(true); PQfinish(d->connection); d->connection = 0; return false; } d->pro = getPSQLVersion(d->connection); d->isUtf8 = setEncodingUtf8(d->connection); setDatestyle(d->connection); setOpen(true); setOpenError(false); return true; }
//------------------------------------------------------------------------------ bool UnixRedBookDevice::getTrackCount(U32 * numTracks) { #if !defined(__FreeBSD__) if(!mAcquired) { setLastError("Device has not been acquired"); return(false); } if (!updateStatus()) return false; AssertFatal(mCD, "mCD is NULL"); *numTracks = mCD->numtracks; return(true); #endif // !defined(__FreeBSD__) }
bool FileWriter::open() { bool result = true; if (isCorrectFileName()) { _fileStream.open(_fileName, ios::out); if (!_fileStream.is_open()) { setLastError(kFileWriterErrorCantOpenFile); result = false; } } else { result = false; } return result; }
EXPORT int Hcsr04Init(int Pin) { clearLastError(); struct HCSR04_resource res; int ret = HCSR04_MAX_DISTANCE+1; char *hcsr04Path = (char *) malloc(FILE_PATH_LENGTH); memset(hcsr04Path, 0, FILE_PATH_LENGTH); strcpy(hcsr04Path, HCSR04_PATH); res.gpio = pintoGPIO(Pin); char *resStr = (char *)&res; if (Hcsr04Write(hcsr04Path, resStr) == -1) { setLastError("Fail to write resource to hcsr04"); ret = -1; } free(hcsr04Path); return ret; }
HLInst* X86Compiler::newInst(uint32_t code, const Operand& o0) { size_t size = X86Compiler_getInstSize(code); HLInst* inst = static_cast<HLInst*>(_zoneAllocator.alloc(size + 1 * sizeof(Operand))); if (inst == NULL) goto _NoMemory; { Operand* opList = reinterpret_cast<Operand*>(reinterpret_cast<uint8_t*>(inst) + size); opList[0] = o0; ASMJIT_ASSERT_OPERAND(o0); return X86Compiler_newInst(this, inst, code, getInstOptionsAndReset(), opList, 1); } _NoMemory: setLastError(kErrorNoHeapMemory); return NULL; }
jint shmemBase_attach(const char *addressString, long timeout, SharedMemoryConnection **connectionPtr) { int error; SharedMemoryTransport *transport; jlong acceptingPID; clearLastError(); error = openTransport(addressString, &transport); if (error != SYS_OK) { return error; } /* lock transport - no additional event to wait on as no connection yet */ error = sysIPMutexEnter(transport->mutex, NULL); if (error != SYS_OK) { setLastError(error); closeTransport(transport); return error; } if (transport->shared->isListening) { error = doAttach(transport, timeout); if (error == SYS_OK) { acceptingPID = transport->shared->acceptingPID; } } else { /* Not listening: error */ error = SYS_ERR; } sysIPMutexExit(transport->mutex); if (error != SYS_OK) { closeTransport(transport); return error; } error = openConnection(transport, acceptingPID, connectionPtr); closeTransport(transport); return error; }
/** * @param loc the location in system.indexes where the index spec is */ void NOINLINE_DECL insert_makeIndex(Collection* collectionToIndex, const DiskLoc& loc, bool mayInterrupt) { uassert(13143, "can't create index on system.indexes", collectionToIndex->ns().coll() != "system.indexes"); BSONObj info = loc.obj(); std::string idxName = info["name"].valuestr(); // Set curop description before setting indexBuildInProg, so that there's something // commands can find and kill as soon as indexBuildInProg is set. Only set this if it's a // killable index, so we don't overwrite commands in currentOp. if (mayInterrupt) { cc().curop()->setQuery(info); } IndexCatalog::IndexBuildBlock indexBuildBlock( collectionToIndex->getIndexCatalog(), idxName, loc ); verify( indexBuildBlock.indexDetails() ); try { buildAnIndex( collectionToIndex->ns(), collectionToIndex->details(), *indexBuildBlock.indexDetails(), mayInterrupt); indexBuildBlock.success(); } catch (DBException& e) { // save our error msg string as an exception or dropIndexes will overwrite our message LastError *le = lastError.get(); int savecode = 0; string saveerrmsg; if ( le ) { savecode = le->code; saveerrmsg = le->msg; } else { savecode = e.getCode(); saveerrmsg = e.what(); } verify(le && !saveerrmsg.empty()); setLastError(savecode,saveerrmsg.c_str()); throw; } }
static int64_t posix_seek(SgObject self, int64_t offset, SgWhence whence) { int w = SEEK_SET; int64_t ret; switch (whence) { case SG_BEGIN: w = SEEK_SET; break; case SG_CURRENT: w = SEEK_CUR; break; case SG_END: w = SEEK_END; break; } ret = lseek(SG_FD(self)->fd, offset, w); setLastError(self); return ret; }
bool LanguageSelection::loadTranslations(const TranslationInfoList& translations) { unloadTranslations(); resizeTranslatorsList(translations.count()); for(int i=0; i < translations.count(); ++i){ if( mTranslators[i]->load(translations.at(i).absoluteFilePath()) ){ QCoreApplication::installTranslator(mTranslators[i].get()); }else{ const auto msg = tr("Could not load translation file '%1'.") .arg(translations.at(i).fullFileName()); auto error = mdtErrorNewQ(msg, Mdt::Error::Warning, this); setLastError(error); qWarning() << QLatin1String("Mdt::Translation::LanguageSelection::loadTranslations(): ") << msg; //error.commit(); Error logger will crash (because logging is not enabled, have to fix it in Mdt::Error) } } return true; }
bool embeddedResult::fetch(int i) { if(!d->driver) return false; if (isForwardOnly()) { // fake a forward seek if (at() < i) { int x = i - at(); while (--x && fetchNext()) {}; return fetchNext(); } else { return false; } } if (at() == i) return true; if (d->preparedQuery) { #if MYSQL_VERSION_ID >= 40108 mysql_stmt_data_seek(d->stmt, i); int nRC = mysql_stmt_fetch(d->stmt); if (nRC) { #ifdef MYSQL_DATA_TRUNCATED if (nRC == 1 || nRC == MYSQL_DATA_TRUNCATED) #else if (nRC == 1) #endif setLastError(qMakeStmtError(QCoreApplication::translate("embeddedResult", "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } #else return false; #endif } else { mysql_data_seek(d->result, i); d->row = mysql_fetch_row(d->result); if (!d->row) return false; } setAt(i); return true; }
QSharedPointer<QObject> QpDaoBase::readObject(int id) const { QSharedPointer<QObject> p = d->cache.get(id); if(p) return p; QObject *object = createInstance(); if(!d->sqlDataAccessObjectHelper->readObject(d->metaObject, id, object)) { setLastError(d->sqlDataAccessObjectHelper->lastError()); delete object; return QSharedPointer<QObject>(); } QSharedPointer<QObject> obj = d->cache.insert(Qp::Private::primaryKey(object), object); Qp::Private::enableSharedFromThis(obj); return obj; }
/* Execute \a query. */ bool QSQLite2Result::reset (const QString& query) { // this is where we build a query. if (!driver()) return false; if (!driver()-> isOpen() || driver()->isOpenError()) return false; d->cleanup(); // Um, ok. callback based so.... pass private static function for this. setSelect(false); char *err = 0; int res = sqlite_compile(d->access, d->utf8 ? query.toUtf8().constData() : query.toAscii().constData(), &(d->currentTail), &(d->currentMachine), &err); if (res != SQLITE_OK || err) { setLastError(QSqlError(QCoreApplication::translate("QSQLite2Result", "Unable to execute statement"), QString::fromAscii(err), QSqlError::StatementError, res)); sqlite_freemem(err); } //if (*d->currentTail != '\000' then there is more sql to eval if (!d->currentMachine) { setActive(false); return false; } // we have to fetch one row to find out about // the structure of the result set d->skippedStatus = d->fetchNext(d->firstRow, 0, true); if (lastError().isValid()) { setSelect(false); setActive(false); return false; } setSelect(!d->rInf.isEmpty()); setActive(true); return true; }