mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
Kill off some usages of c_str.
Also changes some function params, but this is ok. Some simplifications were also able to be made (ie. killing off strcmps with ==, etc).
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user