You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASIC_FUNCTIONALITY_HEADER__
  2. #define __BASIC_FUNCTIONALITY_HEADER__
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <sys/types.h>
  7. #include <time.h>
  8. #define USE_SYSTEM_CALL_TO_PING
  9. #if defined(__APPLE__) || defined(__FreeBSD__)
  10. #include <copyfile.h>
  11. #else
  12. #ifdef __linux__
  13. #include <sys/sendfile.h>
  14. #endif
  15. #endif
  16. #ifdef __linux__
  17. #include <arpa/inet.h>
  18. #include <grp.h>
  19. #include <ifaddrs.h>
  20. #include <netinet/in.h>
  21. #include <pwd.h>
  22. #include <sys/socket.h>
  23. #include <sys/statvfs.h>
  24. #include <sys/types.h>
  25. #include <unistd.h>
  26. int ch_chown(const char * file_path, const char * user_name, const char * group_name);
  27. #include "basicBuildTimeStamp.h"
  28. #else
  29. // #include <winsock2.h>
  30. // #include <ws2tcpip.h>
  31. #ifndef WIN32_LEAN_AND_MEAN
  32. #define WIN32_LEAN_AND_MEAN
  33. #endif
  34. #include <atlbase.h>
  35. #include <dshow.h>
  36. #include <VersionHelpers.h>
  37. #include <windows.h>
  38. #endif
  39. #include "basicTypes.h"
  40. #include <sys/stat.h>
  41. #include <sys/types.h>
  42. int fileCopy(const char * source, const char * destination);
  43. bool fileExist(CSTR strFilename);
  44. bool dirEmpty(CSTR dirname);
  45. CSTR trim(CSTR string);
  46. uint8_t checksum8(uint8_t * Buffer, size_t BufferSize);
  47. uint16_t checksum16(uint8_t * Buffer, size_t BufferSize);
  48. uint8_t checksumLGS(uint8_t * Buffer, size_t BufferSize);
  49. uint16_t checksumPing(void * b, size_t len);
  50. CArray * explode(char Delim, CSTR S_Str);
  51. CSTR implode(CArray * Data, CSTR S_Str, U8 Start, U8 End);
  52. CSTR getTStr(CSTR Fmt = NULL);
  53. CSTR getUniqID_SHA256(void);
  54. uid_t getUserUid(CSTR uname);
  55. gid_t getUserGid(CSTR uname);
  56. bool createAccessibleDir(CSTR path, mode_t mode, uid_t uid, gid_t gid);
  57. off_t getFileSize(const char * filename);
  58. int rand(int a, int b);
  59. CSTR getUniqID_MD5(void);
  60. CSTR getUniqID_UUID(uint32_t SEED = 0);
  61. void getUniqID_UUID(CSTR bu, uint32_t SEED = 0);
  62. CSTR strReplace(CSTR orig, CSTR rep, CSTR with);
  63. int checkCmdExists(CSTR cmd);
  64. ssize_t readLine(int fd, char * buffer, size_t n);
  65. ssize_t readLine(FILE * fd, char * buffer, size_t n);
  66. // #define EPOCH_DIFF 11644473600LL
  67. #define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
  68. bool correctSysTime(int diff);
  69. bool correctSoftTime(int diff);
  70. #define CLEAR(x) memset(&(x), 0, sizeof(x))
  71. #ifdef __linux__
  72. unsigned long long getTimeValue(void);
  73. int xioctl(int fh, unsigned long request, void * arg);
  74. #else
  75. unsigned __int64 getTimeValue(void);
  76. #endif
  77. CSTR getTimeStamp(void);
  78. #ifdef __linux__
  79. bool isProcessUniq(CSTR pName);
  80. inline PF_TIMESTAMP * getPFTS(PF_TIMESTAMP * ptr = NULL)
  81. {
  82. struct timeval tData;
  83. struct timezone tTZ;
  84. if (ptr == NULL)
  85. {
  86. PF_TIMESTAMP * retVal;
  87. retVal = (PF_TIMESTAMP *) malloc(sizeof(PF_TIMESTAMP));
  88. if (retVal != NULL)
  89. {
  90. if (gettimeofday(&tData, &tTZ) == -1)
  91. {
  92. free(retVal);
  93. retVal = NULL;
  94. }
  95. else
  96. {
  97. retVal->seconds = tData.tv_sec;
  98. retVal->milliseconds = (tData.tv_usec / 1000);
  99. };
  100. };
  101. return retVal;
  102. }
  103. else
  104. {
  105. if (gettimeofday(&tData, &tTZ) == -1)
  106. {
  107. ptr->seconds = 0;
  108. ptr->milliseconds = 0;
  109. }
  110. else
  111. {
  112. ptr->seconds = tData.tv_sec;
  113. ptr->milliseconds = (tData.tv_usec / 1000);
  114. };
  115. return ptr;
  116. };
  117. }
  118. pid_t gettid(void);
  119. #define SLEEP(X) usleep(X * 1000)
  120. uint64_t getMilliseconds(void);
  121. bool pingIP4(CSTR ip4);
  122. #else
  123. #ifndef WIN_XP
  124. #include <VersionHelpers.h>
  125. #endif
  126. #define SLEEP(X) Sleep(X)
  127. unsigned __int64 getMilliseconds(void);
  128. #endif
  129. size_t escape_string(char * to, size_t to_length, const char * from, size_t length);
  130. int getIP4(if_info ** arrParam, int max_ifs = 10);
  131. #ifdef __linux__
  132. long long getTotalSpace(CSTR DirName);
  133. long long getFreeSpace(CSTR DirName);
  134. bool enumerateDevices(enumeratorInfo * mlist, const char * dTemplate = "video");
  135. #else
  136. __int64 getTotalSpace(CSTR DirName);
  137. __int64 getFreeSpace(CSTR DirName);
  138. bool enumerateDevices(enumeratorInfo * mlist, REFGUID category);
  139. #endif
  140. localIpAddresses * getLocalIP();
  141. #define DELAY_10MS(X) \
  142. { \
  143. for (uint8_t iii = X; iii && (m_bThreadStatus < TH_ENDED); iii--) \
  144. SLEEP(10); \
  145. }
  146. #endif