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.

174 lines
4.3 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. int getLocalDay();
  65. // Local hour of day (0..23) of time t (t == 0: now), -1 on error
  66. int getLocalHour(time_t t = 0);
  67. ssize_t readLine(int fd, char * buffer, size_t n);
  68. ssize_t readLine(FILE * fd, char * buffer, size_t n);
  69. // #define EPOCH_DIFF 11644473600LL
  70. #define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
  71. bool correctSysTime(int diff);
  72. bool correctSoftTime(int diff);
  73. #define CLEAR(x) memset(&(x), 0, sizeof(x))
  74. #ifdef __linux__
  75. unsigned long long getTimeValue(void);
  76. int xioctl(int fh, unsigned long request, void * arg);
  77. #else
  78. unsigned __int64 getTimeValue(void);
  79. #endif
  80. CSTR getTimeStamp(void);
  81. #ifdef __linux__
  82. bool isProcessUniq(CSTR pName);
  83. inline PF_TIMESTAMP * getPFTS(PF_TIMESTAMP * ptr = NULL)
  84. {
  85. struct timeval tData;
  86. struct timezone tTZ;
  87. if (ptr == NULL)
  88. {
  89. PF_TIMESTAMP * retVal;
  90. retVal = (PF_TIMESTAMP *) malloc(sizeof(PF_TIMESTAMP));
  91. if (retVal != NULL)
  92. {
  93. if (gettimeofday(&tData, &tTZ) == -1)
  94. {
  95. free(retVal);
  96. retVal = NULL;
  97. }
  98. else
  99. {
  100. retVal->seconds = tData.tv_sec;
  101. retVal->milliseconds = (tData.tv_usec / 1000);
  102. };
  103. };
  104. return retVal;
  105. }
  106. else
  107. {
  108. if (gettimeofday(&tData, &tTZ) == -1)
  109. {
  110. ptr->seconds = 0;
  111. ptr->milliseconds = 0;
  112. }
  113. else
  114. {
  115. ptr->seconds = tData.tv_sec;
  116. ptr->milliseconds = (tData.tv_usec / 1000);
  117. };
  118. return ptr;
  119. };
  120. }
  121. pid_t gettid(void);
  122. #define SLEEP(X) usleep(X * 1000)
  123. uint64_t getMilliseconds(void);
  124. bool pingIP4(CSTR ip4);
  125. #else
  126. #ifndef WIN_XP
  127. #include <VersionHelpers.h>
  128. #endif
  129. #define SLEEP(X) Sleep(X)
  130. unsigned __int64 getMilliseconds(void);
  131. #endif
  132. size_t escape_string(char * to, size_t to_length, const char * from, size_t length);
  133. int getIP4(if_info ** arrParam, int max_ifs = 10);
  134. #ifdef __linux__
  135. long long getTotalSpace(CSTR DirName);
  136. long long getFreeSpace(CSTR DirName);
  137. bool enumerateDevices(enumeratorInfo * mlist, const char * dTemplate = "video");
  138. #else
  139. __int64 getTotalSpace(CSTR DirName);
  140. __int64 getFreeSpace(CSTR DirName);
  141. bool enumerateDevices(enumeratorInfo * mlist, REFGUID category);
  142. #endif
  143. localIpAddresses * getLocalIP();
  144. #define DELAY_10MS(X) \
  145. { \
  146. for (uint8_t iii = X; iii && (m_bThreadStatus < TH_ENDED); iii--) \
  147. SLEEP(10); \
  148. }
  149. #endif