bool mozilla::ReadSysFile( const char* aFilename, char* aBuf, size_t aBufSize) { int fd = MOZ_TEMP_FAILURE_RETRY(open(aFilename, O_RDONLY)); if (fd < 0) { return false; } ScopedClose autoClose(fd); if (aBufSize == 0) { return true; } ssize_t bytesRead; size_t offset = 0; do { bytesRead = MOZ_TEMP_FAILURE_RETRY( read(fd, aBuf + offset, aBufSize - offset)); if (bytesRead == -1) { return false; } offset += bytesRead; } while (bytesRead > 0 && offset < aBufSize); MOZ_ASSERT(offset <= aBufSize); if (offset > 0 && aBuf[offset - 1] == '\n') { offset--; } if (offset == aBufSize) { MOZ_ASSERT(offset > 0); offset--; } aBuf[offset] = '\0'; return true; }
void TermWidget::konsoleDestroyed() { m_pKonsoleWidget = 0; m_pKonsolePart = 0; hide(); QTimer::singleShot(0,this,SLOT(autoClose())); }
void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions ) { FILE* fp = fopen( filename.c_str() , "rb" ); AutoCloseFile autoClose( fp ); Dali::Integration::Bitmap* bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); Dali::Integration::BitmapPtr bitmapPtr( bitmap ); Dali::ImageAttributes attributes; DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); FILE* writeFp = fopen( targetFilename.c_str(), "wb" ); AutoCloseFile autoCloseWrite( writeFp ); fwrite( bufferPtr, sizeof( Dali::PixelBuffer ), attributes.GetWidth() * attributes.GetHeight(), writeFp ); }
PrintDialog::PrintDialog(QWidget *parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), firmware(firmware), generalSettings(generalSettings), model(model), printfilename(filename), ui(new Ui::PrintDialog), multimodelprinter(firmware) { ui->setupUi(this); setWindowIcon(CompanionIcon("print.png")); setWindowTitle(model.name); multimodelprinter.setModel(0, model); ui->textEdit->setHtml(multimodelprinter.print(ui->textEdit->document())); if (!printfilename.isEmpty()) { printToFile(); QTimer::singleShot(0, this, SLOT(autoClose())); } }
static bool ReadSysFile(const char *aFilename, char *aBuf, size_t aBufSize) { int fd = open(aFilename, O_RDONLY); if (fd < 0) { ERR("Unable to open file '%s' for reading", aFilename); return false; } ScopedClose autoClose(fd); ssize_t bytesRead = read(fd, aBuf, aBufSize - 1); if (bytesRead < 0) { ERR("Unable to read from file '%s'", aFilename); return false; } if (aBuf[bytesRead - 1] == '\n') { bytesRead--; } aBuf[bytesRead] = '\0'; return true; }
void AdjustSystemClock(int64_t aDeltaMilliseconds) { int fd; struct timespec now; if (aDeltaMilliseconds == 0) { return; } // Preventing context switch before setting system clock sched_yield(); clock_gettime(CLOCK_REALTIME, &now); now.tv_sec += (time_t)(aDeltaMilliseconds / 1000LL); now.tv_nsec += (long)((aDeltaMilliseconds % 1000LL) * NsecPerMsec); if (now.tv_nsec >= NsecPerSec) { now.tv_sec += 1; now.tv_nsec -= NsecPerSec; } if (now.tv_nsec < 0) { now.tv_nsec += NsecPerSec; now.tv_sec -= 1; } do { fd = open("/dev/alarm", O_RDWR); } while (fd == -1 && errno == EINTR); ScopedClose autoClose(fd); if (fd < 0) { HAL_LOG(("Failed to open /dev/alarm: %s", strerror(errno))); return; } if (ioctl(fd, ANDROID_ALARM_SET_RTC, &now) < 0) { HAL_LOG(("ANDROID_ALARM_SET_RTC failed: %s", strerror(errno))); return; } hal::NotifySystemTimeChange(hal::SYS_TIME_CHANGE_CLOCK); }
void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions ) { FILE* fp = fopen( image.name.c_str() , "rb" ); AutoCloseFile autoClose( fp ); DALI_TEST_CHECK( fp != NULL ); // Check the header file. unsigned int width(0), height(0); Dali::ImageAttributes attributes; DALI_TEST_CHECK( functions.header( fp, attributes, width, height ) ); DALI_TEST_EQUALS( width, image.reportedWidth, TEST_LOCATION ); DALI_TEST_EQUALS( height, image.reportedHeight, TEST_LOCATION ); // Loading the header moves the pointer within the file so reset to start of file. fseek( fp, 0, 0 ); // Create a bitmap object and store a pointer to that object so it is destroyed at the end. Dali::Integration::Bitmap * bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); Dali::Integration::BitmapPtr bitmapPtr( bitmap ); // Load Bitmap and check its return values. DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); DALI_TEST_EQUALS( image.width, attributes.GetWidth(), TEST_LOCATION ); DALI_TEST_EQUALS( image.height, attributes.GetHeight(), TEST_LOCATION ); // Compare buffer generated with reference buffer. Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); Dali::PixelBuffer* refBufferPtr( image.refBuffer ); for ( unsigned int i = 0; i < image.refBufferSize; ++i, ++bufferPtr, ++refBufferPtr ) { if( *bufferPtr != *refBufferPtr ) { tet_result( TET_FAIL ); tet_printf("%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); break; } } }