1 #if !defined(_UTILS_H_) 10 #include <sys/types.h> 24 #include "direntwin.h" 28 #include <semaphore.h> 31 #include <sys/utsname.h> 35 #include <sys/prctl.h> 39 #include <sys/syscall.h> 40 #include <sys/sysinfo.h> 41 #include <sys/socket.h> 44 #include <sys/ioctl.h> 46 #include <netinet/tcp.h> 49 #include <sys/resource.h> 53 #define WINSHMEMSPACE "Local" 56 #define MAXKEYNAMELEN 256 57 #define MAXVALUENAMELEN 1024 58 #define MAXCONTENTLEN 4196 59 #define MAXCOMMANDLINELEN 1024 60 #define MAXFILENAMELEN 256 61 #define MAXSHMEMNAMELEN 1024 62 #define MAXSCRIPTLEN 10*1024 65 #define THREAD_TERMINATED 1 67 #define THREAD_RUNNING 3 68 #define THREAD_PAUSED 4 69 #define THREAD_INTERRUPTED 5 71 #define THREAD_STATS_OFF 0 72 #define THREAD_STATS_AUTO 1 73 #define THREAD_STATS_ADHOC 2 79 #define ThreadHandle HANDLE 82 #define THREAD_RET DWORD 83 typedef LPTHREAD_START_ROUTINE THREAD_FUNCTION;
84 #define THREAD_FUNCTION_CALL WINAPI 85 #define THREAD_ARG LPVOID 86 #define thread_ret_val(ret) return ret; 87 #define DllExport __declspec(dllexport) 88 #define MUTEX_INVALID NULL 89 #define SOCKETWOULDBLOCK WSAEWOULDBLOCK 90 #define SOCKETTRYAGAIN WSAEWOULDBLOCK 96 #define ThreadHandle pthread_t 98 #define THREAD_RET void * 99 typedef THREAD_RET (*THREAD_FUNCTION)(
void *);
100 #define THREAD_FUNCTION_CALL 101 #define THREAD_ARG void* 102 #define thread_ret_val(ret) pthread_exit((THREAD_RET)(intptr_t)ret); 103 #define stricmp strcasecmp 104 #define MUTEX_INVALID 0 106 typedef struct sockaddr SOCKADDR;
107 #define SOCKET_ERROR -1 108 #define INVALID_SOCKET -1 109 #define closesocket(X) close(X) 110 #define SOCKETWOULDBLOCK EINPROGRESS 111 #define SOCKETTRYAGAIN EAGAIN 113 #define MUTEXMEMSIZE 64 114 #define EVENTMEMSIZE 256 115 #define _strcmpi strcasecmp 116 #define _strnicmp strnicmp 124 #define OSCPU_UNKNOWN 0 126 #define OSCPU_AMD64 2 129 #define ERROR64 0xFFFFFFFFFFFFFFFFL 130 #define ERROR32 0xFFFFFFFF 131 #define ERROR16 0xFFFF 148 bool ClearUtilsMaps();
154 #define LOG_NOTOPIC 0 156 #define LOG_NETWORK 2 158 #define LOG_PROCESS 4 164 #define LOG_TOPIC10 10 165 #define LOG_TOPIC11 11 166 #define LOG_MAXCOUNT 12 171 std::string GetDataTypeName(uint32 datatype);
172 uint32 GetDataTypeID(
const char* typeName);
183 const char* getText(uint32& len);
184 bool setText(
char* text, uint32 len);
185 std::string toJSON();
194 virtual bool logEntry(
LogEntry* entry) = 0;
205 static bool SetLogFileOutput(
const char* logfile,
bool printOut =
true);
206 static bool SetLogLevelDebug(uint8 level);
207 static bool SetLogLevelDebug(uint8 subject, uint8 level);
208 static bool SetLogLevelVerbose(uint8 level);
209 static bool SetLogLevelVerbose(uint8 subject, uint8 level);
211 static bool LogSystemPrint(uint32 source, uint8 subject, uint8 level,
const char *formatstring, ... );
212 static bool LogSystemDebug(uint32 source, uint8 subject, uint8 level,
const char *formatstring, ... );
214 uint8 logLevelVerbose[LOG_MAXCOUNT];
215 uint8 logLevelDebug[LOG_MAXCOUNT];
221 #define LogPrint LogSystem::LogSystemPrint 222 #define LogDebug LogSystem::LogSystemDebug 242 #define SharedMemoryFileHandleMapType std::map<char*, HANDLE> 244 #define SharedMemoryFileHandleMapType std::map<void*, std::string> 246 static SharedMemoryFileHandleMapType* SharedMemoryFileHandleMap = NULL;
248 static uint16 SharedSystemInstance = 0;
250 bool SetSharedSystemInstance(uint32 inst);
251 uint32 GetSharedSystemInstance();
253 typedef bool (* DrumBeatFunc)(uint32 id, uint32 count);
269 static std::map<uint32, DrumBeatInfo>* DrumBeatMap = NULL;
271 bool CreateDrumBeat(uint32
id, uint32 interval, DrumBeatFunc func,
bool autostart =
false);
272 bool StartDrumBeat(uint32
id);
273 bool StopDrumBeat(uint32
id);
274 bool EndDrumBeat(uint32
id);
279 Mutex(
const char* name,
bool force =
false);
282 bool enter(uint32 timeout,
const char* errorMsg = NULL);
295 pthread_mutex_t* mutex;
302 Semaphore(
const char* name, uint32 maxCount = 100);
305 bool wait(uint32 timeout);
320 Event(
const char* name);
323 bool waitNext(uint32 timeout);
331 pthread_cond_t* event;
332 pthread_mutex_t* mutex;
336 bool EnterMutex(
const char* name, uint32 ms,
bool autocreate =
true);
337 bool LeaveMutex(
const char* name);
338 bool DestroyMutex(
const char* name);
340 Semaphore* GetSemaphore(
const char* name,
bool autocreate =
true);
341 bool WaitForSemaphore(
const char* name, uint32 ms,
bool autocreate =
true);
342 bool SignalSemaphore(
const char* name);
343 bool DestroySemaphore(
const char* name);
345 bool WaitNextEvent(
const char* name, uint32 ms,
bool autocreate =
true);
346 bool SignalEvent(
const char* name);
347 bool DestroyEvent(
const char* name);
349 static Mutex* SharedMemoryMutexMapMutex = NULL;
350 static std::map<std::string, Mutex*>* SharedMemoryMutexMap = NULL;
351 typedef std::pair<std::string, Mutex*> SharedMemoryMutexMapPair;
352 static Mutex* SharedMemorySemaphoreMapMutex = NULL;
353 static std::map<std::string, Semaphore*>* SharedMemorySemaphoreMap = NULL;
354 typedef std::pair<std::string, Semaphore*> SharedMemorySemaphoreMapPair;
355 static Mutex* SharedMemoryEventMapMutex = NULL;
356 static std::map<std::string, Event*>* SharedMemoryEventMap = NULL;
357 typedef std::pair<std::string, Event*> SharedMemoryEventMapPair;
361 PROCESS_INFORMATION procInfo;
364 static std::map<uint32, ProcessData*>* ProcessInformationMap = NULL;
365 typedef std::pair <uint32, ProcessData*> Proc_Pair;
366 static HANDLE ghJob = NULL;
389 static std::map<uint32, Timer*>* timers;
394 bool addTimer(uint32
id, uint32 interval, uint64 start = 0, uint64 end = 0);
395 bool triggerTimer(uint32
id);
396 bool waitForTimer(uint32 timeout, uint32&
id, uint64& time);
397 bool removeTimer(uint32
id);
403 std::queue<TimerTrigger*> triggers;
404 std::map<uint32, TimerSchedule*> schedules;
405 std::list<TimerSchedule*> oldSchedules;
409 void CALLBACK TimerCallback(PVOID arg, BOOLEAN TimerOrWaitFired);
411 static void TimerCallback(
int sig, siginfo_t *siginfo,
void *context);
413 bool UnitTest_Timer();
414 bool UnitTest_Utils();
420 template <
typename T>
427 if (!mutex.enter(200, __FUNCTION__))
429 internalQueue.push(entry);
436 if (!mutex.enter(200, __FUNCTION__))
438 size = (uint32)internalQueue.size();
442 bool peekFirst(T& first) {
443 if (!mutex.enter(200, __FUNCTION__))
445 if (!internalQueue.size()) {
449 first = internalQueue.front();
453 bool takeFirst(T& first) {
454 if (!mutex.enter(200, __FUNCTION__))
456 if (!internalQueue.size()) {
460 first = internalQueue.front();
465 bool waitForAndPeekFirst(T& first, uint32 timeoutMS) {
466 if (!mutex.enter(200, __FUNCTION__))
468 if (internalQueue.size()) {
469 first = internalQueue.front();
474 if (!semaphore.wait(timeoutMS))
476 if (!mutex.enter(200, __FUNCTION__))
478 if (internalQueue.size()) {
479 first = internalQueue.front();
488 bool waitForAndTakeFirst(T& first, uint32 timeoutMS) {
489 if (!mutex.enter(200, __FUNCTION__))
491 if (internalQueue.size()) {
492 first = internalQueue.front();
498 if (!semaphore.wait(timeoutMS))
500 if (!mutex.enter(200, __FUNCTION__))
502 if (internalQueue.size()) {
503 first = internalQueue.front();
513 virtual bool clear() {
514 if (!mutex.enter(200, __FUNCTION__))
517 std::swap(internalQueue, empty);
525 std::queue<T> internalQueue;
528 template <
typename T>
534 T waitForAndTakeFirst(uint32 timeoutMS) {
542 virtual bool clear() {
559 template <
typename T>
565 template <
typename T>
571 bool add(uint64 time, T entry) {
572 if (!mutex.enter(200, __FUNCTION__))
575 newEntry.time = time;
576 newEntry.entry = entry;
577 typename std::list< TimeQueueEntry<T> >::iterator i = internalList.begin(),
578 e = internalList.end();
580 if (time < (*i).time) {
581 internalList.insert(i, newEntry);
587 internalList.push_back(newEntry);
593 if (!mutex.enter(200, __FUNCTION__))
595 size = (uint32)internalList.size();
599 bool getNextEntryDue(T& entry) {
600 if (!mutex.enter(200, __FUNCTION__))
602 if (!internalList.size()) {
606 uint64 now = GetTimeNow();
608 if (first.time < now) {
609 internalList.pop_front();
617 virtual bool clear() {
618 if (!mutex.enter(200, __FUNCTION__))
620 std::list< TimeQueueEntry<T> > empty;
621 std::swap(internalList, empty);
628 std::list< TimeQueueEntry<T> > internalList;
631 template <
typename T>
637 T getNextEntryDue() {
645 virtual bool clear() {
666 char* CreateSharedMemorySegment(
const char* name, uint64 size,
bool force =
false);
668 char* OpenSharedMemorySegment(
const char* name, uint64 size);
670 bool CloseSharedMemorySegment(
char* data, uint64 size);
679 uint32 Calc32BitFieldSize(uint32 bitsize);
681 bool Reset32BitField(
char* bitfield, uint32 bytesize);
683 bool GetFirstFreeBitLoc(
const char* bitfield, uint32 bytesize, uint32& loc);
685 bool GetFirstFreeBitLocN(
const char* bitfield, uint32 bytesize, uint32 num, uint32& loc);
687 bool SetBit(uint32 loc, bit value,
char* bitfield, uint32 bytesize);
689 bool SetBitN(uint32 loc, uint32 num, bit value,
char* bitfield, uint32 bytesize);
691 bool GetBit(uint32 loc,
const char* bitfield, uint32 bytesize, bit& val);
693 bool GetLastOccupiedBitLoc(
const char* bitfield, uint32 bytesize, uint32& loc);
698 std::string GetBitFieldAsString(
const char* bitfield, uint32 bytesize, uint32 size);
700 std::string PrintBitFieldString(
const char* bitfield, uint32 bytesize, uint32 size,
const char* title);
707 std::string PrintProgramTrace(uint32 startLine = 0, uint32 endLine = 0);
708 std::list<std::string> GetProgramTrace();
710 int32 AtomicIncrement32(int32
volatile &v);
711 int64 AtomicIncrement64(int64
volatile &v);
712 int32 AtomicDecrement32(int32
volatile &v);
713 int64 AtomicDecrement64(int64
volatile &v);
715 bool Sleep(uint32 ms);
717 bool CreateThread(THREAD_FUNCTION func,
void* args, ThreadHandle& thread, uint32 &osID);
719 bool WaitForThreadToFinish(ThreadHandle hThread, uint32 timeoutMS = 0);
721 bool CheckForThreadFinished(ThreadHandle hThread);
723 bool TerminateThread(ThreadHandle hThread);
725 bool PauseThread(ThreadHandle hThread);
727 bool ContinueThread(ThreadHandle hThread);
729 bool GetCurrentThreadUniqueID(uint32 &tid);
731 bool GetCurrentThreadOSID(uint32 &tid);
733 bool GetCurrentThread(ThreadHandle& thread);
735 bool IsThreadRunning(ThreadHandle hThread);
737 uint32 GetThreadStatColAbility();
740 #define FileTimeToUint64(ft) (((uint64)(ft.dwHighDateTime))<<32)|((uint64)ft.dwLowDateTime) 744 bool GetCPUTicks(ThreadHandle hThread, uint64& ticks);
746 bool GetCPUTicks(uint64& ticks);
748 bool GetProcessCPUTicks(uint64& ticks);
750 bool GetProcessCPUTicks(uint32 osProcID, uint64& ticks);
752 bool GetProcAndOSCPUUsage(
double& procPercentUse,
double& osPercentUse, uint64 &prevOSTicks, uint64 &prevOSIdleTicks, uint64 &prevProcTicks);
754 bool GetProcAndOSCPUUsage(uint32 osProcID,
double& procPercentUse,
double& osPercentUse, uint64 &prevOSTicks, uint64 &prevOSIdleTicks, uint64 &prevProcTicks);
756 bool GetOSCPUUsage(
double& percentUse);
758 bool GetThreadPriority(ThreadHandle hThread, uint16 priority);
760 bool SetThreadPriority(ThreadHandle hThread, uint16 priority);
762 int ToOSPriority(
int pri);
764 int FromOSPriority(
int pri);
766 bool SignalThread(ThreadHandle hThread, int32 signal);
772 bool GetDesktopSize(uint32& width, uint32& height);
774 bool RenameConsoleWindow(
const char* name,
bool prepend =
false);
776 bool MoveConsoleWindow(int32 x = -1, int32 y = -1, int32 w = -1, int32 h = -1);
783 #define PROC_TERMINATED 1 784 #define PROC_NOTSTARTED 2 785 #define PROC_RUNNING 3 786 #define PROC_TIMEOUT 4 789 #define PARENT_WRITE_PIPE 0 790 #define PARENT_READ_PIPE 1 795 #define PARENT_READ_FD ( (*pipes)[PARENT_READ_PIPE][READ_FD] ) 796 #define PARENT_WRITE_FD ( (*pipes)[PARENT_WRITE_PIPE][WRITE_FD] ) 797 #define CHILD_READ_FD ( (*pipes)[PARENT_WRITE_PIPE][READ_FD] ) 798 #define CHILD_WRITE_FD ( (*pipes)[PARENT_READ_PIPE][WRITE_FD] ) 800 #define PROCBUFSIZE 4096 802 int RunOSCommand(
const char* cmdline,
const char* initdir, uint32 timeout, std::string& stdoutString, std::string& stderrString);
803 uint32 NewProcess(
const char* cmdline,
const char* initdir = NULL,
const char* title = NULL,
804 int16 x = -1, int16 y = -1, int16 w = -1, int16 h = -1);
805 uint8 GetProcessStatus(uint32 proc,
int &returncode);
806 bool EndProcess(uint32 proc);
807 uint8 WaitForProcess(uint32 proc, uint32 timeout,
int &returncode);
808 uint32 GetLocalProcessID();
815 #define DLLHandle HINSTANCE 817 #define DLLHandle void* 820 typedef int (* LibraryFunction)();
827 std::string CommandLineString;
828 std::string CommandLineExec;
829 std::string CommandLineExecOnly;
830 std::string CommandLineExecPath;
831 std::vector<std::string> CommandLineItems;
832 std::map<std::string, std::string> CommandLineArgs;
837 bool SetCommandLine(
int argc,
char* argv[]);
838 std::string GetCommandLine();
839 std::string GetCommandLinePath();
840 std::string GetCommandLineExecutable();
841 std::string GetCommandLineExecutableOnly();
842 uint32 GetCommandLineArgCount();
843 std::string GetCommandLineArg(uint16 n);
844 std::string GetCommandLineArg(
const char* key);
848 static std::string patchLibraryFilename(
const char* filename,
const char* path = NULL);
852 bool load(
const char* filename);
853 LibraryFunction getFunction(
const char* funcName);
858 Library* OpenLibrary(
const char* libName);
864 const char* GetComputerName();
866 uint64 GetProcessMemoryUsage();
869 uint16 GetCPUCount();
871 uint16 GetCPUArchitecture();
873 uint64 GetCPUSpeed();
875 uint64 GetSystemMemorySize();
877 bool GetSystemMemoryUsage(uint64 &totalRAM, uint64 &freeRAM);
879 const char* GetSystemArchitecture();
881 const char* GetSystemOSName();
883 bool GetSystemOSVersion(uint16& major, uint16& minor, uint16& build,
char* text, uint16 textSize);
897 bool CheckNetworkInit();
898 #define CHECKNETWORKINIT utils::CheckNetworkInit(); 900 #define CHECKNETWORKINIT 901 #define WSAEWOULDBLOCK EAGAIN 904 bool GetSocketError(
int wsaError,
char* errorString, uint16 errorStringMaxSize,
bool* isRecoverable);
906 int GetLastOSErrorNumber();
907 std::string GetLastOSErrorMessage();
909 bool WaitForSocketReadability(SOCKET s, int32 timeout);
910 bool WaitForSocketWriteability(SOCKET s, int32 timeout);
912 bool SetSocketNonBlockingMode(SOCKET s);
913 bool SetSocketBlockingMode(SOCKET s);
918 char name[MAXKEYNAMELEN+1];
919 char friendlyName[MAXKEYNAMELEN+1];
922 bool LookupIPAddress(
const char* name, uint32& address);
923 bool LookupHostname(uint32 address,
char* name, uint32 maxSize);
924 std::string GetLocalHostnameString();
925 bool GetLocalHostname(
char* name, uint32 maxSize);
926 bool IsLocalIPAddress(
const char* addr);
927 bool IsLocalIPAddress(uint32& address);
928 bool GetLocalIPAddress(uint32& address);
929 uint32* GetLocalIPAddresses(uint32& count);
930 bool GetLocalMACAddress(uint64& address);
931 uint64* GetLocalMACAddresses(uint32& count);
933 bool GetNextAvailableLocalPort(uint16 lastPort, uint16 &nextPort);
935 #define LOCALHOSTIP 16777343 // 127.0.0.1 as 32-bit dec 936 #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) 937 #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) 939 #define GETIPPORT(a) *(uint16*)((char*)&a + sizeof(uint32)) 940 #define GETIPADDRESS(a) *(uint32*)&a 941 #define GETIPADDRESSPORT(a,p) (((uint32)a)) | (((uint64)p)<<32) 942 #define GETIPADDRESSQUAD(a) ((uint8*)&a)[0], ((uint8*)&a)[1], ((uint8*)&a)[2], ((uint8*)&a)[3] 943 #define GETIPADDRESSQUADPORT(a) ((uint8*)&a)[0], ((uint8*)&a)[1], ((uint8*)&a)[2], ((uint8*)&a)[3], ((uint16*)&a)[2] 946 std::string GetRegistryKeyInfo(
const char* key, HKEY &hKeyRoot);
947 std::string GetRegistryParentKeyInfo(
const char* key, HKEY &hKeyRoot);
949 uint32 ReadRegistryDWORD(
const char* key,
const char* entry);
950 uint64 ReadRegistryQWORD(
const char* key,
const char* entry);
951 std::string ReadRegistryString(
const char* key,
const char* entry);
952 bool WriteRegistryDWORD(
const char* key,
const char* entry, uint32 value);
953 bool WriteRegistryQWORD(
const char* key,
const char* entry, uint64 value);
954 bool WriteRegistryString(
const char* key,
const char* entry,
const char* value);
955 bool DeleteRegistryEntry(
const char* key,
const char* entry);
956 bool DeleteRegistryKey(
const char* key);
957 bool DeleteRegistryTree(
const char* root,
const char* key);
959 bool CopyRegistryTree(
const char* entry,
const char* newName);
966 void PrintBinary(
void* p, uint32 size,
bool asInt,
const char* title);
967 const char* stristr(
const char *str,
const char *substr, uint32 len = 0);
968 bool GetNextLineEnd(
const char *str, uint32 size, uint32& len, uint32& crSize);
969 uint32 TextReplaceCharsInPlace(
char* str, uint32 size,
char find,
char replace);
970 bool TextEndsWith(
const char* str,
const char* end,
bool caseSensitive =
true);
971 bool TextStartsWith(
const char* str,
const char* start,
bool caseSensitive =
true);
972 uint32 strcpyavail(
char* dst,
const char* src, uint32 maxlen,
bool copyAvailable);
973 const char* laststrstr(
const char* str1,
const char* str2);
974 const char* laststristr(
const char* str1,
const char* str2);
976 uint32 StringSingleReplace(std::string& text, std::string key, std::string value,
bool onlyFirst);
977 uint32 StringMultiReplace(std::string& text, std::map<std::string, std::string>& map,
bool onlyFirst);
978 uint32 StringScriptReplace(std::string& text, std::string name, std::list< std::map<std::string, std::string> >& list);
980 std::string TextCapitalise(
const char* text);
981 std::string TextUppercase(
const char* text);
982 std::string TextLowercase(
const char* text);
983 std::string TextIndent(
const char* text,
const char* indent);
984 std::string TextUnindent(
const char* text);
985 std::string TextTrimQuotes(
const char* text);
986 std::string TextTrim(
const char* text);
987 std::multimap<std::string, std::string> TextMultiMapSplit(
const char* text,
const char* outersplit,
const char* innersplit);
988 std::map<std::string, std::string> TextMapSplit(
const char* text,
const char* outersplit,
const char* innersplit);
989 std::string TextJoin(std::vector<std::string> &list,
const char* split, uint32 start = 0, uint32 count = 0);
990 std::string TextJoin(std::list<std::string> &list,
const char* split, uint32 start = 0, uint32 count = 0);
991 std::string TextJoin(std::map<std::string, std::string> &map,
const char* innersplit,
const char* outersplit,
bool keyquotes,
bool valquotes);
992 std::string TextJoinJSON(std::map<std::string, std::string> &map);
993 std::string TextJoinXML(std::map<std::string, std::string> &map,
const char* innernodeName,
const char* outernodeName);
994 std::vector<std::string> TextListSplit(
const char* text,
const char* split,
bool keepEmpty =
true,
bool autoTrim =
false);
995 std::vector<std::string> TextListSplitLines(
const char* text,
bool keepEmpty =
true,
bool autoTrim =
false);
996 std::vector<std::string> TextListBreakLines(
const char* text, uint32 maxLineLength = 80);
997 std::string TextListBreakLines(
const char* text, uint32 maxLineLength,
const char* breakstr);
998 std::string TextVectorConcat(std::vector<std::string>,
const char* sep,
bool allowEmpty =
true);
999 std::vector<std::string> TextCommandlineSplit(
const char* cmdline);
1000 char** SplitCommandline(
const char* cmdline,
int& argc);
1001 wchar_t** SplitCommandlineW(
const char* cmdline,
int& argc);
1002 bool DeleteCommandline(
char** argv,
int argc);
1004 std::string StringFormat(
const char *format, ...);
1005 char* StringFormat(uint32& size,
const char *format, ...);
1006 bool StringFormatInto(
char* dst, uint32 maxsize,
const char *format, ...);
1007 char* StringFormatVA(uint32& size,
const char *format, va_list args);
1009 unsigned char Hex2Char(
const char* str);
1010 unsigned char Dec2Char(
const char* str);
1011 int CRC32(
const char *addr, uint32 length, int32 crc = 0);
1013 int8 CompareFloats(float64 a, float64 b);
1023 uint64 lastAccessTime;
1024 uint64 lastModifyTime;
1025 uint64 creationTime;
1028 #define NOSUCHFILE 0 1029 #define STANDARDFILE 1 1030 #define STANDARDDIR 2 1032 std::string ReadAFileString(std::string filename);
1033 char* ReadAFile(
const char* filename, uint32& length,
bool binary =
false);
1034 char* ReadAFile(
const char* dir,
const char* filename, uint32& length,
bool binary =
false);
1035 bool WriteAFile(
const char* filename,
const char* data, uint32 length,
bool binary =
false);
1036 bool WriteAFile(
const char* dir,
const char* filename,
const char* data, uint32 length,
bool binary =
false);
1037 bool AppendToAFile(
const char* filename,
const char* data, uint32 length,
bool binary =
false);
1038 bool AppendToAFile(
const char* dir,
const char* filename,
const char* data, uint32 length,
bool binary =
false);
1039 char* GetFileList(
const char* dirname,
const char* ext, uint32& count,
bool fullpath, uint32 maxNameLen = 256);
1041 std::string GetFilePath(
const char* filename);
1042 const char* GetFileBasename(
const char* filename);
1043 bool DeleteAFile(
const char* filename,
bool force);
1044 bool DeleteAFile(
const char* dir,
const char* filename,
bool force);
1045 bool DeleteADir(
const char* dirname,
bool force);
1046 bool CreateADir(
const char* dirname);
1047 bool DoesADirExist(
const char* dirname);
1048 bool DoesAFileExist(
const char* filename);
1049 bool DeleteFilesInADir(
const char* dirname,
bool force);
1050 bool ChangeAFileAttr(
const char* filename,
bool read,
bool write);
1051 bool MoveAFile(
const char* oldfilename,
const char* newfilename,
bool force =
false);
1052 bool MoveAFile(
const char* olddir,
const char* oldfilename,
const char* newdir,
const char* newfilename,
bool force =
false);
1053 bool CopyAFile(
const char* oldfilename,
const char* newfilename,
bool force =
false);
1054 bool CopyAFile(
const char* olddir,
const char* oldfilename,
const char* newdir,
const char* newfilename,
bool force =
false);
1056 char* Int2Ascii(int64 value,
char* result, uint16 size, uint8 base);
1057 char* Uint2Ascii(uint64 value,
char* result, uint16 size, uint8 base);
1058 unsigned char* Ascii2UTF16LE(
const char* ascii, uint32 len, uint32& size);
1060 bool IsTextNumeric(
const char* ascii, uint32 start = 0, uint32 end = 0);
1061 int64 Ascii2Int64(
const char* ascii, uint32 start = 0, uint32 end = 0);
1062 uint64 Ascii2Uint64(
const char* ascii, uint32 start = 0, uint32 end = 0);
1063 uint64 AsciiHex2Uint64(
const char* ascii, uint32 start = 0, uint32 end = 0);
1064 int32 Ascii2Int32(
const char* ascii, uint32 start = 0, uint32 end = 0);
1065 uint32 Ascii2Uint32(
const char* ascii, uint32 start = 0, uint32 end = 0);
1066 uint32 AsciiHex2Uint32(
const char* ascii, uint32 start = 0, uint32 end = 0);
1067 float64 Ascii2Float64(
const char* ascii, uint32 start = 0, uint32 end = 0);
1069 char* TextSubstringCopy(
const char* ascii, uint32 start, uint32 end);
1071 std::string DecodeJSON(std::string str);
1072 std::string EncodeJSON(std::string str);
1074 bool SeedRandomValues(uint32 seedvalue = 0);
1075 double RandomValue();
1076 double RandomValue(
double to);
1077 double RandomValue(
double from,
double to);
1078 double RandomValue(
double from,
double to,
double interval);
1079 int64 RandomInt(int64 from = 0, int64 to = 100);
1082 std::string BytifySize(
double val);
1084 std::string BytifySizes(
double val1,
double val2);
1086 std::string BytifyRate(
double val);
1088 std::string BytifyRates(
double val1,
double val2);
uint64 GetPeakProcessMemoryUsage()
Definition: Utils.cpp:3927
compute CRC32 hash, based on Intel's Slicing-by-8 algorithm
Definition: crc32.h:41