function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
FreeZipPacker
void FreeZipPacker(ZIP_PACKER *p) { UINT i; // Validate arguments if (p == NULL) { return; } ReleaseFifo(p->Fifo); for (i = 0;i < LIST_NUM(p->FileList);i++) { ZIP_FILE *f = LIST_DATA(p->FileList, i); Free(f); } ReleaseList(p->FileList); Free(p); }
/* Release of ZIP packer*/
Release of ZIP packer
ZipAddFileSimple
void ZipAddFileSimple(ZIP_PACKER *p, char *name, UINT64 dt, UINT attribute, void *data, UINT size) { // Validate arguments if (p == NULL || IsEmptyStr(name) || (size != 0 && data == NULL)) { return; } ZipAddFileStart(p, name, size, dt, attribute); ZipAddFileData(p, data, 0, size); }
/* Simply add the file*/
Simply add the file
ZipAddFileFooter
void ZipAddFileFooter(ZIP_PACKER *p) { ZIP_DATA_FOOTER f; // Validate arguments if (p == NULL) { return; } Zero(&f, sizeof(f)); WriteZipDataFooter(p->CurrentFile, &f); WriteFifo(p->Fifo, &f, sizeof(f)); }
/* Append a file footer*/
Append a file footer
ZipWriteW
bool ZipWriteW(ZIP_PACKER *p, wchar_t *name) { FIFO *f; // Validate arguments if (p == NULL || name == NULL) { return false; } f = ZipFinish(p); if (f == NULL) { return false; } return FileWriteAllW(name, FifoPtr(f), FifoSize(f)); }
/* Output the ZIP data to a file*/
Output the ZIP data to a file
WriteZipDataFooter
void WriteZipDataFooter(ZIP_FILE *f, ZIP_DATA_FOOTER *h) { // Validate arguments if (f == NULL || h ==NULL) { return; } h->Signature = Endian32(Swap32(0x08074B50)); h->CompSize = h->UncompSize = Endian32(Swap32(f->Size)); h->Crc32 = Endian32(Swap32(f->Crc32)); }
/* Creating a ZIP data footer*/
Creating a ZIP data footer
InitCrc32
void InitCrc32() { UINT poly = 0xEDB88320; UINT u, i, j; for (i = 0;i < 256;i++) { u = i; for (j = 0;j < 8;j++) { if ((u & 0x1) != 0) { u = (u >> 1) ^ poly; } else { u >>= 1; } } crc32_table[i] = u; } }
/* Initialize the common table of CRC32*/
Initialize the common table of CRC32
Crc32
UINT Crc32(void *buf, UINT pos, UINT len) { return Crc32Finish(Crc32First(buf, pos, len)); }
/* CRC32 arithmetic processing*/
CRC32 arithmetic processing
SaveFileW
bool SaveFileW(wchar_t *name, void *data, UINT size) { IO *io; // Validate arguments if (name == NULL || (data == NULL && size != 0)) { return false; } io = FileCreateW(name); if (io == NULL) { return false; } if (FileWrite(io, data, size) == false) { FileClose(io); return false; } FileClose(io); return true; }
/* Save the file*/
Save the file
IsFile
bool IsFile(char *name) { wchar_t *name_w = CopyStrToUni(name); bool ret = IsFileW(name_w); Free(name_w); return ret; }
/* Check whether the file exists*/
Check whether the file exists
FileReplaceRenameW
bool FileReplaceRenameW(wchar_t *old_name, wchar_t *new_name) { // Validate arguments if (old_name == NULL || new_name == NULL) { return false; } if (FileCopyW(old_name, new_name) == false) { return false; } FileDeleteW(old_name); return true; }
/* Rename to replace the file*/
Rename to replace the file
ConvertSafeFileName
void ConvertSafeFileName(char *dst, UINT size, char *src) { UINT i; // Validate arguments if (dst == NULL || src == NULL) { return; } StrCpy(dst, size, src); for (i = 0;i < StrLen(dst);i++) { if (IsSafeChar(dst[i]) == false) { dst[i] = '_'; } } }
/* Make the file name safe*/
Make the file name safe
GetDiskFree
bool GetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size) { bool ret; // Validate arguments if (path == NULL) { path = "./"; } #ifdef OS_WIN32 ret = Win32GetDiskFree(path, free_size, used_size, total_size); #else // OS_WIN32 ret = UnixGetDiskFree(path, free_size, used_size, total_size); #endif // OS_WIN32 return ret; }
/* Get the free disk space*/
Get the free disk space
EnumDirWithSubDirs
TOKEN_LIST *EnumDirWithSubDirs(char *dirname) { TOKEN_LIST *ret; UNI_TOKEN_LIST *ret2; wchar_t tmp[MAX_SIZE]; // Validate arguments if (dirname == NULL) { dirname = "./"; } StrToUni(tmp, sizeof(tmp), dirname); ret2 = EnumDirWithSubDirsW(tmp); ret = UniTokenListToTokenList(ret2); UniFreeToken(ret2); return ret; }
/* Enumeration of direction with all sub directories*/
Enumeration of direction with all sub directories
EnumDirEx
DIRLIST *EnumDirEx(char *dirname, COMPARE *compare) { wchar_t *dirname_w = CopyStrToUni(dirname); DIRLIST *ret = EnumDirExW(dirname_w, compare); Free(dirname_w); return ret; }
/* Enumeration of directory*/
Enumeration of directory
CompareDirListByName
int CompareDirListByName(void *p1, void *p2) { DIRENT *d1, *d2; if (p1 == NULL || p2 == NULL) { return 0; } d1 = *(DIRENT **)p1; d2 = *(DIRENT **)p2; if (d1 == NULL || d2 == NULL) { return 0; } return UniStrCmpi(d1->FileNameW, d2->FileNameW); }
/* Comparison of DIRLIST list entry*/
Comparison of DIRLIST list entry
FreeDir
void FreeDir(DIRLIST *d) { UINT i; // Validate arguments if (d == NULL) { return; } for (i = 0;i < d->NumFiles;i++) { DIRENT *f = d->File[i]; Free(f->FileName); Free(f->FileNameW); Free(f); } Free(d->File); Free(d); }
/* Release the enumeration of the directory */
Release the enumeration of the directory
UniSafeFileName
void UniSafeFileName(wchar_t *name) { UINT i, len, dlen; static wchar_t *danger_str = L"\\/:*?\"<>|"; // Validate arguments if (name == NULL) { return; } dlen = UniStrLen(danger_str); len = UniStrLen(name); for (i = 0;i < len;i++) { wchar_t c = name[i]; UINT j; for (j = 0;j < dlen;j++) { if (c == danger_str[j]) { c = L'_'; } } name[i] = c; } }
/* Make the file name safe*/
Make the file name safe
ReadHamcoreW
BUF *ReadHamcoreW(wchar_t *filename) { char *filename_a = CopyUniToStr(filename); BUF *ret; ret = ReadHamcore(filename_a); Free(filename_a); return ret; }
/* Read HamCore file*/
Read HamCore file
FreeHamcore
void FreeHamcore() { UINT i; for (i = 0;i < LIST_NUM(hamcore);i++) { HC *c = LIST_DATA(hamcore, i); Free(c->FileName); if (c->Buffer != NULL) { Free(c->Buffer); } Free(c); } ReleaseList(hamcore); FileClose(hamcore_io); hamcore_io = NULL; hamcore = NULL; }
/* Release of HamCore file system*/
Release of HamCore file system
CompareHamcore
int CompareHamcore(void *p1, void *p2) { HC *c1, *c2; if (p1 == NULL || p2 == NULL) { return 0; } c1 = *(HC **)p1; c2 = *(HC **)p2; if (c1 == NULL || c2 == NULL) { return 0; } return StrCmpi(c1->FileName, c2->FileName); }
/* Comparison of the HCs*/
Comparison of the HCs
GetExeDir
void GetExeDir(char *name, UINT size) { // Validate arguments if (name == NULL) { return; } GetDirNameFromFilePath(name, size, exe_file_name); }
/* Getting the name of the directory where the EXE file is in*/
Getting the name of the directory where the EXE file is in
GetExeName
void GetExeName(char *name, UINT size) { // Validate arguments if (name == NULL) { return; } StrCpy(name, size, exe_file_name); }
/* Get the EXE file name*/
Get the EXE file name
InitGetExeName
void InitGetExeName(char *arg) { wchar_t *arg_w = NULL; // Validate arguments if (arg == NULL) { arg = "./a.out"; } arg_w = CopyUtfToUni(arg); #ifdef OS_WIN32 Win32GetExeNameW(exe_file_name_w, sizeof(exe_file_name_w)); #else // OS_WIN32 UnixGetExeNameW(exe_file_name_w, sizeof(exe_file_name_w), arg_w); #endif // OS_WIN32 UniToStr(exe_file_name, sizeof(exe_file_name), exe_file_name_w); Free(arg_w); }
/* Initialization of the acquisition of the EXE file name*/
Initialization of the acquisition of the EXE file name
ConbinePath
void ConbinePath(char *dst, UINT size, char *dirname, char *filename) { wchar_t dst_w[MAX_PATH]; wchar_t *dirname_w = CopyStrToUni(dirname); wchar_t *filename_w = CopyStrToUni(filename); ConbinePathW(dst_w, sizeof(dst_w), dirname_w, filename_w); Free(dirname_w); Free(filename_w); UniToStr(dst, size, dst_w); }
/* Combine the two paths*/
Combine the two paths
IsFileExists
bool IsFileExists(char *name) { wchar_t *name_w = CopyStrToUni(name); bool ret = IsFileExistsW(name_w); Free(name_w); return ret; }
/* Check whether the file exists*/
Check whether the file exists
GetCurrentPathEnvStr
char *GetCurrentPathEnvStr() { char tmp[1024]; char *tag_name; #ifdef OS_WIN32 tag_name = "Path"; #else // OS_WIN32 tag_name = "PATH"; #endif // OS_WIN32 if (GetEnv(tag_name, tmp, sizeof(tmp)) == false) { #ifdef OS_WIN32 Win32GetCurrentDir(tmp, sizeof(tmp)); #else // OS_WIN32 UnixGetCurrentDir(tmp, sizeof(tmp)); #endif // OS_WIN32 } return CopyStr(tmp); }
/* Get the current contents of the PATH environment variable*/
Get the current contents of the PATH environment variable
FileRenameW
bool FileRenameW(wchar_t *old_name, wchar_t *new_name) { wchar_t tmp1[MAX_SIZE]; wchar_t tmp2[MAX_SIZE]; // Validate arguments if (old_name == NULL || new_name == NULL) { return false; } InnerFilePathW(tmp1, sizeof(tmp1), old_name); InnerFilePathW(tmp2, sizeof(tmp2), new_name); return FileRenameInnerW(tmp1, tmp2); }
/* Rename the file*/
Rename the file
ConvertPathW
void ConvertPathW(wchar_t *path) { UINT i, len; #ifdef PATH_BACKSLASH wchar_t new_char = L'\\'; #else wchar_t new_char = L'/'; #endif len = UniStrLen(path); for (i = 0;i < len;i++) { if (path[i] == L'\\' || path[i] == L'/') { path[i] = new_char; } } }
/* Convert the path*/
Convert the path
DeleteDir
bool DeleteDir(char *name) { wchar_t *name_w = CopyStrToUni(name); bool ret = DeleteDirW(name_w); Free(name_w); return ret; }
/* Delete the directory*/
Delete the directory
InnerFilePathW
void InnerFilePathW(wchar_t *dst, UINT size, wchar_t *src) { // Validate arguments if (dst == NULL || src == NULL) { return; } if (src[0] == L'@') { wchar_t dir[MAX_SIZE]; GetLogDirW(dir, sizeof(dir)); ConbinePathW(dst, size, dir, &src[1]); } else if (src[0] == L'$') { wchar_t dir[MAX_SIZE]; GetDbDirW(dir, sizeof(dir)); ConbinePathW(dst, size, dir, &src[1]); } else { NormalizePathW(dst, size, src); } }
/* Generation of internal file path*/
Generation of internal file path
MakeDirEx
bool MakeDirEx(char *name) { bool ret; wchar_t *name_w = CopyStrToUni(name); ret = MakeDirExW(name_w); Free(name_w); return ret; }
/* Recursive directory creation*/
Recursive directory creation
MakeDir
bool MakeDir(char *name) { wchar_t *name_w = CopyStrToUni(name); bool ret = MakeDirW(name_w); Free(name_w); return ret; }
/* Create a directory*/
Create a directory
FileDelete
bool FileDelete(char *name) { wchar_t *name_w = CopyStrToUni(name); bool ret = FileDeleteW(name_w); Free(name_w); return ret; }
/* Delete the file*/
Delete the file
FileSeek
bool FileSeek(IO *o, UINT mode, int offset) { // Validate arguments if (o == NULL) { return false; } if (o->HamMode == false) { return OSFileSeek(o->pData, mode, offset); } else { return false; } }
/* Seek the file*/
Seek the file
FileSize64
UINT64 FileSize64(IO *o) { // Validate arguments if (o == NULL) { return 0; } if (o->HamMode == false) { return OSFileSize(o->pData); } else { return (UINT64)o->HamBuf->Size; } }
/* Get the file size*/
Get the file size
FileRead
bool FileRead(IO *o, void *buf, UINT size) { // Validate arguments if (o == NULL || buf == NULL) { return false; } // KS KS_INC(KS_IO_READ_COUNT); KS_ADD(KS_IO_TOTAL_READ_SIZE, size); if (size == 0) { return true; } if (o->HamMode == false) { return OSFileRead(o->pData, buf, size); } else { return ReadBuf(o->HamBuf, buf, size) == size ? true : false; } }
/* Read from a file*/
Read from a file
FileWrite
bool FileWrite(IO *o, void *buf, UINT size) { // Validate arguments if (o == NULL || buf == NULL) { return false; } if (o->WriteMode == false) { return false; } // KS KS_INC(KS_IO_WRITE_COUNT); KS_ADD(KS_IO_TOTAL_WRITE_SIZE, size); if (size == 0) { return true; } return OSFileWrite(o->pData, buf, size); }
/* Write to a file*/
Write to a file
FileFlush
void FileFlush(IO *o) { // Validate arguments if (o == NULL) { return; } if (o->HamMode) { return; } OSFileFlush(o->pData); }
/* Flush the file*/
Flush the file
FileClose
void FileClose(IO *o) { FileCloseEx(o, false); }
/* Close the file*/
Close the file
FileCreateInnerW
IO *FileCreateInnerW(wchar_t *name) { IO *o; void *p; wchar_t name2[MAX_SIZE]; // Validate arguments if (name == NULL) { return NULL; } UniStrCpy(name2, sizeof(name2), name); ConvertPathW(name2); p = OSFileCreateW(name2); if (p == NULL) { return NULL; } o = ZeroMalloc(sizeof(IO)); o->pData = p; UniStrCpy(o->NameW, sizeof(o->NameW), name2); UniToStr(o->Name, sizeof(o->Name), o->NameW); o->WriteMode = true; // KS KS_INC(KS_IO_CREATE_COUNT); return o; }
/* Create a file*/
Create a file
FileWriteAllW
bool FileWriteAllW(wchar_t *name, void *data, UINT size) { IO *io; // Validate arguments if (name == NULL || (data == NULL && size != 0)) { return false; } io = FileCreateW(name); if (io == NULL) { return false; } FileWrite(io, data, size); FileClose(io); return true; }
/* Write all the data to the file*/
Write all the data to the file
c_gmtime_r
struct tm * c_gmtime_r(const time_64t* timep, struct tm *tm) { c_timesub(timep, 0L, tm); return tm; }
/* * Re-entrant version of gmtime. */
Re-entrant version of gmtime.
TickRealtime
UINT TickRealtime() { #if defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES) || defined(UNIX_MACOS) return Tick() + 1; #else return TickRealtimeManual() + 1; #endif }
/* Get the real-time system timer*/
Get the real-time system timer
TickRealtimeManual
UINT TickRealtimeManual() { UINT64 ret; Lock(tick_manual_lock); { ret = TickGetRealtimeTickValue64(); if (last_manual_tick != 0 && (last_manual_tick > ret)) { manual_tick_add_value += (last_manual_tick - ret); } last_manual_tick = ret; } Unlock(tick_manual_lock); return (UINT)(ret + manual_tick_add_value); }
/* For systems which not have clock_gettime (such as MacOS X)*/
For systems which not have clock_gettime (such as MacOS X)
TickGetRealtimeTickValue64
UINT64 TickGetRealtimeTickValue64() { struct timeval tv; struct timezone tz; UINT64 ret; memset(&tv, 0, sizeof(tv)); memset(&tz, 0, sizeof(tz)); gettimeofday(&tv, &tz); if (sizeof(tv.tv_sec) != 4) { ret = (UINT64)tv.tv_sec * 1000ULL + (UINT64)tv.tv_usec / 1000ULL; } else { ret = (UINT64)((UINT64)((UINT32)tv.tv_sec)) * 1000ULL + (UINT64)tv.tv_usec / 1000ULL; } return ret; }
/* Returns a appropriate value from the current time*/
Returns a appropriate value from the current time
GetNumberOfCpu
UINT GetNumberOfCpu() { UINT ret = 0; if (cached_number_of_cpus == 0) { UINT i = 0; #ifdef OS_WIN32 i = Win32GetNumberOfCpuInner(); #else // OS_WIN32 i = UnixGetNumberOfCpuInner(); #endif // OS_WIN32 if (i == 0) { i = 8; } cached_number_of_cpus = i; } ret = cached_number_of_cpus; if (ret == 0) { ret = 1; } if (ret > 128) { ret = 128; } return ret; }
/* Get the number of CPUs*/
Get the number of CPUs
NewThreadList
LIST *NewThreadList() { LIST *o = NewList(NULL); return o; }
/* Creating a thread list*/
Creating a thread list
AddThreadToThreadList
void AddThreadToThreadList(LIST *o, THREAD *t) { // Validate arguments if (o == NULL || t == NULL) { return; } LockList(o); { if (IsInList(o, t) == false) { AddRef(t->ref); Add(o, t); } } UnlockList(o); }
/* Add the thread to the thread list*/
Add the thread to the thread list
StopThreadList
void StopThreadList(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } LockList(o); { for (i = 0;i < LIST_NUM(o);i++) { THREAD *t = LIST_DATA(o, i); WaitThread(t, INFINITE); } } UnlockList(o); }
/* Stop all the threads in the thread list*/
Stop all the threads in the thread list
FreeThreadList
void FreeThreadList(LIST *o) { UINT i; // Validate arguments if (o == NULL) { return; } LockList(o); { for (i = 0;i < LIST_NUM(o);i++) { THREAD *t = LIST_DATA(o, i); WaitThread(t, INFINITE); ReleaseThread(t); } DeleteAll(o); } UnlockList(o); ReleaseList(o); }
/* Release the thread list*/
Release the thread list
GetHomeDirW
void GetHomeDirW(wchar_t *path, UINT size) { // Validate arguments if (path == NULL) { return; } if (GetEnvW(L"HOME", path, size) == false) { wchar_t drive[MAX_SIZE]; wchar_t hpath[MAX_SIZE]; if (GetEnvW(L"HOMEDRIVE", drive, sizeof(drive)) && GetEnvW(L"HOMEPATH", hpath, sizeof(hpath))) { UniFormat(path, size, L"%s%s", drive, hpath); } else { #ifdef OS_WIN32 Win32GetCurrentDirW(path, size); #else // OS_WIN32 UnixGetCurrentDirW(path, size); #endif // OS_WIN32 } } }
/* Get the home directory*/
Get the home directory
GetEnv
bool GetEnv(char *name, char *data, UINT size) { char *ret; // Validate arguments if (name == NULL || data == NULL) { return false; } StrCpy(data, size, ""); ret = getenv(name); if (ret == NULL) { return false; } StrCpy(data, size, ret); return true; }
/* Get the environment variable string*/
Get the environment variable string
GetMemInfo
void GetMemInfo(MEMINFO *info) { OSGetMemInfo(info); }
/* Get the memory information*/
Get the memory information
NewSingleInstance
INSTANCE *NewSingleInstance(char *instance_name) { return NewSingleInstanceEx(instance_name, false); }
/* Start the single-instance*/
Start the single-instance
FreeSingleInstance
void FreeSingleInstance(INSTANCE *inst) { // Validate arguments if (inst == NULL) { return; } OSFreeSingleInstance(inst->pData); if (inst->Name != NULL) { Free(inst->Name); } Free(inst); }
/* Release of single instance*/
Release of single instance
Run
bool Run(char *filename, char *arg, bool hide, bool wait) { // Validate arguments if (filename == NULL) { return false; } return OSRun(filename, arg, hide, wait); }
/* Run the process*/
Run the process
GetDateTimeStr64Uni
void GetDateTimeStr64Uni(wchar_t *str, UINT size, UINT64 sec64) { char tmp[MAX_SIZE]; if (str == NULL) { return; } GetDateTimeStr64(tmp, sizeof(tmp), sec64); StrToUni(str, size, tmp); }
/* Date and time related functions*/
Date and time related functions
SafeTime64
UINT64 SafeTime64(UINT64 sec64) { return MAKESURE(sec64, 0, 4102243323123ULL); }
/* Convert to a time to be used safely in the current POSIX implementation*/
Convert to a time to be used safely in the current POSIX implementation
InitThreading
void InitThreading() { thread_pool = NewSk(); thread_count = NewCounter(); }
/* Initialization of thread pool*/
Initialization of thread pool
SetThreadName
void SetThreadName(UINT thread_id, char *name, void *param) { #ifdef OS_WIN32 if (IsDebug()) { char tmp[MAX_SIZE]; if (name == NULL) { strcpy(tmp, "idle"); } else { sprintf(tmp, "%s (0x%x)", name, (UINT)param); } Win32SetThreadName(thread_id, tmp); } #else // OS_WIN32 #ifdef _DEBUG #ifdef PR_SET_NAME char tmp[MAX_SIZE]; if (name == NULL) { strcpy(tmp, "idle"); } else { sprintf(tmp, "%s (%p)", name, param); } tmp[15] = 0; prctl(PR_SET_NAME, (unsigned long)tmp, 0, 0, 0); #endif // PR_SET_NAME #endif // _DEBUG #endif // OS_WIN32 }
/* Set the thread name*/
Set the thread name
CleanupThread
void CleanupThread(THREAD *t) { // Validate arguments if (t == NULL) { return; } ReleaseEvent(t->init_finished_event); ReleaseEvent(t->release_event); ReleaseList(t->PoolWaitList); if (t->Name != NULL) { Free(t->Name); } Free(t); current_num_thread--; //Debug("current_num_thread = %u\n", current_num_thread); }
/* Clean up of thread (pool)*/
Clean up of thread (pool)
ReleaseThread
void ReleaseThread(THREAD *t) { UINT ret; EVENT *e; // Validate arguments if (t == NULL) { return; } e = t->release_event; if (e != NULL) { AddRef(e->ref); } ret = Release(t->ref); Set(e); ReleaseEvent(e); if (ret == 0) { CleanupThread(t); } }
/* Release thread (pool)*/
Release thread (pool)
NoticeThreadInit
void NoticeThreadInit(THREAD *t) { // Validate arguments if (t == NULL) { return; } // Notification Set(t->init_finished_event); }
/* Notify the completion of the thread initialization (pool)*/
Notify the completion of the thread initialization (pool)
WaitThreadInit
void WaitThreadInit(THREAD *t) { // Validate arguments if (t == NULL) { return; } // KS KS_INC(KS_WAITFORTHREAD_COUNT); // Wait Wait(t->init_finished_event, INFINITE); }
/* Wait the completion of the thread initialization (pool)*/
Wait the completion of the thread initialization (pool)
ThreadId
UINT ThreadId() { return OSThreadId(); }
/* Get Thread ID*/
Get Thread ID
NewThreadInternal
THREAD *NewThreadInternal(THREAD_PROC *thread_proc, void *param) { THREAD *t; UINT retry = 0; // Validate arguments if (thread_proc == NULL) { return NULL; } // Initialize Thread object t = ZeroMalloc(sizeof(THREAD)); t->init_finished_event = NewEvent(); t->param = param; t->ref = NewRef(); t->thread_proc = thread_proc; // Wait until the OS to initialize the thread while (true) { if ((retry++) > 60) { printf("\n\n*** error: new thread create failed.\n\n"); AbortExit(); } if (OSInitThread(t)) { break; } SleepThread(500); } // KS KS_INC(KS_NEWTHREAD_COUNT); return t; }
/* Creating a thread*/
Creating a thread
ReleaseThreadInternal
void ReleaseThreadInternal(THREAD *t) { // Validate arguments if (t == NULL) { return; } if (Release(t->ref) == 0) { CleanupThreadInternal(t); } }
/* Release of thread*/
Release of thread
CleanupThreadInternal
void CleanupThreadInternal(THREAD *t) { // Validate arguments if (t == NULL) { return; } // Release of the thread OSFreeThread(t); // Release the event ReleaseEvent(t->init_finished_event); // Memory release Free(t); // KS KS_INC(KS_FREETHREAD_COUNT); }
/* Clean up of the thread*/
Clean up of the thread
WaitThreadInternal
bool WaitThreadInternal(THREAD *t) { // Validate arguments if (t == NULL) { return false; } return OSWaitThread(t); }
/* Wait for the termination of the thread*/
Wait for the termination of the thread
NoticeThreadInitInternal
void NoticeThreadInitInternal(THREAD *t) { // Validate arguments if (t == NULL) { return; } // Notify Set(t->init_finished_event); }
/* Notify that the thread initialization is complete*/
Notify that the thread initialization is complete
WaitThreadInitInternal
void WaitThreadInitInternal(THREAD *t) { // Validate arguments if (t == NULL) { return; } // KS KS_INC(KS_WAITFORTHREAD_COUNT); // Wait Wait(t->init_finished_event, INFINITE); }
/* Wait for completion of thread initialization*/
Wait for completion of thread initialization
GetDateTimeStrEx
void GetDateTimeStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale) { wchar_t tmp1[MAX_SIZE]; wchar_t tmp2[MAX_SIZE]; // Validate arguments if (str == NULL || st == NULL) { return; } GetDateStrEx(tmp1, sizeof(tmp1), st, locale); GetTimeStrEx(tmp2, sizeof(tmp2), st, locale); UniFormat(str, size, L"%s %s", tmp1, tmp2); }
/* Get the date and time string by using the locale information*/
Get the date and time string by using the locale information
GetTimeStrEx
void GetTimeStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale) { wchar_t *tag = L"%02u%s%02u%s%02u%s"; // Validate arguments if (str == NULL || st == NULL) { return; } if (_GETLANG() == SE_LANG_JAPANESE || _GETLANG() == SE_LANG_CHINESE_ZH) { tag = L"%2u%s%2u%s%2u%s"; } locale = (locale != NULL ? locale : &current_locale); UniFormat(str, size, tag, st->wHour, locale->HourStr, st->wMinute, locale->MinuteStr, st->wSecond, locale->SecondStr); }
/* Get the time string by using the locale information*/
Get the time string by using the locale information
GetDateStrEx
void GetDateStrEx(wchar_t *str, UINT size, SYSTEMTIME *st, LOCALE *locale) { wchar_t *tag = L"%04u%s%02u%s%02u%s (%s)"; // Validate arguments if (str == NULL || st == NULL) { return; } if (_GETLANG() == SE_LANG_JAPANESE || _GETLANG() == SE_LANG_CHINESE_ZH) { tag = L"%4u%s%2u%s%2u%s(%s)"; } locale = (locale != NULL ? locale : &current_locale); UniFormat(str, size, tag, st->wYear, locale->YearStr, st->wMonth, locale->MonthStr, st->wDay, locale->DayStr, locale->DayOfWeek[st->wDayOfWeek]); }
/* Get a date string by using the locale information*/
Get a date string by using the locale information
GetTimeStrMilli
void GetTimeStrMilli(char *str, UINT size, SYSTEMTIME *st) { // Validate arguments if (st == NULL || str == NULL) { return; } Format(str, size, "%02u:%02u:%02u.%03u", st->wHour, st->wMinute, st->wSecond, st->wMilliseconds); }
/* Get the time string to milliseconds (for example, 12:34:56.789)*/
Get the time string to milliseconds (for example, 12:34:56.789)
GetDateStr
void GetDateStr(char *str, UINT size, SYSTEMTIME *st) { // Validate arguments if (str == NULL || st == NULL) { return; } Format(str, size, "%04u-%02u-%02u", st->wYear, st->wMonth, st->wDay); }
/* Get the date string (example: 2004/07/23)*/
Get the date string (example: 2004/07/23)
GetDateTimeStr
void GetDateTimeStr(char *str, UINT size, SYSTEMTIME *st) { // Validate arguments if (str == NULL || st == NULL) { return; } Format(str, size, "%04u-%02u-%02u %02u:%02u:%02u", st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond); }
/* Get the date and time string (example: 2004/07/23 12:34:56)*/
Get the date and time string (example: 2004/07/23 12:34:56)
GetDateTimeStrMilli
void GetDateTimeStrMilli(char *str, UINT size, SYSTEMTIME *st) { // Validate arguments if (str == NULL || st == NULL) { return; } Format(str, size, "%04u-%02u-%02u %02u:%02u:%02u.%03u", st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond, st->wMilliseconds); }
/* Get the date and time string in milliseconds (example: 2004/07/23 12:34:56.789)*/
Get the date and time string in milliseconds (example: 2004/07/23 12:34:56.789)
DateTimeStrRFC3339ToSystemTime64
UINT64 DateTimeStrRFC3339ToSystemTime64(char *str) { SYSTEMTIME st; if (DateTimeStrRFC3339ToSystemTime(&st, str)) { return SystemToUINT64(&st); } else { return 0; } }
/* Convert string RFC3339 format (example: 2017-09-27T18:25:55.434-9:00) to UINT64*/
Convert string RFC3339 format (example: 2017-09-27T18:25:55.434-9:00) to UINT64
SetLocale
void SetLocale(wchar_t *str) { wchar_t *set_locale_str; LOCALE tmp; if (str != NULL) { set_locale_str = str; } else { set_locale_str = default_locale_str; } if (LoadLocale(&tmp, set_locale_str) == false) { if (LoadLocale(&tmp, default_locale_str) == false) { return; } } Copy(&current_locale, &tmp, sizeof(LOCALE)); }
/* Set the locale information*/
Set the locale information
SystemToDosDate
USHORT SystemToDosDate(SYSTEMTIME *st) { return (USHORT)( ((UINT)(st->wYear - 1980) << 9) | ((UINT)st->wMonth<< 5) | (UINT)st->wDay); }
/* Convert SYSTEMTIME into DOS date*/
Convert SYSTEMTIME into DOS date
SystemToDosTime
USHORT SystemToDosTime(SYSTEMTIME *st) { return (USHORT)( ((UINT)st->wHour << 11) | ((UINT)st->wMinute << 5) | ((UINT)st->wSecond >> 1)); }
/* Convert SYSTEMTIME into DOS time*/
Convert SYSTEMTIME into DOS time
TimeToSystem
void TimeToSystem(SYSTEMTIME *st, time_64t t) { struct tm tmp; // Validate arguments if (st == NULL) { return; } TimeToTm(&tmp, t); TmToSystem(st, &tmp); }
/* Convert the time_t to SYSTEMTIME*/
Convert the time_t to SYSTEMTIME
SystemToTime
time_64t SystemToTime(SYSTEMTIME *st) { struct tm t; // Validate arguments if (st == NULL) { return 0; } SystemToTm(&t, st); return TmToTime(&t); }
/* Convert the SYSTEMTIME to time_t*/
Convert the SYSTEMTIME to time_t
TmToTime
time_64t TmToTime(struct tm *t) { time_64t tmp; // Validate arguments if (t == NULL) { return 0; } tmp = c_mkgmtime(t); if (tmp == (time_64t)-1) { return 0; } return tmp; }
/* Convert the tm to time_t*/
Convert the tm to time_t
TimeToTm
void TimeToTm(struct tm *t, time_64t time) { // Validate arguments if (t == NULL) { return; } Zero(t, sizeof(struct tm)); c_gmtime_r(&time, t); }
/* Convert time_t to tm*/
Convert time_t to tm
NormalizeTm
void NormalizeTm(struct tm *t) { time_64t tmp; // Validate arguments if (t == NULL) { return; } tmp = c_mkgmtime(t); if (tmp == (time_64t)-1) { return; } c_gmtime_r(&tmp, t); }
/* Normalize the tm*/
Normalize the tm
NormalizeSystem
void NormalizeSystem(SYSTEMTIME *st) { UINT64 sec64; // Validate arguments if (st == NULL) { return; } sec64 = SystemToUINT64(st); UINT64ToSystem(st, sec64); }
/* Normalize the SYSTEMTIME*/
Normalize the SYSTEMTIME
LocalToSystem64
UINT64 LocalToSystem64(UINT64 t) { SYSTEMTIME st; UINT64ToSystem(&st, t); LocalToSystem(&st, &st); return SystemToUINT64(&st); }
/* Convert a 64-bit local time to a system time*/
Convert a 64-bit local time to a system time
SystemToLocal64
UINT64 SystemToLocal64(UINT64 t) { SYSTEMTIME st; UINT64ToSystem(&st, t); SystemToLocal(&st, &st); return SystemToUINT64(&st); }
/* Convert the 64bit system time to local time*/
Convert the 64bit system time to local time
LocalToSystem
void LocalToSystem(SYSTEMTIME *system, SYSTEMTIME *local) { UINT64 sec64; // Validate arguments if (local == NULL || system == NULL) { return; } sec64 = (UINT64)((INT64)SystemToUINT64(local) - GetTimeDiffEx(local, true)); UINT64ToSystem(system, sec64); }
/* Convert local time to system time*/
Convert local time to system time
SystemToLocal
void SystemToLocal(SYSTEMTIME *local, SYSTEMTIME *system) { UINT64 sec64; // Validate arguments if (local == NULL || system == NULL) { return; } sec64 = (UINT64)((INT64)SystemToUINT64(system) + GetTimeDiffEx(system, false)); UINT64ToSystem(local, sec64); }
/* Convert the system time to local time*/
Convert the system time to local time
UINT64ToSystem
void UINT64ToSystem(SYSTEMTIME *st, UINT64 sec64) { UINT64 tmp64; UINT sec, millisec; time_64t time; // Validate arguments if (st == NULL) { return; } sec64 = SafeTime64(sec64 + 32400000ULL); tmp64 = sec64 / (UINT64)1000; millisec = (UINT)(sec64 - tmp64 * (UINT64)1000); sec = (UINT)tmp64; time = (time_64t)sec; TimeToSystem(st, time); st->wMilliseconds = (WORD)millisec; }
/* Convert UINT64 to the SYSTEMTIME*/
Convert UINT64 to the SYSTEMTIME
SystemToUINT64
UINT64 SystemToUINT64(SYSTEMTIME *st) { UINT64 sec64; time_64t time; // Validate arguments if (st == NULL) { return 0; } time = SystemToTime(st); //For times before 1970-01-01, clamp to the minimum //because we have to return an unsigned integer. //This is less wrong than casting it to UINT64 //and returning a time far in the future. //For some reason we subtract 9 hours below, so //account for that here. if( time < 32400000LL ) return 0; sec64 = (UINT64)time * (UINT64)1000; sec64 += st->wMilliseconds; return sec64 - 32400000ULL; }
/* Convert the SYSTEMTIME to UINT64*/
Convert the SYSTEMTIME to UINT64
LocalTime64
UINT64 LocalTime64() { SYSTEMTIME s; LocalTime(&s); return SystemToUINT64(&s); }
/* Get local time in UINT64*/
Get local time in UINT64
SystemTime64
UINT64 SystemTime64() { SYSTEMTIME s; SystemTime(&s); return SystemToUINT64(&s); }
/* Get the system time in UINT64*/
Get the system time in UINT64
LocalTime
void LocalTime(SYSTEMTIME *st) { SYSTEMTIME tmp; // Validate arguments if (st == NULL) { return; } SystemTime(&tmp); SystemToLocal(st, &tmp); }
/* Get local time*/
Get local time
SystemTime
void SystemTime(SYSTEMTIME *st) { // Validate arguments if (st == NULL) { return; } OSGetSystemTime(st); // KS KS_INC(KS_GETTIME_COUNT); }
/* Get the System Time*/
Get the System Time
Tick
UINT Tick() { // KS KS_INC(KS_GETTICK_COUNT); return OSGetTick(); }
/* Get the system timer*/
Get the system timer
AbortExit
void AbortExit() { #ifdef OS_WIN32 _exit(1); #else // OS_WIN32 #ifdef RLIMIT_CORE UnixSetResourceLimit(RLIMIT_CORE, 0); #endif // RLIMIT_CORE abort(); #endif // OS_WIN32 }
/* Stop system (abnormal termination)*/
Stop system (abnormal termination)