Merge pull request #164 from lioncash/cstr-cull

Kill off some usages of c_str.
This commit is contained in:
Pierre Bourdon
2014-03-15 00:57:56 +01:00
170 changed files with 812 additions and 704 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ namespace AudioCommon
{
std::string audio_file_name = File::GetUserPath(D_DUMPAUDIO_IDX) + "audiodump.wav";
File::CreateFullPath(audio_file_name);
mixer->StartLogAudio(audio_file_name.c_str());
mixer->StartLogAudio(audio_file_name);
}
return soundStream;
+16 -6
View File
@@ -4,6 +4,8 @@
#pragma once
#include <string>
#include "AudioCommon/WaveFile.h"
#include "Common/StdMutex.h"
@@ -57,23 +59,31 @@ public:
// ---------------------
virtual void StartLogAudio(const char *filename) {
if (! m_logAudio) {
virtual void StartLogAudio(const std::string& filename)
{
if (! m_logAudio)
{
m_logAudio = true;
g_wave_writer.Start(filename, GetSampleRate());
g_wave_writer.SetSkipSilence(false);
NOTICE_LOG(DSPHLE, "Starting Audio logging");
} else {
}
else
{
WARN_LOG(DSPHLE, "Audio logging has already been started");
}
}
virtual void StopLogAudio() {
if (m_logAudio) {
virtual void StopLogAudio()
{
if (m_logAudio)
{
m_logAudio = false;
g_wave_writer.Stop();
NOTICE_LOG(DSPHLE, "Stopping Audio logging");
} else {
}
else
{
WARN_LOG(DSPHLE, "Audio logging has already been stopped");
}
}
+5 -3
View File
@@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <string>
#include "AudioCommon/WaveFile.h"
#include "Common/Common.h"
#include "Core/ConfigManager.h"
@@ -21,7 +23,7 @@ WaveFileWriter::~WaveFileWriter()
Stop();
}
bool WaveFileWriter::Start(const char *filename, unsigned int HLESampleRate)
bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRate)
{
if (!conv_buffer)
conv_buffer = new short[BUF_SIZE];
@@ -29,14 +31,14 @@ bool WaveFileWriter::Start(const char *filename, unsigned int HLESampleRate)
// Check if the file is already open
if (file)
{
PanicAlertT("The file %s was already open, the file header will not be written.", filename);
PanicAlertT("The file %s was already open, the file header will not be written.", filename.c_str());
return false;
}
file.Open(filename, "wb");
if (!file)
{
PanicAlertT("The file %s could not be opened for writing. Please check if it's already opened by another program.", filename);
PanicAlertT("The file %s could not be opened for writing. Please check if it's already opened by another program.", filename.c_str());
return false;
}
+2 -1
View File
@@ -14,6 +14,7 @@
#pragma once
#include <string>
#include "Common/FileUtil.h"
class WaveFileWriter
@@ -31,7 +32,7 @@ public:
WaveFileWriter();
~WaveFileWriter();
bool Start(const char *filename, unsigned int HLESampleRate);
bool Start(const std::string& filename, unsigned int HLESampleRate);
void Stop();
void SetSkipSilence(bool skip) { skip_silence = skip; }
+2 -2
View File
@@ -262,7 +262,7 @@ public:
}
}
void DoMarker(const char* prevName, u32 arbitraryNumber = 0x42)
void DoMarker(const std::string& prevName, u32 arbitraryNumber = 0x42)
{
u32 cookie = arbitraryNumber;
Do(cookie);
@@ -270,7 +270,7 @@ public:
if (mode == PointerWrap::MODE_READ && cookie != arbitraryNumber)
{
PanicAlertT("Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...",
prevName, cookie, cookie, arbitraryNumber, arbitraryNumber);
prevName.c_str(), cookie, cookie, arbitraryNumber, arbitraryNumber);
mode = PointerWrap::MODE_MEASURE;
}
}
+2 -2
View File
@@ -939,12 +939,12 @@ std::string GetThemeDir(const std::string& theme_name)
return dir;
}
bool WriteStringToFile(const std::string &str, const char *filename)
bool WriteStringToFile(const std::string &str, const std::string& filename)
{
return File::IOFile(filename, "wb").WriteBytes(str.data(), str.size());
}
bool ReadFileToString(const char *filename, std::string &str)
bool ReadFileToString(const std::string& filename, std::string &str)
{
File::IOFile file(filename, "rb");
auto const f = file.GetHandle();
+2 -2
View File
@@ -143,8 +143,8 @@ std::string GetBundleDirectory();
std::string &GetExeDirectory();
#endif
bool WriteStringToFile(const std::string &str, const char *filename);
bool ReadFileToString(const char *filename, std::string &str);
bool WriteStringToFile(const std::string& str, const std::string& filename);
bool ReadFileToString(const std::string& filename, std::string& str);
// simple wrapper for cstdlib file functions to
// hopefully will make error checking easier
+2 -1
View File
@@ -6,6 +6,7 @@
#include <cstring>
#include <fstream>
#include <string>
#include "Common/Common.h"
#include "Common/FileUtil.h"
@@ -48,7 +49,7 @@ class LinearDiskCache
{
public:
// return number of read entries
u32 OpenAndRead(const char *filename, LinearDiskCacheReader<K, V> &reader)
u32 OpenAndRead(const std::string& filename, LinearDiskCacheReader<K, V> &reader)
{
using std::ios_base;
+39 -17
View File
@@ -33,6 +33,7 @@
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include "Common/Common.h"
#include "Common/FileUtil.h"
@@ -188,7 +189,7 @@ static unsigned int write_empty(FILE* file, u64 count)
return 0;
}
bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename)
{
u32 sectors_per_fat;
u32 sectors_per_disk;
@@ -196,7 +197,8 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
// Convert MB to bytes
disk_size *= 1024 * 1024;
if (disk_size < 0x800000 || disk_size > 0x800000000ULL) {
if (disk_size < 0x800000 || disk_size > 0x800000000ULL)
{
ERROR_LOG(COMMON, "Trying to create SD Card image of size %" PRIu64 "MB is out of range (8MB-32GB)", disk_size/(1024*1024));
return false;
}
@@ -212,7 +214,7 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
FILE* const f = file.GetHandle();
if (!f)
{
ERROR_LOG(COMMON, "Could not create file '%s', aborting...\n", filename);
ERROR_LOG(COMMON, "Could not create file '%s', aborting...\n", filename.c_str());
return false;
}
@@ -229,31 +231,51 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
* zero sectors
*/
if (write_sector(f, s_boot_sector)) goto FailWrite;
if (write_sector(f, s_fsinfo_sector)) goto FailWrite;
if (write_sector(f, s_boot_sector))
goto FailWrite;
if (write_sector(f, s_fsinfo_sector))
goto FailWrite;
if (BACKUP_BOOT_SECTOR > 0)
{
if (write_empty(f, BACKUP_BOOT_SECTOR - 2)) goto FailWrite;
if (write_sector(f, s_boot_sector)) goto FailWrite;
if (write_sector(f, s_fsinfo_sector)) goto FailWrite;
if (write_empty(f, RESERVED_SECTORS - 2 - BACKUP_BOOT_SECTOR)) goto FailWrite;
if (write_empty(f, BACKUP_BOOT_SECTOR - 2))
goto FailWrite;
if (write_sector(f, s_boot_sector))
goto FailWrite;
if (write_sector(f, s_fsinfo_sector))
goto FailWrite;
if (write_empty(f, RESERVED_SECTORS - 2 - BACKUP_BOOT_SECTOR))
goto FailWrite;
}
else
{
if (write_empty(f, RESERVED_SECTORS - 2)) goto FailWrite;
}
if (write_sector(f, s_fat_head)) goto FailWrite;
if (write_empty(f, sectors_per_fat-1)) goto FailWrite;
if (write_sector(f, s_fat_head))
goto FailWrite;
if (write_sector(f, s_fat_head)) goto FailWrite;
if (write_empty(f, sectors_per_fat-1)) goto FailWrite;
if (write_empty(f, sectors_per_fat - 1))
goto FailWrite;
if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2*sectors_per_fat)) goto FailWrite;
if (write_sector(f, s_fat_head))
goto FailWrite;
if (write_empty(f, sectors_per_fat - 1))
goto FailWrite;
if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2*sectors_per_fat))
goto FailWrite;
return true;
FailWrite:
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename);
if (unlink(filename) < 0)
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename, GetLastErrorMsg());
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename.c_str());
if (unlink(filename.c_str()) < 0)
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename.c_str(), GetLastErrorMsg());
return false;
}
+2 -1
View File
@@ -4,6 +4,7 @@
#pragma once
#include <string>
#include "Common/CommonTypes.h"
bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename);
bool SDCardCreate(u64 disk_size /*in MB*/, const std::string& filename);
+2 -2
View File
@@ -26,10 +26,10 @@
#endif
// faster than sscanf
bool AsciiToHex(const char* _szValue, u32& result)
bool AsciiToHex(const std::string& _szValue, u32& result)
{
char *endptr = nullptr;
const u32 value = strtoul(_szValue, &endptr, 16);
const u32 value = strtoul(_szValue.c_str(), &endptr, 16);
if (!endptr || *endptr)
return false;
+1 -1
View File
@@ -76,7 +76,7 @@ static bool TryParse(const std::string &str, N *const output)
}
// TODO: kill this
bool AsciiToHex(const char* _szValue, u32& result);
bool AsciiToHex(const std::string& _szValue, u32& result);
std::string TabsToSpaces(int tab_size, const std::string &in);
+3 -2
View File
@@ -39,13 +39,14 @@ void SymbolDB::Index()
}
}
Symbol *SymbolDB::GetSymbolFromName(const char *name)
Symbol* SymbolDB::GetSymbolFromName(const std::string& name)
{
for (auto& func : functions)
{
if (!strcmp(func.second.name.c_str(), name))
if (func.second.name == name)
return &func.second;
}
return nullptr;
}
+6 -5
View File
@@ -80,12 +80,13 @@ public:
SymbolDB() {}
virtual ~SymbolDB() {}
virtual Symbol *GetSymbolFromAddr(u32 addr) { return nullptr; }
virtual Symbol *AddFunction(u32 startAddr) { return nullptr;}
virtual Symbol *AddFunction(u32 startAddr) { return nullptr; }
void AddCompleteSymbol(const Symbol &symbol);
Symbol *GetSymbolFromName(const char *name);
Symbol *GetSymbolFromHash(u32 hash) {
Symbol* GetSymbolFromName(const std::string& name);
Symbol* GetSymbolFromHash(u32 hash)
{
XFuncPtrMap::iterator iter = checksumToFunction.find(hash);
if (iter != checksumToFunction.end())
return iter->second;
@@ -93,8 +94,8 @@ public:
return nullptr;
}
const XFuncMap &Symbols() const {return functions;}
XFuncMap &AccessSymbols() {return functions;}
const XFuncMap &Symbols() const { return functions; }
XFuncMap &AccessSymbols() { return functions; }
void Clear(const char *prefix = "");
void List();
+9 -5
View File
@@ -16,7 +16,7 @@ SysConf::SysConf()
: m_IsValid(false)
{
m_FilenameDefault = File::GetUserPath(F_WIISYSCONF_IDX);
m_IsValid = LoadFromFile(m_FilenameDefault.c_str());
m_IsValid = LoadFromFile(m_FilenameDefault);
}
SysConf::~SysConf()
@@ -32,10 +32,11 @@ void SysConf::Clear()
{
for (auto i = m_Entries.begin(); i < m_Entries.end() - 1; ++i)
delete [] i->data;
m_Entries.clear();
}
bool SysConf::LoadFromFile(const char *filename)
bool SysConf::LoadFromFile(const std::string& filename)
{
// Basic check
if (!File::Exists(filename))
@@ -55,7 +56,9 @@ bool SysConf::LoadFromFile(const char *filename)
return true;
}
else
{
return false;
}
}
File::IOFile f(filename, "rb");
@@ -361,7 +364,7 @@ void SysConf::GenerateSysConf()
m_Filename = m_FilenameDefault;
}
bool SysConf::SaveToFile(const char *filename)
bool SysConf::SaveToFile(const std::string& filename)
{
File::IOFile f(filename, "r+b");
@@ -393,7 +396,8 @@ bool SysConf::Save()
{
if (!m_IsValid)
return false;
return SaveToFile(m_Filename.c_str());
return SaveToFile(m_Filename);
}
void SysConf::UpdateLocation()
@@ -416,6 +420,6 @@ bool SysConf::Reload()
std::string& filename = m_Filename.empty() ? m_FilenameDefault : m_Filename;
m_IsValid = LoadFromFile(filename.c_str());
m_IsValid = LoadFromFile(filename);
return m_IsValid;
}
+2 -2
View File
@@ -163,8 +163,8 @@ public:
}
bool Save();
bool SaveToFile(const char* filename);
bool LoadFromFile(const char* filename);
bool SaveToFile(const std::string& filename);
bool LoadFromFile(const std::string& filename);
bool Reload();
// This function is used when the NAND root is changed
void UpdateLocation();
+9 -9
View File
@@ -126,7 +126,7 @@ bool CBoot::LoadMapFromFilename()
{
std::string strMapFilename;
bool found = FindMapFile(&strMapFilename, nullptr);
if (found && g_symbolDB.LoadMap(strMapFilename.c_str()))
if (found && g_symbolDB.LoadMap(strMapFilename))
{
UpdateDebugger_MapLoaded();
return true;
@@ -149,7 +149,7 @@ bool CBoot::Load_BS2(const std::string& _rBootROMFilename)
// Load the whole ROM dump
std::string data;
if (!File::ReadFileToString(_rBootROMFilename.c_str(), data))
if (!File::ReadFileToString(_rBootROMFilename, data))
return false;
u32 ipl_hash = HashAdler32((const u8*)data.data(), data.size());
@@ -247,7 +247,7 @@ bool CBoot::BootUp()
{
PPCAnalyst::FindFunctions(0x80004000, 0x811fffff, &g_symbolDB);
SignatureDB db;
if (db.Load((File::GetSysDirectory() + TOTALDB).c_str()))
if (db.Load(File::GetSysDirectory() + TOTALDB))
{
db.Apply(&g_symbolDB);
HLE::PatchFunctions();
@@ -268,7 +268,7 @@ bool CBoot::BootUp()
// DOL
case SCoreStartupParameter::BOOT_DOL:
{
CDolLoader dolLoader(_StartupPara.m_strFilename.c_str());
CDolLoader dolLoader(_StartupPara.m_strFilename);
// Check if we have gotten a Wii file or not
bool dolWii = dolLoader.IsWii();
if (dolWii != _StartupPara.bWii)
@@ -284,7 +284,7 @@ bool CBoot::BootUp()
}
else if (!VolumeHandler::IsWii() && !_StartupPara.m_strDefaultGCM.empty())
{
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM.c_str());
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM);
BS2Success = EmulatedBS2(dolWii);
}
@@ -320,7 +320,7 @@ bool CBoot::BootUp()
}
// Check if we have gotten a Wii file or not
bool elfWii = IsElfWii(_StartupPara.m_strFilename.c_str());
bool elfWii = IsElfWii(_StartupPara.m_strFilename);
if (elfWii != _StartupPara.bWii)
{
PanicAlertT("Warning - starting ELF in wrong console mode!");
@@ -334,7 +334,7 @@ bool CBoot::BootUp()
}
else if (!VolumeHandler::IsWii() && !_StartupPara.m_strDefaultGCM.empty())
{
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM.c_str());
VolumeHandler::SetVolumeName(_StartupPara.m_strDefaultGCM);
BS2Success = EmulatedBS2(elfWii);
}
@@ -362,7 +362,7 @@ bool CBoot::BootUp()
else // Poor man's bootup
{
Load_FST(elfWii);
Boot_ELF(_StartupPara.m_strFilename.c_str());
Boot_ELF(_StartupPara.m_strFilename);
}
UpdateDebugger_MapLoaded();
Dolphin_Debugger::AddAutoBreakpoints();
@@ -371,7 +371,7 @@ bool CBoot::BootUp()
// Wii WAD
case SCoreStartupParameter::BOOT_WII_NAND:
Boot_WiiWAD(_StartupPara.m_strFilename.c_str());
Boot_WiiWAD(_StartupPara.m_strFilename);
if (LoadMapFromFilename())
HLE::PatchFunctions();
+3 -3
View File
@@ -25,7 +25,7 @@ class CBoot
public:
static bool BootUp();
static bool IsElfWii(const char *filename);
static bool IsElfWii(const std::string& filename);
// Tries to find a map file for the current game by looking first in the
// local user directory, then in the shared user directory.
@@ -46,8 +46,8 @@ private:
static void UpdateDebugger_MapLoaded(const char* _gameID = nullptr);
static bool LoadMapFromFilename();
static bool Boot_ELF(const char *filename);
static bool Boot_WiiWAD(const char *filename);
static bool Boot_ELF(const std::string& filename);
static bool Boot_WiiWAD(const std::string& filename);
static bool EmulatedBS2_GC();
static bool EmulatedBS2_Wii();
+5 -3
View File
@@ -2,6 +2,8 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <string>
#include "Common/CommonFuncs.h"
#include "Common/FileUtil.h"
@@ -14,14 +16,14 @@ CDolLoader::CDolLoader(u8* _pBuffer, u32 _Size)
Initialize(_pBuffer, _Size);
}
CDolLoader::CDolLoader(const char* _szFilename)
CDolLoader::CDolLoader(const std::string& filename)
: m_isWii(false)
{
const u64 size = File::GetSize(_szFilename);
const u64 size = File::GetSize(filename);
u8* const tmpBuffer = new u8[(size_t)size];
{
File::IOFile pStream(_szFilename, "rb");
File::IOFile pStream(filename, "rb");
pStream.ReadBytes(tmpBuffer, (size_t)size);
}
+3 -1
View File
@@ -4,12 +4,14 @@
#pragma once
#include <string>
#include "Common/CommonTypes.h"
class CDolLoader
{
public:
CDolLoader(const char* _szFilename);
CDolLoader(const std::string& filename);
CDolLoader(u8* _pBuffer, u32 _Size);
~CDolLoader();

Some files were not shown because too many files have changed in this diff Show More