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
This commit is contained in:
Soren Jorvang 2011-03-11 00:37:37 +00:00
parent 1f42629112
commit 4f69672b2b
4 changed files with 6 additions and 34 deletions

View File

@ -45,8 +45,6 @@ _mm_shuffle_epi8(__m128i a, __m128i mask)
#include <errno.h> #include <errno.h>
#ifdef __linux__ #ifdef __linux__
#include <byteswap.h> #include <byteswap.h>
#else
char * strndup(char const *s, size_t n);
#endif #endif
// go to debugger mode // go to debugger mode
@ -86,7 +84,6 @@ inline u64 _rotr64(u64 x, unsigned int shift){
#define unlink _unlink #define unlink _unlink
#define snprintf _snprintf #define snprintf _snprintf
#define vscprintf _vscprintf #define vscprintf _vscprintf
char* strndup (char const *s, size_t n);
// 64 bit offsets for windows // 64 bit offsets for windows
#define fseeko _fseeki64 #define fseeko _fseeki64

View File

@ -83,7 +83,7 @@ LogManager::LogManager()
m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager"); m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay"); 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(); m_consoleLog = new ConsoleListener();
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) { 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) { FileLogListener::FileLogListener(std::string filename) {
m_filename = strndup(filename, 255); m_filename = filename;
m_logfile = fopen(filename, "a+"); m_logfile = fopen(filename.c_str(), "a+");
setEnable(true); setEnable(true);
} }
FileLogListener::~FileLogListener() { FileLogListener::~FileLogListener() {
free(m_filename);
if (m_logfile) if (m_logfile)
fclose(m_logfile); fclose(m_logfile);
} }

View File

@ -40,7 +40,7 @@ public:
class FileLogListener : public LogListener { class FileLogListener : public LogListener {
public: public:
FileLogListener(const char *filename); FileLogListener(std::string filename);
~FileLogListener(); ~FileLogListener();
void Log(LogTypes::LOG_LEVELS, const char *msg); void Log(LogTypes::LOG_LEVELS, const char *msg);
@ -60,7 +60,7 @@ public:
const char *getName() const { return "file"; } const char *getName() const { return "file"; }
private: private:
char *m_filename; std::string m_filename;
FILE *m_logfile; FILE *m_logfile;
bool m_enable; bool m_enable;
}; };

View File

@ -36,27 +36,3 @@ const char *GetLastErrorMsg()
#endif #endif
return errStr; 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