/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_system_api
*
* Description :
* 	system or C API
*
* History:
*
* <Date> 		<Author> 		<version> 		<Modification>
* 2021/03/23		chin 			0.01 		First draft
* 2021/4/25      huangliang         0.02        add system calls
***********************************************************/
#ifndef __LUX_SYSTEM_API_H__
#define __LUX_SYSTEM_API_H__
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include "lux_base.h"
#include <unistd.h>
#include <arpa/inet.h>
#include <regex.h>
#include <netdb.h>	   /* gethostbyname() */

#define F_OK    0

extern void* LuxMmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
extern int LuxMunmap(void *addr, size_t length);
extern int LuxMsync(void *addr, size_t length, int flags);
extern void* LuxMemset(void* pStr, int iValue, size_t szCount);
extern EFuncRetCode LuxMemsetSafe(void* pDestStr, size_t szSize, int iValue, size_t szCount);
extern void* LuxMemcpy(void* pDst, const void* pSrc, size_t szCount);
extern EFuncRetCode LuxMemcpySafe(void* pDst, size_t szSize, const void* pSrc, size_t szCount);
extern int LuxMemcmp(const void* pBuf1,const void* pBuf2,size_t szCount);
extern char* LuxStrcpy(char* pcDestStr, const char* pcScrStr);
extern char* LuxStrncpy(char* pcDestStr, const char* pcScrStr, size_t szCount);
extern int LuxStrcmp(const char* pcStr1, const char* pcStr2);
extern int LuxStrncmp(const char* pcStr1, const char* pcStr2, size_t szCount);
extern size_t LuxStrlen(const char* pcStr);
extern size_t LuxStrnlen(const char* pcStr, size_t szLen);
extern char* LuxStrcat(char* pcDestStr, const char* pcSrcStr);
extern char* LuxStrncat(char* pcDest, const char* pcSrc, size_t szCount);
extern char* LuxStrstr(char* pcDestStr, const char* pcSrcStr);
extern int LuxPrintf(const char* fmt,...);
extern int LuxFprintf(FILE* fp, char* fmt, ...);
extern int LuxDprintf(int fd, const char *fmt, ...);
extern int LuxSprintf(char* pcBuf, const char* fmt, ...);
extern int LuxSnprintf(char* pcBuf, size_t szSize, const char* fmt, ...);
extern int LuxSscanf(const char* pcBuf, const char* fmt, ...);
extern int LuxScanf(const char* fmt, ...);
extern int LuxFscanf(FILE* stream, const char* fmt, ...);
extern int LuxOpenAndCreat(const char* pcPathname,int iFlags,mode_t mode);
extern int LuxOpen(const char* pcPathname,int iFlags);
extern int LuxClose(int fd);
extern ssize_t LuxRead(int fd, void* pBuf, size_t szCount);
extern ssize_t LuxWrite(int fd, void* pBuf, size_t szCount);
extern off_t LuxLseek(int fd, off_t offset, int iWhence);
extern FILE* LuxFopen(const char* pcPathname, const char* pcMode);
extern int LuxFclose(FILE* stream);
extern size_t LuxFread(void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern size_t LuxFwrite(const void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern int LuxFseek(FILE *stream, long offset, int iWhence);
extern long LuxFtell(FILE* stream);
extern void LuxRewind(FILE* stream);
extern EFuncRetCode LuxSystem(char* pcCmdStr);
extern FILE* LuxPopen(const char* pcCmdStr, const char* pcType);
extern int LuxPclose(FILE* stream);
extern void* LuxDlopen(const char* pcFilename, int iFlags);
extern int LuxDlclose(void* pDlhandle);
extern void* LuxDlsym(void* pDlhandle, const char* pcSymbol);
extern char* LuxDlerror(void);
extern time_t LuxTime(time_t* timep);
extern char* LuxCtime(const time_t* timep);
extern char* LuxAsctime(const struct tm* tm);
extern struct tm* LuxGmtime(const time_t* timep);
extern struct tm* LuxLocaltime(const time_t* timep);
extern time_t LuxMktime(struct tm* tm);
extern void* LuxMalloc(size_t size);
extern void* LuxCalloc(size_t nmemb, size_t size);
extern void* LuxRealloc(void* ptr, size_t size);
extern void LuxFree(void* ptr);
extern void* LuxMemchr(const void* pStr, int iCharacter, size_t szCount);
extern char* LuxStrchr(const char* pcStr, int iCharacter);
extern char* LuxStrtok(char* pcStr, const char* pcDelim);
extern int LuxFeof(FILE* stream);
extern int LuxFflush(FILE* stream);
extern int LuxRemove(const char* pcFilename);
extern int LuxRename(const char* pcOldFilename, const char* pcNewFilename);
extern int LuxRand(void);
extern void LuxSrand(unsigned int iSeed);

extern int  LuxAccess(const char* pcPathName,int mode);

extern int  LuxClosedir(DIR* psDir);
extern struct dirent*  LuxReaddir(DIR* psDir);
extern int  LuxChdir(const char* pcPathName);
extern int  LuxRmdir(const char* pcPathname);
extern int  LuxChmod(const char* pcFilename,mode_t mode);
extern int  LuxMkdir(const char* pcPathName,mode_t mode);
extern int  LuxClockgettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int  LuxClocksettime (__clockid_t ClockId, struct timespec* psTimeSpec);

extern int  LuxFgetc(FILE *pstream);
extern int  LuxFputc(int chara, FILE *pstream);
extern int  LuxFerror(FILE *pstream);
extern DIR* LuxOpendir(const char *pcdirname);

extern const char* LuxInetNtop(int af, const void* psrc, char* pcDst, size_t size);
extern int LuxInetPton(int af, const char *pcSrc, void *pDst);
extern char* LuxInetNtoa(struct in_addr in);
extern int LuxSocket(int domain, int type, int protocol);
extern int LuxIoctl(int fd, unsigned long request, ...);
extern void LuxReboot(int iFlag);
extern int LuxRegcomp(regex_t *compiled, const char *pattern, int cflags);
extern int LuxRegexec(regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr[], int eflags);
extern void LuxRegfree(regex_t *compiled);
extern int LuxGetaddrinfo( const char *hostname, const char *service, const struct addrinfo *hints, struct addrinfo **result );
extern int LuxAtoi(const char* paddr);

#endif


