int f$fseek (const MyFile &file, int offset, int whence) { if (eq2 (file, STDOUT) || eq2 (file, STDERR)) { php_warning ("Can't use fseek with STDERR and STDOUT\n"); return -1; } const static int whences[3] = {SEEK_SET, SEEK_END, SEEK_CUR}; if ((unsigned int)whence >= 3u) { php_warning ("Wrong parameter whence in function fseek\n"); return -1; } whence = whences[whence]; OrFalse <string> filename_or_false = full_realpath (file.to_string()); if (!f$boolval (filename_or_false)) { php_warning ("Wrong file \"%s\" specified", file.to_string().c_str()); return -1; } string filename = filename_or_false.val(); if (dl::query_num == opened_files_last_query_num && opened_files->has_key (filename)) { FILE *f = opened_files->get_value (filename); dl::enter_critical_section();//OK int res = fseek (f, (long)offset, whence); dl::leave_critical_section(); return res; } else { php_warning ("File \"%s\" is not opened\n", filename.c_str()); return -1; } }
OrFalse <int> f$fpassthru (const MyFile &file) { if (eq2 (file, STDOUT) || eq2 (file, STDERR)) { php_warning ("Can't use fpassthru with STDERR and STDOUT\n"); return false; } OrFalse <string> filename_or_false = full_realpath (file.to_string()); if (!f$boolval (filename_or_false)) { php_warning ("Wrong file \"%s\" specified", file.to_string().c_str()); return false; } string filename = filename_or_false.val(); if (dl::query_num == opened_files_last_query_num && opened_files->has_key (filename)) { int result = 0; FILE *f = opened_files->get_value (filename); dl::enter_critical_section();//OK while (!feof (f)) { clearerr (f); size_t res_size = fread (&php_buf[0], 1, PHP_BUF_LEN, f); if (ferror (f)) { dl::leave_critical_section(); php_warning ("Error happened during fpassthru from file \"%s\"", filename.c_str()); return false; } coub->append (php_buf, (dl::size_type)res_size); result += (int)res_size; } dl::leave_critical_section(); return result; } else { php_warning ("File \"%s\" is not opened\n", filename.c_str()); return false; } }
OrFalse <int> f$fwrite (const MyFile &file, const string &text) { if (eq2 (file, STDOUT)) { *coub += text; return (int)text.size(); } int res = -1; if (eq2 (file, STDERR)) { dl::enter_critical_section();//OK res = (int)fwrite (text.c_str(), text.size(), 1, stderr); dl::leave_critical_section(); } else { OrFalse <string> filename_or_false = full_realpath (file.to_string()); if (!f$boolval (filename_or_false)) { php_warning ("Wrong file \"%s\" specified", file.to_string().c_str()); return false; } string filename = filename_or_false.val(); if (dl::query_num == opened_files_last_query_num && opened_files->has_key (filename)) { FILE *f = opened_files->get_value (filename); dl::enter_critical_section();//OK res = (int)fwrite (text.c_str(), text.size(), 1, f); dl::leave_critical_section(); } } if (res < 0) { return false; } return res; }
TEST( ElemMatchObjectMatchExpression, MatchesElementMultiple ) { BSONObj baseOperand1 = BSON( "b" << 5 ); BSONObj baseOperand2 = BSON( "b" << 6 ); BSONObj baseOperand3 = BSON( "c" << 7 ); BSONObj notMatch1 = BSON( "a" << BSON_ARRAY( BSON( "b" << 5 << "c" << 7 ) ) ); BSONObj notMatch2 = BSON( "a" << BSON_ARRAY( BSON( "b" << 6 << "c" << 7 ) ) ); BSONObj notMatch3 = BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 5 << 6 ) ) ) ); BSONObj match = BSON( "a" << BSON_ARRAY( BSON( "b" << BSON_ARRAY( 5 << 6 ) << "c" << 7 ) ) ); auto_ptr<ComparisonMatchExpression> eq1( new ComparisonMatchExpression() ); ASSERT( eq1->init( "b", ComparisonMatchExpression::EQ, baseOperand1[ "b" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> eq2( new ComparisonMatchExpression() ); ASSERT( eq2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> eq3( new ComparisonMatchExpression() ); ASSERT( eq3->init( "c", ComparisonMatchExpression::EQ, baseOperand3[ "c" ] ).isOK() ); auto_ptr<AndMatchExpression> andOp( new AndMatchExpression() ); andOp->add( eq1.release() ); andOp->add( eq2.release() ); andOp->add( eq3.release() ); ElemMatchObjectMatchExpression op; ASSERT( op.init( "a", andOp.release() ).isOK() ); ASSERT( !op.matchesSingleElement( notMatch1[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch2[ "a" ] ) ); ASSERT( !op.matchesSingleElement( notMatch3[ "a" ] ) ); ASSERT( op.matchesSingleElement( match[ "a" ] ) ); }
bool f$fclose (const MyFile &file) { if (eq2 (file, STDOUT) || eq2 (file, STDERR)) { return true; } OrFalse <string> filename_or_false = full_realpath (file.to_string()); if (!f$boolval (filename_or_false)) { php_warning ("Wrong file \"%s\" specified", file.to_string().c_str()); return false; } string filename = filename_or_false.val(); if (dl::query_num == opened_files_last_query_num && opened_files->has_key (filename)) { dl::enter_critical_section();//NOT OK: opened_files fclose (opened_files->get_value (filename)); opened_files->unset (filename); dl::leave_critical_section(); return true; } return false; }
OrFalse <int> f$ftell (const MyFile &file) { if (eq2 (file, STDOUT) || eq2 (file, STDERR)) { php_warning ("Can't use ftell with STDERR and STDOUT\n"); return false; } OrFalse <string> filename_or_false = full_realpath (file.to_string()); if (!f$boolval (filename_or_false)) { php_warning ("Wrong file \"%s\" specified", file.to_string().c_str()); return false; } string filename = filename_or_false.val(); if (dl::query_num == opened_files_last_query_num && opened_files->has_key (filename)) { FILE *f = opened_files->get_value (filename); dl::enter_critical_section();//OK int result = (int)ftell (f); dl::leave_critical_section(); return result; } else { php_warning ("File \"%s\" is not opened\n", filename.c_str()); return false; } }
MyFile f$fopen (const string &filename, const string &mode) { if (dl::query_num != opened_files_last_query_num) { new (opened_files_storage) array <FILE *>(); opened_files->set_value (STDOUT, stdout); opened_files->set_value (STDERR, stderr); opened_files_last_query_num = dl::query_num; } if (eq2 (filename, STDOUT) || eq2 (filename, STDOUT)) { php_warning ("Can't open STDERR or STDOUT"); return false; } OrFalse <string> real_filename_or_false = full_realpath (filename); if (!f$boolval (real_filename_or_false)) { php_warning ("Wrong file \"%s\" specified", filename.c_str()); return false; } string real_filename = real_filename_or_false.val(); if (opened_files->has_key (real_filename)) { php_warning ("File \"%s\" already opened. Closing previous one.", real_filename.c_str()); f$fclose (MyFile (real_filename)); } dl::enter_critical_section();//NOT OK: opened_files FILE *file = fopen (real_filename.c_str(), mode.c_str()); if (file != NULL) { opened_files->set_value (real_filename, file); dl::leave_critical_section(); return MyFile (real_filename); } else { dl::leave_critical_section(); return MyFile (false); } }
OrFalse <string> f$fread (const MyFile &file, int length) { if (eq2 (file, STDOUT) || eq2 (file, STDERR)) { php_warning ("Can't use fread with STDERR and STDOUT\n"); return false; } if (length <= 0) { php_warning ("Parameter length in function fread must be positive\n"); return false; } OrFalse <string> filename_or_false = full_realpath (file.to_string()); if (!f$boolval (filename_or_false)) { php_warning ("Wrong file \"%s\" specified", file.to_string().c_str()); return false; } string filename = filename_or_false.val(); string res (length, false); if (dl::query_num == opened_files_last_query_num && opened_files->has_key (filename)) { FILE *f = opened_files->get_value (filename); dl::enter_critical_section();//OK clearerr (f); size_t res_size = fread (&res[0], 1, length, f); if (ferror (f)) { dl::leave_critical_section(); php_warning ("Error happened during fread from file \"%s\"", filename.c_str()); return false; } dl::leave_critical_section(); res.shrink ((dl::size_type)res_size); return res; } else { php_warning ("File \"%s\" is not opened\n", filename.c_str()); return false; } }
void run_test( int my_factory_events, int factories, int handlers, int maxq ) { struct timeval tv; struct timeval tv2; gettimeofday( &tv, NULL ); fprintf(stderr,"run_test %i %i %i %i [%x %x ... ", my_factory_events, factories, handlers, maxq, (unsigned int)tv.tv_sec, (unsigned int)tv.tv_usec ); pEventFactory pmeft1 ( new MyEventFactory( my_factory_events )) ; MyEventHandler *pe = new MyEventHandler(); pe->need_hook=true; pEventHandler peh1( pe ); pEventHandler phook1( new MyHookEventHandler() ); pEventFactory pmeft2 ( new MyEventFactory( my_factory_events )) ; pe = new MyEventHandler(); pe->need_hook=false; pEventHandler peh2( pe ); pEventFactory pmeft3 ( new MyEventFactory( my_factory_events )) ; pEventHandler phook3( new MyHookEventHandler() ); pe = new MyEventHandler(); pe->need_hook=true; pEventHandler peh3( pe ); { EventQueue eq1( pmeft1, peh1, phook1, factories, handlers, maxq ); EventQueue eq2( pmeft2, peh2, factories, handlers, maxq ); EventQueue eq3( pmeft3, peh3, phook3, factories, handlers, maxq ); eq1.wait(); eq2.wait(); eq3.wait(); } gettimeofday( &tv2, NULL ); time_t secs = tv2.tv_sec - tv.tv_sec ; time_t usecs = tv2.tv_usec - tv.tv_usec ; if( usecs < 0 ) { usecs += 1000000 ; secs -= 1 ; } fprintf(stderr,"%x %x ] secs %li msecs %li \n", (unsigned int)tv2.tv_sec, (unsigned int)tv2.tv_usec, secs, usecs ); if( MyEventHandler::errors ) { PANIC("MyEventHandler::errors"); } };
void PrefGeneral::getData(Preferences * pref) { requires_restart = false; filesettings_method_changed = false; if (pref->mplayer_bin != mplayerPath()) { requires_restart = true; pref->mplayer_bin = mplayerPath(); qDebug("PrefGeneral::getData: mplayer binary has changed, getting version number"); // Forces to get info from mplayer to update version number InfoReader i( pref->mplayer_bin ); i.getInfo(); // Update the drivers list at the same time //setDrivers( i.voList(), i.aoList() ); } TEST_AND_SET(pref->use_screenshot, useScreenshots()); TEST_AND_SET(pref->screenshot_directory, screenshotDir()); TEST_AND_SET(pref->vo, VO()); TEST_AND_SET(pref->ao, AO()); bool dont_remember_ms = !rememberSettings(); TEST_AND_SET(pref->dont_remember_media_settings, dont_remember_ms); bool dont_remember_time = !rememberTimePos(); TEST_AND_SET(pref->dont_remember_time_pos, dont_remember_time); if (pref->file_settings_method != fileSettingsMethod()) { pref->file_settings_method = fileSettingsMethod(); filesettings_method_changed = true; } pref->audio_lang = audioLang(); pref->subtitle_lang = subtitleLang(); pref->initial_audio_track = audioTrack(); pref->initial_subtitle_track = subtitleTrack(); pref->close_on_finish = closeOnFinish(); pref->pause_when_hidden = pauseWhenHidden(); TEST_AND_SET(pref->use_soft_video_eq, eq2()); TEST_AND_SET(pref->use_soft_vol, softVol()); pref->global_volume = globalVolume(); TEST_AND_SET(pref->use_audio_equalizer, useAudioEqualizer()); TEST_AND_SET(pref->use_hwac3, Ac3DTSPassthrough()); pref->initial_volnorm = initialVolNorm(); TEST_AND_SET(pref->softvol_max, amplification()); pref->initial_postprocessing = initialPostprocessing(); pref->initial_deinterlace = initialDeinterlace(); pref->initial_zoom_factor = initialZoom(); TEST_AND_SET(pref->use_direct_rendering, directRendering()); TEST_AND_SET(pref->use_double_buffer, doubleBuffer()); TEST_AND_SET(pref->use_slices, useSlices()); pref->start_in_fullscreen = startInFullscreen(); if (pref->add_blackborders_on_fullscreen != blackbordersOnFullscreen()) { pref->add_blackborders_on_fullscreen = blackbordersOnFullscreen(); if (pref->fullscreen) requires_restart = true; } TEST_AND_SET(pref->autoq, autoq()); #ifdef Q_OS_WIN pref->avoid_screensaver = avoidScreensaver(); TEST_AND_SET(pref->turn_screensaver_off, turnScreensaverOff()); #else TEST_AND_SET(pref->disable_screensaver, disableScreensaver()); #endif #ifndef Q_OS_WIN pref->vdpau = vdpau; #endif pref->initial_audio_channels = audioChannels(); TEST_AND_SET(pref->use_scaletempo, scaleTempoFilter()); TEST_AND_SET(pref->autosync, autoSyncActivated()); TEST_AND_SET(pref->autosync_factor, autoSyncFactor()); TEST_AND_SET(pref->use_mc, mcActivated()); TEST_AND_SET(pref->mc_value, mc()); }