Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #164 from lioncash/cstr-cull
Kill off some usages of c_str.
  • Loading branch information
delroth committed Mar 14, 2014
2 parents 12c2e34 + a82675b commit 8d679e7
Show file tree
Hide file tree
Showing 170 changed files with 810 additions and 702 deletions.
2 changes: 1 addition & 1 deletion Source/Core/AudioCommon/AudioCommon.cpp
Expand Up @@ -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;
Expand Down
22 changes: 16 additions & 6 deletions Source/Core/AudioCommon/Mixer.h
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include <string>

#include "AudioCommon/WaveFile.h"
#include "Common/StdMutex.h"

Expand Down Expand Up @@ -57,23 +59,31 @@ class CMixer {
// ---------------------


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");
}
}
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/AudioCommon/WaveFile.cpp
Expand Up @@ -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"
Expand All @@ -21,22 +23,22 @@ 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];

// 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;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/AudioCommon/WaveFile.h
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <string>
#include "Common/FileUtil.h"

class WaveFileWriter
Expand All @@ -31,7 +32,7 @@ class WaveFileWriter
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; }
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Common/ChunkFile.h
Expand Up @@ -262,15 +262,15 @@ class PointerWrap
}
}

void DoMarker(const char* prevName, u32 arbitraryNumber = 0x42)
void DoMarker(const std::string& prevName, u32 arbitraryNumber = 0x42)
{
u32 cookie = arbitraryNumber;
Do(cookie);

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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Common/FileUtil.cpp
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Common/FileUtil.h
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/LinearDiskCache.h
Expand Up @@ -6,6 +6,7 @@

#include <cstring>
#include <fstream>
#include <string>

#include "Common/Common.h"
#include "Common/FileUtil.h"
Expand Down Expand Up @@ -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;

Expand Down
56 changes: 39 additions & 17 deletions Source/Core/Common/SDCardUtil.cpp
Expand Up @@ -33,6 +33,7 @@
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>

#include "Common/Common.h"
#include "Common/FileUtil.h"
Expand Down Expand Up @@ -188,15 +189,16 @@ 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;

// 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;
}
Expand All @@ -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;
}

Expand All @@ -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_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_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;
}
3 changes: 2 additions & 1 deletion Source/Core/Common/SDCardUtil.h
Expand Up @@ -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);
4 changes: 2 additions & 2 deletions Source/Core/Common/StringUtil.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/StringUtil.h
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Common/SymbolDB.cpp
Expand Up @@ -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;
}

Expand Down
11 changes: 6 additions & 5 deletions Source/Core/Common/SymbolDB.h
Expand Up @@ -80,21 +80,22 @@ class SymbolDB
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;
else
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();
Expand Down

0 comments on commit 8d679e7

Please sign in to comment.