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.

133 lines
3.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
6 years ago
​
​
7 years ago
​
7 years ago
​
5 years ago
5 years ago
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
5 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASIC_FUNCTIONALITY_HEADER__
  2. #define __BASIC_FUNCTIONALITY_HEADER__
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <time.h>
  7. #include <fcntl.h>
  8. #if defined(__APPLE__) || defined(__FreeBSD__)
  9. #include <copyfile.h>
  10. #else
  11. #ifdef __linux__
  12. #include <sys/sendfile.h>
  13. #endif
  14. #endif
  15. #ifdef __linux__
  16. #include <unistd.h>
  17. #include <ifaddrs.h>
  18. #include <sys/socket.h>
  19. #include <netinet/in.h>
  20. #include <arpa/inet.h>
  21. #include <sys/statvfs.h>
  22. #include <sys/types.h>
  23. #include <pwd.h>
  24. #include <grp.h>
  25. int chown( const char *file_path, const char *user_name, const char *group_name);
  26. #include "basicBuildTimeStamp.h"
  27. #else
  28. //#include <winsock2.h>
  29. //#include <ws2tcpip.h>
  30. #ifndef WIN32_LEAN_AND_MEAN
  31. #define WIN32_LEAN_AND_MEAN
  32. #endif
  33. #include <atlbase.h>
  34. #include <windows.h>
  35. #include <VersionHelpers.h>
  36. #include <dshow.h>
  37. #endif
  38. #include "basicTypes.h"
  39. int fileCopy( const char* source, const char* destination );
  40. bool fileExist( const char *strFilename );
  41. bool dirEmpty( const char *dirname );
  42. CSTR trim( CSTR string );
  43. uint8_t checksum8( uint8_t *Buffer, size_t BufferSize );
  44. uint16_t checksum16( uint8_t *Buffer, size_t BufferSize );
  45. uint8_t checksumLGS( uint8_t *Buffer, size_t BufferSize );
  46. uint16_t checksumPing( void *b, size_t len );
  47. CArray * explode( char Delim, CSTR S_Str );
  48. CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End );
  49. CSTR getTStr( CSTR Fmt = NULL );
  50. CSTR getUniqID_SHA256(void);
  51. int rand( int a, int b );
  52. CSTR getUniqID_MD5(void);
  53. CSTR getUniqID_UUID( uint32_t SEED = 0);
  54. CSTR strReplace( CSTR orig, CSTR rep, CSTR with );
  55. int checkCmdExists( CSTR cmd );
  56. //#define EPOCH_DIFF 11644473600LL
  57. #define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
  58. bool correctSysTime( int diff );
  59. bool correctSoftTime( int diff );
  60. #ifdef __linux__
  61. unsigned long long getTimeValue( void );
  62. #else
  63. unsigned __int64 getTimeValue( void );
  64. #endif
  65. CSTR getTimeStamp(void);
  66. #ifdef __linux__
  67. inline PF_TIMESTAMP * getPFTS( PF_TIMESTAMP * ptr = NULL ){
  68. struct timeval tData;
  69. struct timezone tTZ;
  70. if( ptr == NULL ) {
  71. PF_TIMESTAMP *retVal;
  72. retVal = (PF_TIMESTAMP *) malloc(sizeof(PF_TIMESTAMP));
  73. if( retVal != NULL ) {
  74. if( gettimeofday( &tData, &tTZ ) == -1 ){
  75. free(retVal);
  76. retVal = NULL;
  77. } else {
  78. retVal->seconds = tData.tv_sec;
  79. retVal->milliseconds = ( tData.tv_usec / 1000 );
  80. };
  81. };
  82. return retVal;
  83. } else {
  84. if( gettimeofday( &tData, &tTZ ) == -1 ){
  85. ptr->seconds = 0;
  86. ptr->milliseconds = 0;
  87. } else {
  88. ptr->seconds = tData.tv_sec;
  89. ptr->milliseconds = ( tData.tv_usec / 1000 );
  90. };
  91. return ptr;
  92. };
  93. };
  94. pid_t gettid( void );
  95. #define SLEEP(X) usleep(X*1000)
  96. uint64_t getMilliseconds( void );
  97. #else
  98. #ifndef WIN_XP
  99. #include <VersionHelpers.h>
  100. #endif
  101. #define SLEEP(X) Sleep(X)
  102. unsigned __int64 getMilliseconds( void );
  103. #endif
  104. int getIP4( if_info **arrParam, int max_ifs = 10 );
  105. #ifdef __linux__
  106. long long getTotalSpace( CSTR DirName );
  107. long long getFreeSpace( CSTR DirName );
  108. bool enumerateDevices( enumeratorInfo *mlist, const char *dTemplate = "video" );
  109. #else
  110. __int64 getTotalSpace( CSTR DirName );
  111. __int64 getFreeSpace( CSTR DirName );
  112. bool enumerateDevices(enumeratorInfo *mlist, REFGUID category);
  113. #endif
  114. localIpAddresses *getLocalIP();
  115. #endif