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:
parent
1f42629112
commit
4f69672b2b
|
@ -45,8 +45,6 @@ _mm_shuffle_epi8(__m128i a, __m128i mask)
|
|||
#include <errno.h>
|
||||
#ifdef __linux__
|
||||
#include <byteswap.h>
|
||||
#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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue