diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2014-02-09 16:12:59 +0100 |
|---|---|---|
| committer | Pierre Bourdon <delroth@gmail.com> | 2014-02-09 16:14:13 +0100 |
| commit | e59f770ccbf61f012d148a390e7f76775ab2a02e (patch) | |
| tree | 4fd9c32775ca42490d8bf498e13049f4353c3037 /Source/Core/Common | |
| parent | 9da6900595318620690a5cdb5094a05e17cf094e (diff) | |
Revert "Merge pull request #49 from Parlane/sprintf_tidy"
Change broke the build on Debian stable.
This reverts commit 28755439b36ac8e875d764da5db31ad693459ace, reversing
changes made to 64e01ec763d21915e7166e625f8a3e85b46fbcbb.
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/CDUtils.cpp | 42 | ||||
| -rw-r--r-- | Source/Core/Common/IniFile.h | 4 | ||||
| -rw-r--r-- | Source/Core/Common/Log.h | 2 | ||||
| -rw-r--r-- | Source/Core/Common/LogManager.cpp | 15 | ||||
| -rw-r--r-- | Source/Core/Common/MemArena.cpp | 12 | ||||
| -rw-r--r-- | Source/Core/Common/NandPaths.cpp | 24 | ||||
| -rw-r--r-- | Source/Core/Common/Timer.cpp | 14 |
7 files changed, 67 insertions, 46 deletions
diff --git a/Source/Core/Common/CDUtils.cpp b/Source/Core/Common/CDUtils.cpp index 7e1ebebd27..569ceb3c3b 100644 --- a/Source/Core/Common/CDUtils.cpp +++ b/Source/Core/Common/CDUtils.cpp @@ -2,7 +2,6 @@ #include "CDUtils.h" #include "Common.h" -#include "StringUtil.h" #include <memory> // for std::unique_ptr #ifdef _WIN32 @@ -151,10 +150,10 @@ static struct }; // Returns true if a device is a block or char device and not a symbolic link -bool is_device(const std::string& source_name) +bool is_device(const char *source_name) { struct stat buf; - if (0 != lstat(source_name.c_str(), &buf)) + if (0 != lstat(source_name, &buf)) return false; return ((S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) && @@ -162,15 +161,17 @@ bool is_device(const std::string& source_name) } // Check a device to see if it is a DVD/CD-ROM drive -static bool is_cdrom(const std::string& drive, char *mnttype) +static bool is_cdrom(const char *drive, char *mnttype) { + bool is_cd=false; + int cdfd; + // Check if the device exists if (!is_device(drive)) return(false); - bool is_cd=false; // If it does exist, verify that it is a cdrom/dvd drive - int cdfd = open(drive.c_str(), (O_RDONLY|O_NONBLOCK), 0); + cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0); if ( cdfd >= 0 ) { #ifdef __linux__ @@ -185,16 +186,21 @@ static bool is_cdrom(const std::string& drive, char *mnttype) // Returns a pointer to an array of strings with the device names std::vector<std::string> cdio_get_devices () { + unsigned int i; + char drive[40]; std::vector<std::string> drives; + // Scan the system for DVD/CD-ROM drives. - for (unsigned int i = 0; checklist[i].format; ++i) + for ( i=0; checklist[i].format; ++i ) { - for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) + unsigned int j; + for ( j=checklist[i].num_min; j<=checklist[i].num_max; ++j ) { - std::string drive = StringFromFormat(checklist[i].format, j); - if ( (is_cdrom(drive.c_str(), NULL)) > 0 ) + sprintf(drive, checklist[i].format, j); + if ( (is_cdrom(drive, NULL)) > 0 ) { - drives.push_back(std::move(drive)); + std::string str = drive; + drives.push_back(str); } } } @@ -216,5 +222,17 @@ bool cdio_is_cdrom(std::string device) #endif std::vector<std::string> devices = cdio_get_devices(); - return std::find(devices.begin(), devices.end(), device) != devices.end();; + bool res = false; + for (auto& odevice : devices) + { + if (strncmp(odevice.c_str(), device.c_str(), MAX_PATH) == 0) + { + res = true; + break; + } + } + + devices.clear(); + return res; } + diff --git a/Source/Core/Common/IniFile.h b/Source/Core/Common/IniFile.h index 005f866f65..abfb58b0a6 100644 --- a/Source/Core/Common/IniFile.h +++ b/Source/Core/Common/IniFile.h @@ -140,10 +140,6 @@ public: void SetLines(const char* sectionName, const std::vector<std::string> &lines); bool GetLines(const char* sectionName, std::vector<std::string>& lines, const bool remove_comments = true) const; - inline bool DeleteKey(const char* sectionName, const std::string& key) - { - return DeleteKey(sectionName, key.c_str()); - } bool DeleteKey(const char* sectionName, const char* key); bool DeleteSection(const char* sectionName); diff --git a/Source/Core/Common/Log.h b/Source/Core/Common/Log.h index 8c7a1eb331..b0f3519579 100644 --- a/Source/Core/Common/Log.h +++ b/Source/Core/Common/Log.h @@ -77,8 +77,6 @@ enum LOG_LEVELS LDEBUG = DEBUG_LEVEL, }; -static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID"; - #define LOGTYPES_LEVELS LogTypes::LOG_LEVELS #define LOGTYPES_TYPE LogTypes::LOG_TYPE diff --git a/Source/Core/Common/LogManager.cpp b/Source/Core/Common/LogManager.cpp index 5fe218b2f4..50c6ab400a 100644 --- a/Source/Core/Common/LogManager.cpp +++ b/Source/Core/Common/LogManager.cpp @@ -114,6 +114,7 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char *file, int line, const char *format, va_list args) { char temp[MAX_MSGLEN]; + char msg[MAX_MSGLEN * 2]; LogContainer *log = m_Log[type]; if (!log->IsEnabled() || level > log->GetLevel() || ! log->HasListeners()) @@ -121,15 +122,15 @@ void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); - std::string msg = StringFromFormat("%s %s:%u %c[%s]: %s\n", - Common::Timer::GetTimeFormatted().c_str(), - file, line, - LogTypes::LOG_LEVEL_TO_CHAR[(int)level], - log->GetShortName(), temp); + static const char level_to_char[7] = "-NEWID"; + sprintf(msg, "%s %s:%u %c[%s]: %s\n", + Common::Timer::GetTimeFormatted().c_str(), + file, line, level_to_char[(int)level], + log->GetShortName(), temp); #ifdef ANDROID - Host_SysMessage(msg.c_str()); + Host_SysMessage(msg); #endif - log->Trigger(level, msg.c_str()); + log->Trigger(level, msg); } void LogManager::Init() diff --git a/Source/Core/Common/MemArena.cpp b/Source/Core/Common/MemArena.cpp index 699005dd52..e7f3911e91 100644 --- a/Source/Core/Common/MemArena.cpp +++ b/Source/Core/Common/MemArena.cpp @@ -6,7 +6,6 @@ #include "MemoryUtil.h" #include "MemArena.h" -#include "StringUtil.h" #ifdef _WIN32 #include <windows.h> @@ -58,21 +57,20 @@ void MemArena::GrabLowMemSpace(size_t size) return; } #else + char fn[64]; for (int i = 0; i < 10000; i++) { - std::string file_name = StringFromFormat("dolphinmem.%d", i); - fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); + sprintf(fn, "dolphinmem.%d", i); + fd = shm_open(fn, O_RDWR | O_CREAT | O_EXCL, 0600); if (fd != -1) - { - shm_unlink(file_name.c_str()); break; - } - else if (errno != EEXIST) + if (errno != EEXIST) { ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno)); return; } } + shm_unlink(fn); if (ftruncate(fd, size) < 0) ERROR_LOG(MEMMAP, "Failed to allocate low memory space"); #endif diff --git a/Source/Core/Common/NandPaths.cpp b/Source/Core/Common/NandPaths.cpp index 52e3904536..3ca5550d40 100644 --- a/Source/Core/Common/NandPaths.cpp +++ b/Source/Core/Common/NandPaths.cpp @@ -12,16 +12,20 @@ namespace Common std::string GetTicketFileName(u64 _titleID) { - return StringFromFormat("%sticket/%08x/%08x.tik", - File::GetUserPath(D_WIIUSER_IDX).c_str(), - (u32)(_titleID >> 32), (u32)_titleID); + char TicketFilename[1024]; + sprintf(TicketFilename, "%sticket/%08x/%08x.tik", + File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(_titleID >> 32), (u32)_titleID); + + return TicketFilename; } std::string GetTitleDataPath(u64 _titleID) { - return StringFromFormat("%stitle/%08x/%08x/data/", - File::GetUserPath(D_WIIUSER_IDX).c_str(), - (u32)(_titleID >> 32), (u32)_titleID); + char path[1024]; + sprintf(path, "%stitle/%08x/%08x/data/", + File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(_titleID >> 32), (u32)_titleID); + + return path; } std::string GetTMDFileName(u64 _titleID) @@ -30,9 +34,11 @@ std::string GetTMDFileName(u64 _titleID) } std::string GetTitleContentPath(u64 _titleID) { - return StringFromFormat("%stitle/%08x/%08x/content/", - File::GetUserPath(D_WIIUSER_IDX).c_str(), - (u32)(_titleID >> 32), (u32)_titleID); + char ContentPath[1024]; + sprintf(ContentPath, "%stitle/%08x/%08x/content/", + File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(_titleID >> 32), (u32)_titleID); + + return ContentPath; } bool CheckTitleTMD(u64 _titleID) diff --git a/Source/Core/Common/Timer.cpp b/Source/Core/Common/Timer.cpp index 91a2a2d3ad..267755fb17 100644 --- a/Source/Core/Common/Timer.cpp +++ b/Source/Core/Common/Timer.cpp @@ -167,23 +167,27 @@ u64 Timer::GetLocalTimeSinceJan1970() std::string Timer::GetTimeFormatted() { time_t sysTime; + struct tm * gmTime; + char formattedTime[13]; + char tmp[13]; + time(&sysTime); - - struct tm * gmTime = localtime(&sysTime); + gmTime = localtime(&sysTime); - char tmp[13]; strftime(tmp, 6, "%M:%S", gmTime); // Now tack on the milliseconds #ifdef _WIN32 struct timeb tp; (void)::ftime(&tp); - return StringFromFormat("%s:%03i", tmp, tp.millitm); + sprintf(formattedTime, "%s:%03i", tmp, tp.millitm); #else struct timeval t; (void)gettimeofday(&t, NULL); - return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000)); + sprintf(formattedTime, "%s:%03d", tmp, (int)(t.tv_usec / 1000)); #endif + + return std::string(formattedTime); } // Returns a timestamp with decimals for precise time comparisons |
