|
|
#ifndef __BASIC_FUNCTIONALITY_HEADER__
#define __BASIC_FUNCTIONALITY_HEADER__
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#define USE_SYSTEM_CALL_TO_PING
#if defined(__APPLE__) || defined(__FreeBSD__)
#include <copyfile.h>
#else
#ifdef __linux__
#include <sys/sendfile.h>
#endif
#endif
#ifdef __linux__
#include <arpa/inet.h>
#include <grp.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <pwd.h>
#include <sys/socket.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <unistd.h>
int ch_chown(const char * file_path, const char * user_name, const char * group_name); #include "basicBuildTimeStamp.h"
#else
// #include <winsock2.h>
// #include <ws2tcpip.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <atlbase.h>
#include <dshow.h>
#include <VersionHelpers.h>
#include <windows.h>
#endif
#include "basicTypes.h"
#include <sys/stat.h>
#include <sys/types.h>
int fileCopy(const char * source, const char * destination);bool fileExist(CSTR strFilename);bool dirEmpty(CSTR dirname);
CSTR trim(CSTR string);uint8_t checksum8(uint8_t * Buffer, size_t BufferSize);uint16_t checksum16(uint8_t * Buffer, size_t BufferSize);uint8_t checksumLGS(uint8_t * Buffer, size_t BufferSize);uint16_t checksumPing(void * b, size_t len);CArray * explode(char Delim, CSTR S_Str);CSTR implode(CArray * Data, CSTR S_Str, U8 Start, U8 End);CSTR getTStr(CSTR Fmt = NULL);CSTR getUniqID_SHA256(void);uid_t getUserUid(CSTR uname);gid_t getUserGid(CSTR uname);bool createAccessibleDir(CSTR path, mode_t mode, uid_t uid, gid_t gid);off_t getFileSize(const char * filename);
int rand(int a, int b);
CSTR getUniqID_MD5(void);CSTR getUniqID_UUID(uint32_t SEED = 0);void getUniqID_UUID(CSTR bu, uint32_t SEED = 0);CSTR strReplace(CSTR orig, CSTR rep, CSTR with);
int checkCmdExists(CSTR cmd);int getLocalDay();// Local hour of day (0..23) of time t (t == 0: now), -1 on error
int getLocalHour(time_t t = 0);
ssize_t readLine(int fd, char * buffer, size_t n);ssize_t readLine(FILE * fd, char * buffer, size_t n);
// #define EPOCH_DIFF 11644473600LL
#define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000
bool correctSysTime(int diff);bool correctSoftTime(int diff);
#define CLEAR(x) memset(&(x), 0, sizeof(x))
#ifdef __linux__
unsigned long long getTimeValue(void);int xioctl(int fh, unsigned long request, void * arg);#else
unsigned __int64 getTimeValue(void);#endif
CSTR getTimeStamp(void);
#ifdef __linux__
bool isProcessUniq(CSTR pName);
inline PF_TIMESTAMP * getPFTS(PF_TIMESTAMP * ptr = NULL){ struct timeval tData; struct timezone tTZ; if (ptr == NULL) { PF_TIMESTAMP * retVal; retVal = (PF_TIMESTAMP *) malloc(sizeof(PF_TIMESTAMP)); if (retVal != NULL) { if (gettimeofday(&tData, &tTZ) == -1) { free(retVal); retVal = NULL; } else { retVal->seconds = tData.tv_sec; retVal->milliseconds = (tData.tv_usec / 1000); }; }; return retVal; } else { if (gettimeofday(&tData, &tTZ) == -1) { ptr->seconds = 0; ptr->milliseconds = 0; } else { ptr->seconds = tData.tv_sec; ptr->milliseconds = (tData.tv_usec / 1000); }; return ptr; };}
pid_t gettid(void); #define SLEEP(X) usleep(X * 1000)
uint64_t getMilliseconds(void);bool pingIP4(CSTR ip4);#else
#ifndef WIN_XP
#include <VersionHelpers.h>
#endif
#define SLEEP(X) Sleep(X)
unsigned __int64 getMilliseconds(void);#endif
size_t escape_string(char * to, size_t to_length, const char * from, size_t length);
int getIP4(if_info ** arrParam, int max_ifs = 10);
#ifdef __linux__
long long getTotalSpace(CSTR DirName);long long getFreeSpace(CSTR DirName);bool enumerateDevices(enumeratorInfo * mlist, const char * dTemplate = "video");#else
__int64 getTotalSpace(CSTR DirName);__int64 getFreeSpace(CSTR DirName);bool enumerateDevices(enumeratorInfo * mlist, REFGUID category);#endif
localIpAddresses * getLocalIP();
#define DELAY_10MS(X) \
{ \ for (uint8_t iii = X; iii && (m_bThreadStatus < TH_ENDED); iii--) \ SLEEP(10); \ }
#endif
|