extern warp_result_t save_file (const char *path, const char *data, size_t size) { SDL_RWops *io = SDL_RWFromFile(path, "w"); if (io == NULL) { return warp_failure("Cannot open the file: %s.", path); } const size_t saved_count = io->write(io, data, size, 1); io->close(io); if (saved_count != 1) { warp_log_e("Expected to save single object," " number of saved objects: %zu", saved_count); } return warp_success(); }
int main(int argc, char *argv[]) { SDL_RWops *rwops = NULL; char test_buf[30]; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); cleanup(); /* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */ rwops = SDL_RWFromFile(NULL, NULL); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(NULL, "ab+"); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj"); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile("something", ""); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile("something", NULL); if (rwops) RWOP_ERR_QUIT(rwops); SDL_Log("test1 OK\n"); /* test 2 : check that inexistent file is not successfully opened/created when required */ /* modes : r, r+ imply that file MUST exist modes : a, a+, w, w+ checks that it succeeds (file may not exists) */ rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */ if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */ if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(FBASENAME2, "wb"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2, "wb+"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2, "ab"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2, "ab+"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); SDL_Log("test2 OK\n"); /* test 3 : creation, writing , reading, seeking, test : w mode, r mode, w+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */ if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops, "1234567890", 10, 1)) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops, "1234567890", 1, 10)) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops, "1234567", 1, 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); /* we are in write only mode */ rwops->close(rwops); rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */ if (!rwops) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7 != rwops->read(rwops, test_buf, 1, 7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "1234567", 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 10, 100)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (2 != rwops->read(rwops, test_buf, 10, 3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "12345678901234567890", 20)) RWOP_ERR_QUIT(rwops); if (0 != rwops->write(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); /* readonly mode */ rwops->close(rwops); /* test 3: same with w+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */ if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops, "1234567890", 10, 1)) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops, "1234567890", 1, 10)) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops, "1234567", 1, 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (1 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7 != rwops->read(rwops, test_buf, 1, 7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "1234567", 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 10, 100)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (2 != rwops->read(rwops, test_buf, 10, 3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "12345678901234567890", 20)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); SDL_Log("test3 OK\n"); /* test 4: same in r+ mode */ rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */ if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops, "1234567890", 10, 1)) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops, "1234567890", 1, 10)) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops, "1234567", 1, 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (1 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); /* we are in read/write mode */ if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7 != rwops->read(rwops, test_buf, 1, 7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "1234567", 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 10, 100)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (2 != rwops->read(rwops, test_buf, 10, 3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "12345678901234567890", 20)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); SDL_Log("test4 OK\n"); /* test5 : append mode */ rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */ if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops, "1234567890", 10, 1)) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops, "1234567890", 1, 10)) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops, "1234567", 1, 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (1 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7 != rwops->read(rwops, test_buf, 1, 7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "1234567", 7)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 1, 1)) RWOP_ERR_QUIT(rwops); if (0 != rwops->read(rwops, test_buf, 10, 100)) RWOP_ERR_QUIT(rwops); if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (3 != rwops->read(rwops, test_buf, 10, 3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); SDL_Log("test5 OK\n"); cleanup(); return 0; /* all ok */ }
int main(int argc, char ** argv) { #ifdef WIN32 SetUnhandledExceptionFilter( UnhandledExceptionProc ); #endif for(int i = 1; i < argc;) { int ret = argsHandler(argc, argv, i); if(!ret) { // ignore unknown arg i++; } } if ( cg_printVersion ) { printf( "%s\n", PACKAGE_STRING ); return 0; } if ( cg_printHelp ) { printHelp( argv[0] ); return 0; } std::unique_ptr<SplashWindow> splashWindow; try{ // start recording backtrace spades::reflection::Backtrace::StartBacktrace(); SPADES_MARK_FUNCTION(); // show splash window // NOTE: splash window uses image loader, which assumes backtrace is already initialized. splashWindow.reset(new SplashWindow()); auto showSplashWindowTime = SDL_GetTicks(); auto pumpEvents = [&splashWindow] { splashWindow->PumpEvents(); }; // initialize threads spades::Thread::InitThreadSystem(); spades::DispatchQueue::GetThreadQueue()->MarkSDLVideoThread(); SPLog("Package: " PACKAGE_STRING); // setup user-specific default resource directories #ifdef WIN32 static wchar_t buf[4096]; GetModuleFileNameW(NULL, buf, 4096); std::wstring appdir = buf; appdir = appdir.substr(0, appdir.find_last_of(L'\\')+1); if(SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, buf))){ std::wstring datadir = buf; datadir += L"\\OpenSpades\\Resources"; spades::FileManager::AddFileSystem(new spades::DirectoryFileSystem(Utf8FromWString(datadir.c_str()), true)); } spades::FileManager::AddFileSystem(new spades::DirectoryFileSystem(Utf8FromWString((appdir + L"Resources").c_str()), false)); //fltk has a console window on windows (can disable while building, maybe use a builtin console for a later release?) HWND hCon = GetConsoleWindow(); if( NULL != hCon ) { setIcon( hCon ); } #elif defined(__APPLE__) std::string home = getenv("HOME"); spades::FileManager::AddFileSystem (new spades::DirectoryFileSystem("./Resources", false)); // OS X application is made of Bundle, which contains its own Resources directory. { char *baseDir = SDL_GetBasePath(); if(baseDir) { spades::FileManager::AddFileSystem (new spades::DirectoryFileSystem(baseDir, false)); SDL_free(baseDir); } } spades::FileManager::AddFileSystem (new spades::DirectoryFileSystem(home+"/Library/Application Support/OpenSpades/Resources", true)); #else std::string home = getenv("HOME"); spades::FileManager::AddFileSystem (new spades::DirectoryFileSystem("./Resources", false)); spades::FileManager::AddFileSystem(new spades::DirectoryFileSystem(CMAKE_INSTALL_PREFIX "/" OPENSPADES_INSTALL_RESOURCES, false)); std::string xdg_data_home = home+"/.local/share"; if (getenv("XDG_DATA_HOME") == NULL) { SPLog("XDG_DATA_HOME not defined. Assuming that XDG_DATA_HOME is ~/.local/share"); } else { std::string xdg_data_home = getenv("XDG_DATA_HOME"); SPLog("XDG_DATA_HOME is %s", xdg_data_home.c_str()); } struct stat info; if ( stat((xdg_data_home+"/openspades").c_str(), &info ) != 0 ) { if ( stat((home+"/.openspades").c_str(), &info ) != 0) { } else if( info.st_mode & S_IFDIR ) { SPLog("Openspades directory in XDG_DATA_HOME not found, though old directory exists. Trying to resolve compatibility problem."); if (rename( (home+"/.openspades").c_str() , (xdg_data_home+"/openspades").c_str() ) != 0) { SPLog("Failed to move old directory to new."); } else { SPLog("Successfully moved old directory."); if (mkdir((home+"/.openspades").c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0) { SDL_RWops *io = SDL_RWFromFile((home+"/.openspades/CONTENT_MOVED_TO_NEW_DIR").c_str(), "wb"); if (io != NULL) { const char* text = ("Content of this directory moved to "+xdg_data_home+"/openspades").c_str(); io->write(io, text, strlen(text), 1); io->close(io); } } } } } spades::FileManager::AddFileSystem (new spades::DirectoryFileSystem(xdg_data_home+"/openspades/Resources", true)); #endif // start log output to SystemMessages.log try{ spades::StartLog(); }catch(const std::exception& ex){ SDL_InitSubSystem(SDL_INIT_VIDEO); auto msg = spades::Format("Failed to start recording log because of the following error:\n{0}\n\n" "OpenSpades will continue to run, but any critical events are not logged.", ex.what()); if(SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "OpenSpades Log System Failure", msg.c_str(), splashWindow->GetWindow())) { // showing dialog failed. } } SPLog("Log Started."); // load preferences. spades::Settings::GetInstance()->Load(); pumpEvents(); // dump CPU info (for debugging?) { spades::CpuID cpuid; SPLog("---- CPU Information ----"); SPLog("Vendor ID: %s", cpuid.GetVendorId().c_str()); SPLog("Brand ID: %s", cpuid.GetBrand().c_str()); SPLog("Supports MMX: %s", cpuid.Supports(spades::CpuFeature::MMX)?"YES":"NO"); SPLog("Supports SSE: %s", cpuid.Supports(spades::CpuFeature::SSE)?"YES":"NO"); SPLog("Supports SSE2: %s", cpuid.Supports(spades::CpuFeature::SSE2)?"YES":"NO"); SPLog("Supports SSE3: %s", cpuid.Supports(spades::CpuFeature::SSE3)?"YES":"NO"); SPLog("Supports SSSE3: %s", cpuid.Supports(spades::CpuFeature::SSSE3)?"YES":"NO"); SPLog("Supports FMA: %s", cpuid.Supports(spades::CpuFeature::FMA)?"YES":"NO"); SPLog("Supports AVX: %s", cpuid.Supports(spades::CpuFeature::AVX)?"YES":"NO"); SPLog("Supports AVX2: %s", cpuid.Supports(spades::CpuFeature::AVX2)?"YES":"NO"); SPLog("Supports AVX512F: %s", cpuid.Supports(spades::CpuFeature::AVX512F)?"YES":"NO"); SPLog("Supports AVX512CD: %s", cpuid.Supports(spades::CpuFeature::AVX512CD)?"YES":"NO"); SPLog("Supports AVX512ER: %s", cpuid.Supports(spades::CpuFeature::AVX512ER)?"YES":"NO"); SPLog("Supports AVX512PF: %s", cpuid.Supports(spades::CpuFeature::AVX512PF)?"YES":"NO"); SPLog("Simultaneous Multithreading: %s", cpuid.Supports(spades::CpuFeature::SimultaneousMT)?"YES":"NO"); SPLog("Misc:"); SPLog("%s", cpuid.GetMiscInfo().c_str()); SPLog("-------------------------"); } // register resource directory specified by Makefile (or something) #if defined(RESDIR_DEFINED) spades::FileManager::AddFileSystem(new spades::DirectoryFileSystem(RESDIR, false)); #endif // search current file system for .pak files { std::vector<spades::IFileSystem*> fss; std::vector<spades::IFileSystem*> fssImportant; std::vector<std::string> files = spades::FileManager::EnumFiles(""); struct Comparator { static int GetPakId(const std::string& str) { if(str.size() >= 4 && str[0] == 'p' && str[1] == 'a' && str[2] == 'k' && (str[3] >= '0' && str[3] <= '9')){ return atoi(str.c_str() + 3); }else{ return 32767; } } static bool Compare(const std::string& a, const std::string& b) { int pa = GetPakId(a); int pb = GetPakId(b); if(pa == pb){ return a < b; }else{ return pa < pb; } } }; std::sort(files.begin(), files.end(), Comparator::Compare); for(size_t i = 0; i < files.size(); i++){ std::string name = files[i]; // check extension if(name.size() < 4 || name.rfind(".pak") != name.size() - 4){ continue; } if(spades::FileManager::FileExists(name.c_str())) { spades::IStream *stream = spades::FileManager::OpenForReading(name.c_str()); spades::ZipFileSystem *fs = new spades::ZipFileSystem(stream); if(name[0] == '_' && false) { // last resort for #198 SPLog("Pak Registered: %s (marked as 'important')\n", name.c_str()); fssImportant.push_back(fs); }else{ SPLog("Pak Registered: %s\n", name.c_str()); fss.push_back(fs); } } } for(size_t i = fss.size(); i > 0; i--){ spades::FileManager::AppendFileSystem(fss[i - 1]); } for(size_t i = 0; i < fssImportant.size(); i++){ spades::FileManager::PrependFileSystem(fssImportant[i]); } } pumpEvents(); // initialize localization system SPLog("Initializing localization system"); spades::LoadCurrentLocale(); _Tr("Main", "Localization System Loaded"); pumpEvents(); // parse args // initialize AngelScript SPLog("Initializing script engine"); spades::ScriptManager::GetInstance(); pumpEvents(); ThreadQuantumSetter quantumSetter; (void)quantumSetter; // suppress "unused variable" warning SDL_InitSubSystem(SDL_INIT_VIDEO); // we want to show splash window at least for some time... pumpEvents(); auto ticks = SDL_GetTicks(); if(ticks < showSplashWindowTime + 1500) { SDL_Delay(showSplashWindowTime + 1500 - ticks); } pumpEvents(); // everything is now ready! if( !cg_autoConnect ) { if(!((int)cl_showStartupWindow != 0 || splashWindow->IsStartupScreenRequested())) { splashWindow.reset(); SPLog("Starting main screen"); spades::StartMainScreen(); }else{ splashWindow.reset(); SPLog("Starting startup window"); ::spades::gui::StartupScreen::Run(); } } else { splashWindow.reset(); spades::ServerAddress host(cg_lastQuickConnectHost.CString(), (int)cg_protocolVersion == 3 ? spades::ProtocolVersion::v075 : spades::ProtocolVersion::v076 ); spades::StartClient(host, cg_playerName); } spades::Settings::GetInstance()->Flush(); }catch(const ExitRequestException&){ // user changed his mind. }catch(const std::exception& ex) { try { splashWindow.reset(nullptr); }catch(...){ } std::string msg = ex.what(); msg = _Tr("Main", "A serious error caused OpenSpades to stop working:\n\n{0}\n\nSee SystemMessages.log for more details.", msg); SPLog("[!] Terminating due to the fatal error: %s", ex.what()); SDL_InitSubSystem(SDL_INIT_VIDEO); if(SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, _Tr("Main", "OpenSpades Fatal Error").c_str(), msg.c_str(), nullptr)) { // showing dialog failed. // TODO: do appropriate action } } return 0; }
int main(int argc, char *argv[]) { SDL_RWops *rwops = NULL; char test_buf[30]; cleanup(); rwops = SDL_RWFromFile(NULL,NULL); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(NULL,"ab+"); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(NULL,"sldfkjsldkfj"); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile("something",""); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile("something",NULL); if (rwops) RWOP_ERR_QUIT(rwops); printf("test1 OK\n"); rwops = SDL_RWFromFile(FBASENAME2,"rb"); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(FBASENAME2,"rb+"); if (rwops) RWOP_ERR_QUIT(rwops); rwops = SDL_RWFromFile(FBASENAME2,"wb"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2,"wb+"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2,"ab"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); rwops = SDL_RWFromFile(FBASENAME2,"ab+"); if (!rwops) RWOP_ERR_QUIT(rwops); rwops->close(rwops); unlink(FBASENAME2); printf("test2 OK\n"); rwops = SDL_RWFromFile(FBASENAME1,"wb"); if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); rwops = SDL_RWFromFile(FBASENAME1,"rb"); if (!rwops) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops); if (0!=rwops->write(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); rwops = SDL_RWFromFile(FBASENAME1,"wb+"); if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); printf("test3 OK\n"); rwops = SDL_RWFromFile(FBASENAME1,"rb+"); if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (2!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"12345678901234567890",20)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); printf("test4 OK\n"); rwops = SDL_RWFromFile(FBASENAME1,"ab+"); if (!rwops) RWOP_ERR_QUIT(rwops); if (1 != rwops->write(rwops,"1234567890",10,1) ) RWOP_ERR_QUIT(rwops); if (10 != rwops->write(rwops,"1234567890",1,10) ) RWOP_ERR_QUIT(rwops); if (7 != rwops->write(rwops,"1234567",1,7) ) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (1!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (20+27!=rwops->seek(rwops,-7,RW_SEEK_END)) RWOP_ERR_QUIT(rwops); if (7!=rwops->read(rwops,test_buf,1,7)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"1234567",7)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,1,1)) RWOP_ERR_QUIT(rwops); if (0!=rwops->read(rwops,test_buf,10,100)) RWOP_ERR_QUIT(rwops); if (27!=rwops->seek(rwops,-27,RW_SEEK_CUR)) RWOP_ERR_QUIT(rwops); if (0!=rwops->seek(rwops,0L,RW_SEEK_SET)) RWOP_ERR_QUIT(rwops); if (3!=rwops->read(rwops,test_buf,10,3)) RWOP_ERR_QUIT(rwops); if (SDL_memcmp(test_buf,"123456789012345678901234567123",30)) RWOP_ERR_QUIT(rwops); rwops->close(rwops); printf("test5 OK\n"); cleanup(); return 0; }