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.

151 lines
4.7 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
​
​
​
5 years ago
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
5 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. #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 ch_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 <sys/stat.h>
  39. #include <sys/types.h>
  40. #include "basicTypes.h"
  41. int fileCopy( const char* source, const char* destination );
  42. bool fileExist( const char *strFilename );
  43. bool dirEmpty( const char *dirname );
  44. CSTR trim( CSTR string );
  45. uint8_t checksum8( uint8_t *Buffer, size_t BufferSize );
  46. uint16_t checksum16( uint8_t *Buffer, size_t BufferSize );
  47. uint8_t checksumLGS( uint8_t *Buffer, size_t BufferSize );
  48. uint16_t checksumPing( void *b, size_t len );
  49. CArray * explode( char Delim, CSTR S_Str );
  50. CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End );
  51. CSTR getTStr( CSTR Fmt = NULL );
  52. CSTR getUniqID_SHA256(void);
  53. uid_t getUserUid( CSTR uname );
  54. gid_t getUserGid( CSTR uname );
  55. bool createAccessibleDir( CSTR path, mode_t mode, uid_t uid, gid_t gid );
  56. off_t getFileSize(const char *filename) ;
  57. int rand( int a, int b );
  58. CSTR getUniqID_MD5(void);
  59. CSTR getUniqID_UUID( uint32_t SEED = 0);
  60. CSTR strReplace( CSTR orig, CSTR rep, CSTR with );
  61. int checkCmdExists( CSTR cmd );
  62. ssize_t readLine( int fd, char *buffer, size_t n );
  63. ssize_t readLine( FILE *fd, char *buffer, size_t n);
  64. //#define EPOCH_DIFF 11644473600LL
  65. #define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
  66. bool correctSysTime( int diff );
  67. bool correctSoftTime( int diff );
  68. #define CLEAR(x) memset(&(x), 0, sizeof(x))
  69. #ifdef __linux__
  70. unsigned long long getTimeValue( void );
  71. int xioctl(int fh, int request, void *arg);
  72. #else
  73. unsigned __int64 getTimeValue( void );
  74. #endif
  75. CSTR getTimeStamp(void);
  76. #ifdef __linux__
  77. bool isProcessUniq( CSTR pName );
  78. inline PF_TIMESTAMP * getPFTS( PF_TIMESTAMP * ptr = NULL ){
  79. struct timeval tData;
  80. struct timezone tTZ;
  81. if( ptr == NULL ) {
  82. PF_TIMESTAMP *retVal;
  83. retVal = (PF_TIMESTAMP *) malloc(sizeof(PF_TIMESTAMP));
  84. if( retVal != NULL ) {
  85. if( gettimeofday( &tData, &tTZ ) == -1 ){
  86. free(retVal);
  87. retVal = NULL;
  88. } else {
  89. retVal->seconds = tData.tv_sec;
  90. retVal->milliseconds = ( tData.tv_usec / 1000 );
  91. };
  92. };
  93. return retVal;
  94. } else {
  95. if( gettimeofday( &tData, &tTZ ) == -1 ){
  96. ptr->seconds = 0;
  97. ptr->milliseconds = 0;
  98. } else {
  99. ptr->seconds = tData.tv_sec;
  100. ptr->milliseconds = ( tData.tv_usec / 1000 );
  101. };
  102. return ptr;
  103. };
  104. };
  105. pid_t gettid( void );
  106. #define SLEEP(X) usleep(X*1000)
  107. uint64_t getMilliseconds( void );
  108. #else
  109. #ifndef WIN_XP
  110. #include <VersionHelpers.h>
  111. #endif
  112. #define SLEEP(X) Sleep(X)
  113. unsigned __int64 getMilliseconds( void );
  114. #endif
  115. size_t escape_string( char *to, size_t to_length, const char *from, size_t length );
  116. int getIP4( if_info **arrParam, int max_ifs = 10 );
  117. #ifdef __linux__
  118. long long getTotalSpace( CSTR DirName );
  119. long long getFreeSpace( CSTR DirName );
  120. bool enumerateDevices( enumeratorInfo *mlist, const char *dTemplate = "video" );
  121. #else
  122. __int64 getTotalSpace( CSTR DirName );
  123. __int64 getFreeSpace( CSTR DirName );
  124. bool enumerateDevices(enumeratorInfo *mlist, REFGUID category);
  125. #endif
  126. localIpAddresses *getLocalIP();
  127. #define DELAY_10MS( X ) { for( uint8_t iii = X; iii && ( m_bThreadStatus < TH_ENDED ); iii-- ) SLEEP( 10 ); }
  128. #endif