9 #ifndef PLOG_ENABLE_WCHAR_INPUT    11 #       define PLOG_ENABLE_WCHAR_INPUT 1    13 #       define PLOG_ENABLE_WCHAR_INPUT 0    20 #   include <sys/timeb.h>    23 #elif defined(__rtems__)    26 #   if PLOG_ENABLE_WCHAR_INPUT    31 #   include <sys/syscall.h>    32 #   include <sys/time.h>    34 #   if PLOG_ENABLE_WCHAR_INPUT    40 #   define _PLOG_NSTR(x)   L##x    41 #   define PLOG_NSTR(x)    _PLOG_NSTR(x)    43 #   define PLOG_NSTR(x)    x    54         typedef wchar_t nchar;
    64 #if defined(_WIN32) && defined(__BORLANDC__)    66 #elif defined(_WIN32) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)    67             *t = *::localtime(time);
    71             ::localtime_r(time, t);
    75         inline void gmtime_s(
struct tm* t, 
const time_t* time)
    77 #if defined(_WIN32) && defined(__BORLANDC__)    79 #elif defined(_WIN32) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)    91         inline void ftime(Time* t)
   105             ::gettimeofday(&tv, NULL);
   108             t->
millitm = 
static_cast<unsigned short>(tv.tv_usec / 1000);
   115             return GetCurrentThreadId();
   116 #elif defined(__linux__)   117             return static_cast<unsigned int>(::syscall(__NR_gettid));
   118 #elif defined(__FreeBSD__)   120             syscall(SYS_thr_self, &tid);
   121             return static_cast<unsigned int>(tid);
   122 #elif defined(__rtems__)   123             return rtems_task_self();
   124 #elif defined(__APPLE__)   126             pthread_threadid_np(NULL, &tid64);
   127             return static_cast<unsigned int>(tid64);
   131 #if PLOG_ENABLE_WCHAR_INPUT && !defined(_WIN32)   132         inline std::string toNarrow(
const wchar_t* wstr)
   134             size_t wlen = ::wcslen(wstr);
   135             std::string str(wlen * 
sizeof(
wchar_t), 0);
   139                 const char* in = 
reinterpret_cast<const char*
>(&wstr[0]);
   141                 size_t inBytes = wlen * 
sizeof(wchar_t);
   142                 size_t outBytes = str.size();
   144                 iconv_t cd = ::iconv_open(
"UTF-8", 
"WCHAR_T");
   145                 ::iconv(cd, const_cast<char**>(&in), &inBytes, &out, &outBytes);
   148                 str.resize(str.size() - outBytes);
   156         inline std::wstring toWide(
const char* str)
   158             size_t len = ::strlen(str);
   159             std::wstring wstr(len, 0);
   163                 int wlen = MultiByteToWideChar(codePage::kActive, 0, str, static_cast<int>(len), &wstr[0], static_cast<int>(wstr.size()));
   170         inline std::string toNarrow(
const std::wstring& wstr, 
long page)
   172             std::string str(wstr.size() * 
sizeof(wchar_t), 0);
   176                 int len = WideCharToMultiByte(page, 0, wstr.c_str(), 
static_cast<int>(wstr.size()), &str[0], static_cast<int>(str.size()), 0, 0);
   186 #if (defined(_WIN32) && !defined(__MINGW32__)) || defined(__OBJC__)   187             return std::string(func);
   189             const char* funcBegin = func;
   190             const char* funcEnd = ::strchr(funcBegin, 
'(');
   194                 return std::string(func);
   197             for (
const char* i = funcEnd - 1; i >= funcBegin; --i) 
   206             return std::string(funcBegin, funcEnd);
   213             return std::wcsrchr(fileName, L
'.');
   215             return std::strrchr(fileName, 
'.');
   219         inline void splitFileName(
const nchar* fileName, nstring& fileNameNoExt, nstring& fileExt)
   225                 fileNameNoExt.assign(fileName, dot);
   226                 fileExt.assign(dot + 1);
   230                 fileNameNoExt.assign(fileName);
   254             File(
const nchar* fileName) : m_file(-1)
   264             off_t 
open(
const nchar* fileName)
   266 #if defined(_WIN32) && (defined(__BORLANDC__) || defined(__MINGW32__))   267                 m_file = ::_wsopen(fileName, _O_CREAT | _O_WRONLY | _O_BINARY, SH_DENYWR, _S_IREAD | _S_IWRITE);
   268 #elif defined(_WIN32)   269                 ::_wsopen_s(&m_file, fileName, _O_CREAT | _O_WRONLY | _O_BINARY, _SH_DENYWR, _S_IREAD | _S_IWRITE);
   271                 m_file = ::open(fileName, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
   273                 return seek(0, SEEK_END);
   276             int write(
const void* buf, 
size_t count)
   279                 return m_file != -1 ? ::_write(m_file, buf, static_cast<unsigned int>(count)) : -1;
   281                 return m_file != -1 ? 
static_cast<int>(::write(m_file, buf, count)) : -1;
   285             template<
class CharType>
   286             int write(
const std::basic_string<CharType>& str)
   288                 return write(str.data(), str.size() * 
sizeof(CharType));
   291             off_t 
seek(off_t offset, 
int whence)
   294                 return m_file != -1 ? ::_lseek(m_file, offset, whence) : -1;
   296                 return m_file != -1 ? ::lseek(m_file, offset, whence) : -1;
   316                 return ::_wunlink(fileName);
   318                 return ::unlink(fileName);
   322             static int rename(
const nchar* oldFilename, 
const nchar* newFilename)
   325                 return MoveFileW(oldFilename, newFilename);
   327                 return ::rename(oldFilename, newFilename);
   341                 InitializeCriticalSection(&m_sync);
   342 #elif defined(__rtems__)   343                 rtems_semaphore_create(0, 1,
   345                             RTEMS_BINARY_SEMAPHORE |
   346                             RTEMS_INHERIT_PRIORITY, 1, &m_sync);
   348                 ::pthread_mutex_init(&m_sync, 0);
   355                 DeleteCriticalSection(&m_sync);
   356 #elif defined(__rtems__)   357                 rtems_semaphore_delete(m_sync);
   359                 ::pthread_mutex_destroy(&m_sync);
   369                 EnterCriticalSection(&m_sync);
   370 #elif defined(__rtems__)   371                 rtems_semaphore_obtain(m_sync, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
   373                 ::pthread_mutex_lock(&m_sync);
   380                 LeaveCriticalSection(&m_sync);
   381 #elif defined(__rtems__)   382                 rtems_semaphore_release(m_sync);
   384                 ::pthread_mutex_unlock(&m_sync);
   390             CRITICAL_SECTION m_sync;
   392             pthread_mutex_t m_sync;
   420                 m_instance = 
static_cast<T*
>(
this);
   435             static T* m_instance;
 Definition: AndroidAppender.h:5
 
MutexLock(Mutex &mutex)
Definition: Util.h:399
 
off_t seek(off_t offset, int whence)
Definition: Util.h:291
 
unsigned short millitm
Definition: Util.h:99
 
std::string processFuncName(const char *func)
Definition: Util.h:184
 
File(const nchar *fileName)
Definition: Util.h:254
 
File()
Definition: Util.h:250
 
void close()
Definition: Util.h:300
 
void splitFileName(const nchar *fileName, nstring &fileNameNoExt, nstring &fileExt)
Definition: Util.h:219
 
time_t time
Definition: Util.h:98
 
void localtime_s(struct tm *t, const time_t *time)
Definition: Util.h:62
 
static int rename(const nchar *oldFilename, const nchar *newFilename)
Definition: Util.h:322
 
int write(const std::basic_string< CharType > &str)
Definition: Util.h:286
 
char nchar
Definition: Util.h:59
 
void gmtime_s(struct tm *t, const time_t *time)
Definition: Util.h:75
 
std::ostringstream nostringstream
Definition: Util.h:57
 
int write(const void *buf, size_t count)
Definition: Util.h:276
 
~Mutex()
Definition: Util.h:352
 
~Singleton()
Definition: Util.h:423
 
static int unlink(const nchar *fileName)
Definition: Util.h:313
 
std::istringstream nistringstream
Definition: Util.h:58
 
std::string nstring
Definition: Util.h:56
 
off_t open(const nchar *fileName)
Definition: Util.h:264
 
unsigned int gettid()
Definition: Util.h:112
 
Singleton()
Definition: Util.h:417
 
void ftime(Time *t)
Definition: Util.h:102
 
const nchar * findExtensionDot(const nchar *fileName)
Definition: Util.h:210
 
Mutex()
Definition: Util.h:338
 
NonCopyable()
Definition: Util.h:238
 
~MutexLock()
Definition: Util.h:404
 
static T * getInstance()
Definition: Util.h:429
 
~File()
Definition: Util.h:259