From 4f69672b2b31581746aae907e7757981fc48db77 Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Fri, 11 Mar 2011 00:37:37 +0000 Subject: [PATCH] Remove the need for the less than standard strnlen()/strndup(). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7326 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/CommonFuncs.h | 3 --- Source/Core/Common/Src/LogManager.cpp | 9 ++++----- Source/Core/Common/Src/LogManager.h | 4 ++-- Source/Core/Common/Src/Misc.cpp | 24 ------------------------ 4 files changed, 6 insertions(+), 34 deletions(-) diff --git a/Source/Core/Common/Src/CommonFuncs.h b/Source/Core/Common/Src/CommonFuncs.h index 1a3cec0e63..7dd156f42e 100644 --- a/Source/Core/Common/Src/CommonFuncs.h +++ b/Source/Core/Common/Src/CommonFuncs.h @@ -45,8 +45,6 @@ _mm_shuffle_epi8(__m128i a, __m128i mask) #include #ifdef __linux__ #include -#else -char * strndup(char const *s, size_t n); #endif // go to debugger mode @@ -86,7 +84,6 @@ inline u64 _rotr64(u64 x, unsigned int shift){ #define unlink _unlink #define snprintf _snprintf #define vscprintf _vscprintf -char* strndup (char const *s, size_t n); // 64 bit offsets for windows #define fseeko _fseeki64 diff --git a/Source/Core/Common/Src/LogManager.cpp b/Source/Core/Common/Src/LogManager.cpp index 815dd2ec6d..6c47b78d15 100644 --- a/Source/Core/Common/Src/LogManager.cpp +++ b/Source/Core/Common/Src/LogManager.cpp @@ -83,7 +83,7 @@ LogManager::LogManager() m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager"); m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay"); - m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX).c_str()); + m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX)); m_consoleLog = new ConsoleListener(); for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) { @@ -176,14 +176,13 @@ void LogContainer::trigger(LogTypes::LOG_LEVELS level, const char *msg) { } } -FileLogListener::FileLogListener(const char *filename) { - m_filename = strndup(filename, 255); - m_logfile = fopen(filename, "a+"); +FileLogListener::FileLogListener(std::string filename) { + m_filename = filename; + m_logfile = fopen(filename.c_str(), "a+"); setEnable(true); } FileLogListener::~FileLogListener() { - free(m_filename); if (m_logfile) fclose(m_logfile); } diff --git a/Source/Core/Common/Src/LogManager.h b/Source/Core/Common/Src/LogManager.h index b948cb20af..78b383d64c 100644 --- a/Source/Core/Common/Src/LogManager.h +++ b/Source/Core/Common/Src/LogManager.h @@ -40,7 +40,7 @@ public: class FileLogListener : public LogListener { public: - FileLogListener(const char *filename); + FileLogListener(std::string filename); ~FileLogListener(); void Log(LogTypes::LOG_LEVELS, const char *msg); @@ -60,7 +60,7 @@ public: const char *getName() const { return "file"; } private: - char *m_filename; + std::string m_filename; FILE *m_logfile; bool m_enable; }; diff --git a/Source/Core/Common/Src/Misc.cpp b/Source/Core/Common/Src/Misc.cpp index 116743c517..baa8266ced 100644 --- a/Source/Core/Common/Src/Misc.cpp +++ b/Source/Core/Common/Src/Misc.cpp @@ -36,27 +36,3 @@ const char *GetLastErrorMsg() #endif return errStr; } - -#if !defined(__linux__) && !defined(_WIN32) -// strlen with cropping after size n -static size_t strnlen(const char *s, size_t n) -{ - const char *p = (const char *)memchr(s, 0, n); - - return p ? (size_t)(p - s) : n; -} -#endif -#if defined(_WIN32) || !(__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -// strdup with cropping after size n -char* strndup(char const *s, size_t n) -{ - size_t len = strnlen(s, n); - char *dup = (char *)malloc(len + 1); - - if (dup == NULL) - return NULL; - - dup[len] = '\0'; - return (char *)memcpy(dup, s, len); -} -#endif