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.

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