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.

155 lines
4.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
7 years ago
​
​
6 years ago
​
​
7 years ago
​
7 years ago
​
3 years ago
​
​
5 years ago
​
​
​
​
5 years ago
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
4 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. #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 <unistd.h>
  18. #include <ifaddrs.h>
  19. #include <sys/socket.h>
  20. #include <netinet/in.h>
  21. #include <arpa/inet.h>
  22. #include <sys/statvfs.h>
  23. #include <sys/types.h>
  24. #include <pwd.h>
  25. #include <grp.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 <windows.h>
  36. #include <VersionHelpers.h>
  37. #include <dshow.h>
  38. #endif
  39. #include <sys/stat.h>
  40. #include <sys/types.h>
  41. #include "basicTypes.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, int 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. struct timeval tData;
  82. struct timezone tTZ;
  83. if( ptr == NULL ) {
  84. PF_TIMESTAMP *retVal;
  85. retVal = (PF_TIMESTAMP *) malloc(sizeof(PF_TIMESTAMP));
  86. if( retVal != NULL ) {
  87. if( gettimeofday( &tData, &tTZ ) == -1 ){
  88. free(retVal);
  89. retVal = NULL;
  90. } else {
  91. retVal->seconds = tData.tv_sec;
  92. retVal->milliseconds = ( tData.tv_usec / 1000 );
  93. };
  94. };
  95. return retVal;
  96. } else {
  97. if( gettimeofday( &tData, &tTZ ) == -1 ){
  98. ptr->seconds = 0;
  99. ptr->milliseconds = 0;
  100. } else {
  101. ptr->seconds = tData.tv_sec;
  102. ptr->milliseconds = ( tData.tv_usec / 1000 );
  103. };
  104. return ptr;
  105. };
  106. };
  107. pid_t gettid( void );
  108. #define SLEEP(X) usleep(X*1000)
  109. uint64_t getMilliseconds( void );
  110. bool pingIP4( CSTR ip4 );
  111. #else
  112. #ifndef WIN_XP
  113. #include <VersionHelpers.h>
  114. #endif
  115. #define SLEEP(X) Sleep(X)
  116. unsigned __int64 getMilliseconds( void );
  117. #endif
  118. size_t escape_string( char *to, size_t to_length, const char *from, size_t length );
  119. int getIP4( if_info **arrParam, int max_ifs = 10 );
  120. #ifdef __linux__
  121. long long getTotalSpace( CSTR DirName );
  122. long long getFreeSpace( CSTR DirName );
  123. bool enumerateDevices( enumeratorInfo *mlist, const char *dTemplate = "video" );
  124. #else
  125. __int64 getTotalSpace( CSTR DirName );
  126. __int64 getFreeSpace( CSTR DirName );
  127. bool enumerateDevices(enumeratorInfo *mlist, REFGUID category);
  128. #endif
  129. localIpAddresses *getLocalIP();
  130. #define DELAY_10MS( X ) { for( uint8_t iii = X; iii && ( m_bThreadStatus < TH_ENDED ); iii-- ) SLEEP( 10 ); }
  131. #endif