Files
OpenBMC/meta-luxshare/meta-bhs/recipes-oem/oem-cover-pre-heat/pre-heat/lux_system_api.c
T

2702 lines
63 KiB
C
Raw Normal View History

2026-04-23 17:07:55 +08:00
/***********************************************************
* 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
***********************************************************/
#include "lux_system_api.h"
#include <stdarg.h>
#include <dlfcn.h>
#include <time.h>
#include <sys/mman.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <netdb.h>
/***********************************************************
* Name:
* LuxMsync
*
* Summary:
* flushes changes made to the in-core copy of a file that was mapped into memory using mmap(2) back to the filesystem.
*
* Return Value:
* On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
*
* Parameter Input:
* void *addr
* size_t length
* int flags
*
* Parameter Output:
* None
*
* Author:
* Tivon.Xia@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxMsync(void *addr, size_t length, int flags)
{
return msync(addr, length,flags);
}
/***********************************************************
* Name:
* LuxMmap
*
* Summary:
* creates a new mapping in the virtual address space of the calling process.
*
* Return Value:
* On success, mmap() returns a pointer to the mapped area.
* On error, the value MAP_FAILED (that is, (void *) -1) is returned, and errno is set to indicate the cause of the error.
*
* Parameter Input:
* void *addr ----starting address for the new mapping
* size_t length ----the length of the mapping (>0)
* int prot ----desired memory protection of the mapping (and must not conflict with the open mode of the file)
* int flags ----determines whether updates to the mapping are visible to other processes mapping the same region, and whether
* updates are carried through to the underlying file.
* int fd ----
* off_t offset ----offset must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE).
*
* Parameter Output:
* None
*
* Author:
* Tivon.Xia@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxMmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset)
{
return mmap(addr,length,prot,flags,fd,offset);
}
/***********************************************************
* Name:
* LuxMunmap
*
* Summary:
* deletes the mappings for the specified address range, and causes further references to addresses within the range to generate invalid memory references.
*
* Return Value:
* On success, munmap() returns 0. On failure, it returns -1, and errno is set to indicate the cause of the error (probably to EINVAL).
*
* Parameter Input:
* void *addr
* size_t length
*
* Parameter Output:
* None
*
* Author:
* Tivon.Xia@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxMunmap(void *addr, size_t length)
{
return munmap(addr,length);
}
/***********************************************************
* Name:
* LuxMemset
*
* Summary:
* fill memory with a constant byte
*
* Return Value:
* The memset() function returns a pointer to the memory area pStr.
*
* Parameter Input:
* void* pDestStr -- buffer to initial
* size_t szSize -- buffer size
* int iValue -- initial value
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxMemset(void* pStr, int iValue, size_t szCount)
{
if(NULL == pStr)
{
return NULL;
}
else
{
return memset(pStr,iValue,szCount);
}
}
/***********************************************************
* Name:
* LuxMemset_s
*
* Summary:
* LuxMemset_s(safe memset)
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* void* pDestStr -- buffer to initial
* size_t szSize -- buffer size
* int iValue -- initial value
* size_t szCount -- the size which you want to initial
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxMemsetSafe(void* pDestStr, size_t szSize, int iValue, size_t szCount)
{
if((NULL == pDestStr)||(szCount>szSize))
{
return FUNC_FAILED;
}
void* pNewStr = pDestStr;
while (szSize --)
{
*(char*) pNewStr = (char) iValue;
pNewStr = (char*) pNewStr + 1;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxMemcpy
*
* Summary:
* copy memory area
*
* Return Value:
* The memcpy() function returns a pointer to pDst
*
* Parameter Input:
* void* pDst -- dest buffer
* const void *pSrc -- source buffer
* szCount -- size need to copy
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxMemcpy(void* pDst, const void* pSrc, size_t szCount)
{
if(NULL == pDst || NULL == pSrc)
{
return NULL;
}
else
{
return memcpy(pDst,pSrc,szCount);
}
}
/***********************************************************
* Name:
* LuxMemcpy_s
*
* Summary:
* LuxMemcpy_s(safe memcpy)
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* void* pDst -- dest buffer
* size_t szSize -- dest buffer size
* const void* pSrc -- source buffer
* size_t szCount -- the size which you want to copy
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxMemcpySafe(void* pDst, size_t szSize, const void* pSrc, size_t szCount)
{
char* psrc;
char* pdst;
if((NULL == pDst || NULL == pSrc)||(szCount > szSize))
{
return FUNC_FAILED;
}
if((pSrc < pDst) && (char*)pSrc + szCount > (char*)pDst) /* from back to front*/
{
psrc = (char*)pSrc + szCount - 1;
pdst = (char*)pDst + szCount - 1;
while(szCount--)
{
*pdst-- = *psrc--;
}
}
else
{
psrc = (char*)pSrc;
pdst = (char*)pDst;
while(szCount--)
{
*pdst++ = *psrc++;
}
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxMemcmp
*
* Summary:
* compare memory areas
*
* Return Value:
* The memcmp() function returns an integer less than, equal to, or greater than zero if the first n bytes of pBuf1 is found,
* respectively, to be less than, to match, or be greater than the first szCount bytes of pBuf2.
*
* Parameter Input:
* void* pStr1 -- buf1 need to compare
* void* pStr2 -- buf2 need to compare
* size_t szCount -- the size which you want to compare
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxMemcmp(const void* pBuf1,const void* pBuf2,size_t szCount)
{
if((NULL == pBuf1)||(NULL == pBuf2))
return -1;
else
return memcmp(pBuf1,pBuf2,szCount);
}
/***********************************************************
* Name:
* LuxMemchr
*
* Summary:
* Scans the initial n bytes of the memory area pointed to by s for the first instance of iCharacter
*
* Return Value:
* The memchr() functions return a pointer to the matching byte or NULL if the character does not occur in the given memory area
*
* Parameter Input:
* void* pStr
* int iCharacter
* size_t szCount
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxMemchr(const void* pStr, int iCharacter, size_t szCount)
{
if(NULL == pStr)
return NULL;
else
return memchr(pStr, iCharacter, szCount);
}
/***********************************************************
* Name:
* LuxStrchr
*
* Summary:
* returns a pointer to the first occurrence of the character iCharacter in the string pStr
*
* Return Value:
* The strchr() functions return a pointer to the matched character or NULL if the character is not found.
*
* Parameter Input:
* void* pcStr
* int iCharacter
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrchr(const char* pcStr, int iCharacter)
{
if(NULL == pcStr)
return NULL;
else
return strchr(pcStr, iCharacter);
}
/***********************************************************
* Name:
* LuxStrtok
*
* Summary:
* The strtok() function breaks a string into a sequence of zero or more nonempty tokens.
*
* Return Value:
* The strtok() functions return a pointer to the next token, or NULL if there are no more tokens.
*
* Parameter Input:
* void* pcStr
* int iCharacter
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrtok(char* pcStr, const char* pcDelim)
{
return strtok(pcStr, pcDelim);
}
/***********************************************************
* Name:
* LuxStrcpy
*
* Summary:
* copy a string
*
* Return Value:
* The strcpy() functions return a pointer to the destination string pcDestStr
*
* Parameter Input:
* void* pcDestStr
* void* pcScrStr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrcpy(char* pcDestStr, const char* pcScrStr)
{
if((NULL == pcDestStr)||(NULL == pcScrStr))
return NULL;
else
return strcpy(pcDestStr,pcScrStr);
}
/***********************************************************
* Name:
* LuxStrncpy
*
* Summary:
* copy a string-except that at most szCount bytes of src are copied
*
* Return Value:
* The strcpy() functions return a pointer to the destination string pcDestStr
*
* Parameter Input:
* void* pcDestStr
* void* pcScrStr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrncpy(char* pcDestStr, const char* pcScrStr, size_t szCount)
{
if((NULL == pcDestStr)||(NULL == pcScrStr))
return NULL;
if(szCount<=0)
return NULL;
return strncpy(pcDestStr,pcScrStr,szCount);
}
/***********************************************************
* Name:
* LuxStrcmp
*
* Summary:
* compare two strings
*
* Return Value:
* The strcmp() function compares the two strings pcStr1 and pcStr2. It returns an integer less than, equal to, or greater than zero if pcStr1 is found,
* respectively, to be less than, to match, or be greater than pcStr2.
*
* Parameter Input:
* char* pcStr1
* char* pcStr2
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxStrcmp(const char* pcStr1, const char* pcStr2)
{
if((NULL == pcStr1)||(NULL == pcStr2))
return -1;
else
return strcmp(pcStr1,pcStr2);
}
/***********************************************************
* Name:
* LuxStrncmp
*
* Summary:
* compare two strings
*
* Return Value:
* The strncmp() function is similar to strcmp(), except it compares only the first (at most) szCount bytes of pcStr1 and pcStr2
*
* Parameter Input:
* const char* pcStr1
* const char* pcStr2
* size_t szCount--the count need to compare
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxStrncmp(const char* pcStr1, const char* pcStr2, size_t szCount)
{
if((NULL == pcStr1)||(NULL == pcStr2))
return -1;
if(szCount<=0)
return -1;
return strncmp(pcStr1,pcStr2,szCount);
}
/***********************************************************
* Name:
* LuxStrlen
*
* Summary:
* calculate the length of a string
*
* Return Value:
* The strlen() function returns the number of characters in the string pointed to by pcStr.
*
* Parameter Input:
* char* pcStr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
size_t LuxStrlen(const char* pcStr)
{
if(NULL == pcStr)
return 0;
return strlen(pcStr);
}
/***********************************************************
* Name:
* LuxStrnlen
*
* Summary:
* determine the length of a fixed-size string
*
* Return Value:
* The strnlen() function returns strlen(pcStr), if that is less than szLen, or szLen if there is no null terminating ('\0') among the first szLen characters pointed to by pcStr
*
* Parameter Input:
* char* pcStr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
size_t LuxStrnlen(const char* pcStr, size_t szLen)
{
if(NULL == pcStr)
return 0;
return strnlen(pcStr,szLen);
}
/***********************************************************
* Name:
* LuxStrcat
*
* Summary:
* concatenate two strings
*
* Return Value:
* The strcat() functions return a pointer to the resulting string pcDestStr.
*
* Parameter Input:
* char *pcDestStr
* const char *pcSrcStr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrcat(char* pcDestStr, const char* pcSrcStr)
{
if((NULL == pcDestStr)||(NULL == pcSrcStr))
return NULL;
return strcat(pcDestStr,pcSrcStr);
}
/***********************************************************
* Name:
* LuxStrncat
*
* Summary:
* concatenate two strings
*
* Return Value:
* The strcat() functions return a pointer to the resulting string pcDest.
*
* Parameter Input:
* char* pcDest, const char* pcSrc, size_t szCount
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrncat(char* pcDest, const char* pcSrc, size_t szCount)
{
if((NULL == pcDest)||(NULL == pcSrc))
{
return NULL;
}
return strncat(pcDest,pcSrc,szCount);
}
/***********************************************************
* Name:
* LuxStrstr
*
* Summary:
* locate a substring
*
* Return Value:
* These functions return a pointer to the beginning of the located substring, or NULL if the substring is not found
*
* Parameter Input:
* char* pcDestStr, const char* pcSrcStr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxStrstr(char* pcDestStr, const char* pcSrcStr)
{
if((NULL == pcDestStr)||(NULL == pcSrcStr))
{
return NULL;
}
return strstr(pcDestStr,pcSrcStr);
}
/***********************************************************
* Name:
* LuxPrintf
*
* Summary:
* formatted output conversion
*
* Return Value:
* Upon successful return, these functions return the number of characters printed
* If an output error is encountered, a negative value is returned
*
* Parameter Input:
* const char* pcfmt,...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxPrintf(const char* pcfmt,...)
{
int iRet = 0;
va_list args;
va_start(args,pcfmt);
iRet = vprintf(pcfmt, args);
va_end(args);
return iRet;
}
/***********************************************************
* Name:
* LuxFprintf
*
* Summary:
* formatted output to a file pointor
*
* Return Value:
* Upon successful return, these functions return the number of characters printed
* If an output error is encountered, a negative value is returned
*
* Parameter Input:
* FILE* fp, char* pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFprintf(FILE* fp, char* pcfmt, ...)
{
if(NULL == fp)
{
return -1;
}
else
{
int iRet = 0;
va_list args;
va_start(args,pcfmt);
iRet = vfprintf(fp, pcfmt, args);
va_end(args);
return iRet;
}
}
/***********************************************************
* Name:
* LuxDprintf
*
* Summary:
* formatted output to a file descriptor
*
* Return Value:
* Upon successful return, these functions return the number of characters printed
* If an output error is encountered, a negative value is returned
*
* Parameter Input:
* int fd, const char *pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxDprintf(int fd, const char *pcfmt, ...)
{
if(fd < 0)
{
return -1;
}
else
{
int iRet = 0;
va_list args;
va_start(args,pcfmt);
iRet = vdprintf(fd, pcfmt, args);
va_end(args);
return iRet;
}
}
/***********************************************************
* Name:
* LuxSprintf
*
* Summary:
* formatted output to a buffer
*
* Return Value:
* Upon successful return, these functions return the number of characters printed
* If an output error is encountered, a negative value is returned
*
* Parameter Input:
* char* pcBuf, const char* pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxSprintf(char* pcBuf, const char* pcfmt, ...)
{
va_list args;
int iRet;
va_start(args, pcfmt);
iRet = vsprintf(pcBuf, pcfmt, args);
va_end(args);
return iRet;
}
/***********************************************************
* Name:
* LuxSprintf
*
* Summary:
* formatted output to a buffer at most szSize bytes (including the terminating null byte ('\0'))
*
* Return Value:
* Upon successful return, these functions return the number of characters printed
* If an output error is encountered, a negative value is returned
*
* Parameter Input:
* char* pcBuf, size_t szSize, const char* pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxSnprintf(char* pcBuf, size_t szSize, const char* pcfmt, ...)
{
va_list args;
int iRet;
va_start(args, pcfmt);
iRet = vsnprintf(pcBuf, szSize, pcfmt, args);
va_end(args);
return iRet;
}
/***********************************************************
* Name:
* LuxSscanf
*
* Summary:
* reads its input from the character string pointed to by pcBuf
*
* Return Value:
* On success, return the number of input items successfully matched and assigned
* The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs
*
* Parameter Input:
* const char* pcBuf, const char* pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxSscanf(const char* pcBuf, const char* pcfmt, ...)
{
va_list ap;
int iRet;
va_start(ap, pcfmt);
iRet = vsscanf(pcBuf, pcfmt, ap);
va_end(ap);
return iRet;
}
/***********************************************************
* Name:
* LuxScanf
*
* Summary:
* reads input from the standard input stream stdin
*
* Return Value:
* On success, return the number of input items successfully matched and assigned
* The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs
*
* Parameter Input:
* const char* pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxScanf(const char* pcfmt, ...)
{
va_list ap;
int iRet;
va_start(ap, pcfmt);
iRet = vscanf(pcfmt, ap);
va_end(ap);
return iRet;
}
/***********************************************************
* Name:
* LuxFscanf
*
* Summary:
* reads input from the stream pointer stream
*
* Return Value:
* On success, return the number of input items successfully matched and assigned
* The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs
*
* Parameter Input:
* FILE* pstream, const char* pcfmt, ...
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFscanf(FILE* pstream, const char* pcfmt, ...)
{
if(NULL == pstream)
{
return -1;
}
else
{
va_list ap;
int iRet;
va_start(ap, pcfmt);
iRet = vfscanf(pstream, pcfmt, ap);
va_end(ap);
return iRet;
}
}
/***********************************************************
* Name:
* LuxOpenAndCreat
*
* Summary:
* creat or open a file or a device
*
* Return Value:
* Upon successful return a FILE descriptor.
* Otherwise, NULL is returned and errno is set to indicate the error.
*
* Parameter Input:
* char* pcPathname -- file name to open
* char* iFlags -- file flags to open, support below flags:
* O_RDONLY Open file for reading.
* O_WRONLY Open file for writing.
* O_RDWR Open file for reading and writing.
* if need to create a file,below flags also need to use:
* O_APPEND Append a file.
* O_CREAT Create a new file if file not exist. .
* mode_t mode -- file mode to open, support below mode:
* S_IRUSR/S_IWUSR/S_IXUSR
* S_IRGRP/S_IWGRP/S_IXGRP
* S_IROTH/S_IWOTH/S_IXOTH
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxOpenAndCreat(const char* pcPathname,int iFlags,mode_t mode)
{
return open(pcPathname,iFlags,mode);
}
/***********************************************************
* Name:
* LuxOpen
*
* Summary:
* open a file or a device
*
* Return Value:
* Upon successful return a FILE descriptor.
* Otherwise, NULL is returned and errno is set to indicate the error.
*
* Parameter Input:
* char* pcPathname -- file name to open
* char* iFlags -- file flags to open, support below flags:
* O_RDONLY Open file for reading.
* O_WRONLY Open file for writing.
* O_RDWR Open file for reading and writing.
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxOpen(const char* pcPathname,int iFlags)
{
return open(pcPathname,iFlags);
}
/***********************************************************
* Name:
* LuxClose
*
* Summary:
* close a file or a device
*
* Return Value:
* returns zero on success.
* On error, -1 is returned, and errno is set appropriately.
*
* Parameter Input:
* int fd -- a file descriptor
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxClose(int fd)
{
if(fd < 0)
{
return -1;
}
return close(fd);
}
/***********************************************************
* Name:
* LuxRead
*
* Summary:
* read from a file descriptor
*
* Return Value:
* On success, the number of bytes read is returned (zero indicates end of file).
* On error, -1 is returned, and errno is set appropriately.
*
* Parameter Input:
* int fd -- a file descriptor
* void* pBuf -- read the file into the buf
* size_t szCount -- the count need to read from the file
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
ssize_t LuxRead(int fd, void* pBuf, size_t szCount)
{
if(fd < 0)
{
return -1;
}
return read(fd, pBuf, szCount);
}
/***********************************************************
* Name:
* LuxWrite
*
* Summary:
* write buf to a file descriptor
*
* Return Value:
* On success, the number of bytes write is returned (zero indicates end of file).
* On error, -1 is returned, and errno is set appropriately.
*
* Parameter Input:
* int fd -- a file descriptor
* void* pBuf -- write the buf into the file
* size_t szCount -- the count need to write to the file
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
ssize_t LuxWrite(int fd, void* pBuf, size_t szCount)
{
if(fd < 0)
{
return -1;
}
return write(fd, pBuf, szCount);
}
/***********************************************************
* Name:
* LuxLseek
*
* Summary:
* reposition read/write file offset
*
* Return Value:
* Upon successful completion, returns the resulting offset location as measured in bytes from the beginning of the file..
* On error, the value (off_t) -1 is returned and errno is set to indicate the error.
*
* Parameter Input:
* int fd -- a file descriptor
* off_t offset -- offset to move
* iWhence -- position to move, support below settings:
* SEEK_SET -- The file offset is set to offset bytes.
* SEEK_CUR -- The file offset is set to its current location plus offset bytes.
* SEEK_END -- The file offset is set to the size of the file plus offset bytes.
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
off_t LuxLseek(int fd, off_t offset, int iWhence)
{
if(fd < 0)
{
return -1;
}
return lseek(fd, offset, iWhence);
}
/***********************************************************
* Name:
* LuxFopen
*
* Summary:
* stream open functions
*
* Return Value:
* Upon successful return a FILE pointer.
* Otherwise, NULL is returned and errno is set to indicate the error.
*
* Parameter Input:
* char* pcPathname -- file name to open
* char* pcMode -- file mode to open, support below mode
* r Open text file for reading.
* r+ Open for reading and writing.
* w Truncate file to zero length or create text file for writing.
* w+ Open for reading and writing.
* a Open for appending (writing at end of file).
* a+ Open for reading and appending (writing at end of file).
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
FILE* LuxFopen(const char* pcPathname, const char* pcMode)
{
return fopen(pcPathname,pcMode);
}
/***********************************************************
* Name:
* LuxFclose
*
* Summary:
* close a stream
*
* Return Value:
* Upon successful completion, 0 is returned.
* Otherwise, EOF is returned and errno is set to indicate the error.
*
* Parameter Input:
* FILE* pstream -- pstream to close
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFclose(FILE* pstream)
{
if(NULL == pstream)
{
return -1;
}
return fclose(pstream);
}
/***********************************************************
* Name:
* LuxFread
*
* Summary:
* LuxFread -- read a stream and store to buffer
*
* Return Value:
* On success, return the number of items read. This number equals the number of bytes transferred only when size is 1.
* If an error occurs, or the end of the file is reached, the return value is a short item count (or zero).
*
* Parameter Input:
* const void* ptr -- storing data at the location given by ptr
* size_t szSize -- each size bytes long
* size_t szNmemb -- reads nmemb items of data
* FILE* pstream -- file pstream to read
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
size_t LuxFread(void* ptr, size_t szSize, size_t szNmemb, FILE* pstream)
{
if(NULL == pstream)
{
return -1;
}
return fread(ptr, szSize, szNmemb, pstream);
}
/***********************************************************
* Name:
* LuxFwrite
*
* Summary:
* LuxFwrite -- write buffer data to a stream
*
* Return Value:
* On success, return the number of items written. This number equals the number of bytes transferred only when size is 1.
* If an error occurs, or the end of the file is reached, the return value is a short item count (or zero).
*
* Parameter Input:
* const void* ptr -- obtaining data from the location given by ptr
* size_t szSize -- each size bytes long
* size_t szNmemb -- writes nmemb items of data
* FILE* pstream -- file stream to write
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
size_t LuxFwrite(const void* ptr, size_t szSize, size_t szNmemb, FILE* pstream)
{
if(NULL == pstream)
{
return -1;
}
return fwrite(ptr, szSize, szNmemb, pstream);
}
/***********************************************************
* Name:
* LuxFseek
*
* Summary:
* reposition a stream
*
* Return Value:
* Upon successful completion, return 0.
* Otherwise, -1 is returned and errno is set to indicate the error.
*
* Parameter Input:
* FILE* pstream -- pstream
* long offset -- offset to move
* iWhence -- position to move, support below settings:
* SEEK_SET -- The file offset is set to offset bytes.
* SEEK_CUR -- The file offset is set to its current location plus offset bytes.
* SEEK_END -- The file offset is set to the size of the file plus offset bytes.
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFseek(FILE *pstream, long offset, int iWhence)
{
if(NULL == pstream)
{
return -1;
}
return fseek(pstream,offset,iWhence);
}
/***********************************************************
* Name:
* LuxFtell
*
* Summary:
* LuxFtell -- obtains the current value of the file position indicator for the stream pointed to by stream.
*
* Return Value:
* Upon successful completion,ftell() returns the current offset.
* Otherwise, -1 is returned and errno is set to indicate the error.
*
* Parameter Input:
* FILE* pstream -- file pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
long LuxFtell(FILE* pstream)
{
if(NULL == pstream)
{
return -1;
}
return ftell(pstream);
}
/***********************************************************
* Name:
* LuxFeof
*
* Summary:
* LuxFeof -- The function feof() tests the end-of-file indicator for the stream pointed to by stream, returning nonzero if it is set.
*
* Return Value:
* return nonzero if it is not end of file.
* return zero if it end of file.
*
* Parameter Input:
* FILE* stream -- file pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFeof(FILE* pstream)
{
return feof(pstream);
}
/***********************************************************
* Name:
* LuxFflush
*
* Summary:
* LuxFflush -- forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function.
*
* Return Value:
* Upon successful completion 0 is returned.
* Otherwise, EOF is returned and errno is set to indicate the error. .
*
* Parameter Input:
* FILE* pstream -- file pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFflush(FILE* pstream)
{
return fflush(pstream);
}
/***********************************************************
* Name:
* LuxRewind
*
* Summary:
* LuxRewind -- sets the file position indicator for the stream pointed to by stream to the beginning of the file.
*
* Return Value:
* None
*
* Parameter Input:
* FILE* pstream -- file pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void LuxRewind(FILE* pstream)
{
rewind(pstream);
}
/***********************************************************
* Name:
* LuxRemove
*
* Summary:
* LuxRemove -- deletes a name from the filesystem.
*
* Return Value:
* On success, zero is returned.
* On error, -1 is returned, and errno is set appropriately
*
* Parameter Input:
* char* pcFilename -- file name
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxRemove(const char* pcFilename)
{
if(NULL == pcFilename)
{
return -1;
}
return remove(pcFilename);
}
/***********************************************************
* Name:
* LuxRename
*
* Summary:
* LuxRename -- rename the specified files by replacing the first occurrence of expression in their name by replacement.
*
* Return Value:
* On success, zero is returned.
* On error, -1 is returned, and errno is set appropriately
*
* Parameter Input:
* const char* pcOldFilename, const char* pcNewFilename
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxRename(const char* pcOldFilename, const char* pcNewFilename)
{
return rename(pcOldFilename, pcNewFilename);
}
/***********************************************************
* Name:
* LuxSystem
*
* Summary:
* LuxSystem
*
* Return Value:
* on success, returns FUNC_OK;
* on fail, returns FUNC_FAILED.
*
* Parameter Input:
* char* pcCmdStr -- cmd string need to be executed
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxSystem(char* pcCmdStr)
{
int iStatus = system(pcCmdStr);
if (-1 == iStatus)
{
printf("system error!");
return FUNC_FAILED;
}
else
{
/*printf("exit status value = [0x%x]\n", iStatus);*/
if (WIFEXITED(iStatus))
{
if (0 == WEXITSTATUS(iStatus))
{
/*printf("run shell script successfully.\n");*/
return FUNC_OK;
}
else
{
printf("run shell script fail, script exit code: %d\n", WEXITSTATUS(iStatus));
return FUNC_FAILED;
}
}
else
{
printf("exit status = [%d]\n", WEXITSTATUS(iStatus));
return FUNC_FAILED;
}
}
}
/***********************************************************
* Name:
* LuxPopen
*
* Summary:
* pipe stream to or from a process
*
* Return Value:
* on success, returns a pointer to an open stream that can be used to read or write to the pipe;
* if the fork(2) or pipe(2) calls fail, or if the function cannot allocate memory, NULL is returned.
*
* Parameter Input:
* char* pcCmdStr -- cmd string need to be executed
* char* pcType -- "w" or "r"
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
FILE* LuxPopen(const char* pcCmdStr, const char* pcType)
{
if(NULL == pcCmdStr)
{
return NULL;
}
return popen(pcCmdStr, pcType);
}
/***********************************************************
* Name:
* LuxPclose
*
* Summary:
* LuxPclose
*
* Return Value:
* on success, returns the exit status of the command;
* if wait4(2) returns an error, or some other error is detected, -1 is returned
*
* Parameter Input:
* FILE* pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxPclose(FILE* pstream)
{
if(NULL == pstream)
{
return -1;
}
return pclose(pstream);
}
/***********************************************************
* Name:
* LuxDlopen
*
* Summary:
* open a shared object
*
* Return Value:
* On success, dlopen() return a non-NULL handle for the loaded library.
* On error (file could not be found, was not readable, had the wrong format, or caused errors during load‐ing), these functions return NULL.
*
* Parameter Input:
* char* pcFilename -- file name to open
* int iFlags -- One of the following two values must be included in flags:
* RTLD_LAZY -- Perform lazy binding. Resolve symbols only as the code that references them is executed.
* RTLD_NOW -- If this value is specified, or the environment variable LD_BIND_NOW is set to a nonempty string, all undefined symbols in the shared object are resolved before dlopen() returns.
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxDlopen(const char* pcFilename, int iFlags)
{
void* pDlhandle = NULL;
pDlhandle = dlopen(pcFilename, iFlags);
if(NULL == pDlhandle)
{
return NULL;
}
return pDlhandle;
}
/***********************************************************
* Name:
* LuxDlclose
*
* Summary:
* close a shared object
*
* Return Value:
* On success, dlclose() returns 0;
* on error, it returns a nonzero value.
*
* Parameter Input:
* void* pDlhandle
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxDlclose(void* pDlhandle)
{
if(NULL == pDlhandle)
{
return -1;
}
return dlclose(pDlhandle);
}
/***********************************************************
* Name:
* LuxDlsym
*
* Summary:
* obtain address of a symbol in a shared object or executable
*
* Return Value:
* On success, these functions return the address associated with pcSymbol;
* On failure, return NULL.
*
* Parameter Input:
* FILE* pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxDlsym(void* pDlhandle, const char* pcSymbol)
{
if(NULL == pDlhandle)
{
return NULL;
}
return dlsym(pDlhandle, pcSymbol);
}
/***********************************************************
* Name:
* LuxDlerror
*
* Summary:
* obtain error diagnostic for functions in the dlopen API
*
* Return Value:
* The dlerror() function returns a human-readable, null-terminated string describing the most recent error that occurred
* from a call to one of the functions in the dlopen API since the last call to dlerror().
* dlerror() returns NULL if no errors have occurred since initialization or since it was last called.
*
* Parameter Input:
* FILE* pstream
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxDlerror(void)
{
return dlerror();
}
/***********************************************************
* Name:
* LuxTime
*
* Summary:
* returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)..
*
* Return Value:
* On success, the value of time in seconds since the Epoch is returned.
* On error, ((time_t) -1) is returned, and errno is set appropriately..
*
* Parameter Input:
* time_t* timep
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
time_t LuxTime(time_t* timep)
{
return time(timep);
}
/***********************************************************
* Name:
* LuxCtime
*
* Summary:
* It converts the calendar time t into a null-terminated string.
*
* Return Value:
* On success, LuxCtime() return a pointer to a string.
* On failed, return NULL.
*
* Parameter Input:
* time_t* timep
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxCtime(const time_t* timep)
{
return ctime(timep);
}
/***********************************************************
* Name:
* LuxAsctime
*
* Summary:
* The LuxAsctime() function converts the broken-down time value tm into a null-terminated string with the same format as ctime().
*
* Return Value:
* On success, LuxAsctime() return a pointer to a string.
* On failed, return NULL.
* Parameter Input:
* struct tm* tm
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxAsctime(const struct tm* tm)
{
return asctime(tm);
}
/***********************************************************
* Name:
* LuxGmtime
*
* Summary:
* The gmtime() function converts the calendar time timep to broken-down time representation, expressed in Coordinated Universal Time (UTC)
* Return Value:
* On success, gmtime() return a pointer to a struct tm.
*
* Parameter Input:
* time_t* timep
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
struct tm* LuxGmtime(const time_t* timep)
{
return gmtime(timep);
}
/***********************************************************
* Name:
* LuxLocaltime
*
* Summary:
* The localtime() function converts the calendar time timep to broken-down time representation, expressed relative to the user's specified timezone.
* Return Value:
* On success, localtime() return a pointer to a struct tm.
*
* Parameter Input:
* time_t* timep
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
struct tm* LuxLocaltime(const time_t* timep)
{
return localtime(timep);
}
/***********************************************************
* Name:
* LuxMktime
*
* Summary:
* The mktime() function converts a broken-down time structure, expressed as local time, to calendar time representation.
* Return Value:
* On success, mktime() returns the calendar time (seconds since the Epoch), expressed as a value of type time_t.
* On fail, return (time_t) -1
* Parameter Input:
* time_t* timep
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
time_t LuxMktime(struct tm* tm)
{
return mktime(tm);
}
/***********************************************************
* Name:
* LuxMalloc
*
* Summary:
* The malloc() function allocates size bytes and returns a pointer to the allocated memory.
*
* Return Value:
* The malloc() functions return a pointer to the allocated memory, which is suitably aligned for any built-in type.
* On error, the function return NULL
* Parameter Input:
* size_t size
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxMalloc(size_t size)
{
return malloc(size);
}
/***********************************************************
* Name:
* LuxCalloc
*
* Summary:
* The calloc() function allocates memory for an array of nmemb elements
* of size bytes each and returns a pointer to the allocated memory..
*
* Return Value:
* The calloc() functions return a pointer to the allocated memory, which is suitably aligned for any built-in type.
* On error, the function return NULL
* Parameter Input:
* size_t size
* size_t nmemb
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxCalloc(size_t nmemb, size_t size)
{
return calloc(nmemb, size);
}
/***********************************************************
* Name:
* LuxRealloc
*
* Summary:
* The realloc() function changes the size of the memory block pointed to
* by ptr to size bytes.
*
* Return Value:
* The realloc() function changes the size of the memory block pointed to
* by ptr to size bytes.
* On error, the function return NULL
* Parameter Input:
* void* ptr
* size_t size
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void* LuxRealloc(void* ptr, size_t size)
{
return realloc(ptr, size);
}
/***********************************************************
* Name:
* LuxFree
*
* Summary:
* The free() function frees the memory space pointed to by ptr, which
* must have been returned by a previous call to malloc(), calloc(), or
* realloc()..
* Return Value:
* None
*
* Parameter Input:
* void* ptr
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void LuxFree(void* ptr)
{
free(ptr);
}
/***********************************************************
* Name:
* LuxRand
*
* Summary:
* The rand outputs num pseudo-random bytes after seeding the random number generator once
*
* Return Value:
* The rand() functions return a value between 0 and RAND_MAX (inclusive)
*
* Parameter Input:
* None
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxRand(void)
{
return rand();
}
/***********************************************************
* Name:
* LuxSrand
*
* Summary:
* pseudo-random number generator
*
* Return Value:
* None
*
* Parameter Input:
* unsigned int iSeed
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void LuxSrand(unsigned int iSeed)
{
srand(iSeed);
}
/***********************************************************
* Name:
* LuxAccess
*
* Summary:
* LuxAccess checks whether the calling process can access the file pathname. If pathname is a symbolic link, it is dereferenced
*
* Return Value:
* On success , zero is returned. On error , -1 is returned.
*
* Parameter Input:
* pcPathName:
* Input pathName
* mode:
* F_OK
* R_OK
* W_OK
* X_OK
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxAccess(const char* pcPathName,int mode)
{
if(NULL == pcPathName)
{
return -1;
}
return access(pcPathName,mode);
}
/***********************************************************
* Name:
* LuxReaddir
*
* Summary:
* The LuxReaddir() function returns a pointer to a dirent structure repre�
* senting the next directory entry in the directory stream pointed to by
* dirp. It returns NULL on reaching the end of the directory stream or
* if an error occurred.
*
*
* Return Value:
* On success, readdir() returns a pointer to a dirent structure. (This
* structure may be statically allocated; do not attempt to free(3) it.)
* If the end of the directory stream is reached, NULL is returned and
* errno is not changed. If an error occurs, NULL is returned and errno
* is set appropriately. To distinguish end of stream and from an error,
* set errno to zero before calling readdir() and then check the value of
* errno if NULL is returned.
*
*
* Parameter Input:
* pcPathName:
* Input DIR
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
struct dirent* LuxReaddir(DIR* psDir)
{
if(NULL == psDir)
{
return NULL;
}
return readdir(psDir);
}
/***********************************************************
* Name:
* LuxMkdir
*
* Summary:
* mkdir() attempts to create a directory named pcPathName
*
* Return Value:
* mkdir() and mkdirat() return zero on success, or -1 if an error occurred
* Parameter Input:
* pcPathName:
* Input char* pcPathName:DirName
* mode_t mode:permission
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxMkdir(const char* pcPathName,mode_t mode)
{
if(NULL == pcPathName)
{
return -1;
}
return mkdir(pcPathName,mode);
}
/***********************************************************
* Name:
* LuxClosedir
*
* Summary:
* The LuxClosedir() function closes the directory stream associated with dirp.
* A successful call to closedir() also closes the underlying file descriptor associated with dirp.
* The directory stream descriptor dirp is not available after this call
*
* Return Value:
* The closedir() function returns 0 on success. On error, -1 is returned.
* Parameter Input:
* pcPathName:
* Input DIR* psDir:DirName
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxClosedir(DIR* psDir)
{
if(NULL == psDir)
{
return -1;
}
return closedir(psDir);
}
/***********************************************************
* Name:
* LuxChdir
*
* Summary:
* LuxChdir() changes the current working directory of the calling process to the directory specified in path.
*
* Return Value:
* On success, zero is returned. On error, -1 is returned.
* Parameter Input:
* pcPathName:
* Input const char* pcPathName :DirName
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxChdir(const char* pcPathName)
{
if(NULL == pcPathName)
{
return -1;
}
return chdir(pcPathName);
}
/***********************************************************
* Name:
* LuxRmdir
*
* Summary:
* LuxRmdir() deletes a directory, which must be empty.
*
* Return Value:
* On success, zero is returned. On error, -1 is returned.
* Parameter Input:
* pcPathName:
* Input const char* pcPathName :DirName
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxRmdir(const char* pcPathname)
{
if(NULL == pcPathname)
{
return -1;
}
return rmdir(pcPathname);
}
/***********************************************************
* Name:
* LuxChmod
*
* Summary:
* chmod() changes the mode of the file specified whose pathname is given in pathname, which is dereferenced if it is a symbolic link.
*
* Return Value:
* On success, zero is returned. On error, -1 is returned.
* Parameter Input:
* pcPathName:
* Input const char* pcFilename :file name
* Input mode_t mode :mode
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxChmod(const char* pcFilename,mode_t mode)
{
if(NULL == pcFilename)
{
return -1;
}
return chmod(pcFilename,mode);
}
/***********************************************************
* Name:
* LuxClockgettime
*
* Summary:
* The function clock_getres() finds the resolution (precision) of the specified clock clk_id, and, if res is non-NULL, stores it in the struct timespec pointed to by res. The resolution of
* clocks depends on the implementation and cannot be configured by a particular process. If the time value pointed to by the argument tp of clock_settime() is not a multiple of res, then it is
* truncated to a multiple of res.
*
* Return Value:
* On success, zero is returned. On error, -1 is returned.
* Parameter Input:
* pcPathName:
* Input __clockid_t ClockId :The ClockId argument is the identifier of the particular clock on which to act.
* Output struct timespec* psTimeSpec :stores it in the struct timespec pointed to by psTimeSpec
*
* Parameter Output:
* Output struct timespec* psTimeSpec :stores it in the struct timespec pointed to by psTimeSpec
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxClockgettime (__clockid_t ClockId, struct timespec* psTimeSpec)
{
if(NULL == psTimeSpec)
{
return -1;
}
return clock_gettime(ClockId,psTimeSpec);
}
/***********************************************************
* Name:
* LuxClocksettime
*
* Summary:
* The function LuxClocksettime() finds the resolution (precision) of the specified clock clk_id, and, if res is non-NULL, stores it in the struct timespec pointed to by res. The resolution of
* clocks depends on the implementation and cannot be configured by a particular process. If the time value pointed to by the argument tp of clock_settime() is not a multiple of res, then it is
* truncated to a multiple of res.
*
*
* Return Value:
* On success, zero is returned. On error, -1 is returned.
* Parameter Input:
* pcPathName:
* Input __clockid_t ClockId :The ClockId argument is the identifier of the particular clock on which to act.
* Input struct timespec* psTimeSpec :If the time value pointed to by the argument tp of clock_settime() is not a multiple of res, then it is
* truncated to a multiple of psTimeSpec.
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxClocksettime (__clockid_t ClockId, struct timespec* psTimeSpec)
{
if(NULL == psTimeSpec)
{
return -1;
}
return clock_settime(ClockId,psTimeSpec);
}
/***********************************************************
* Name:
* LuxOpendir
*
* Summary:
* fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.
*
* Return Value:
* returns it as an unsigned char cast to an int, or EOF on end of file or error.
* Parameter Input:
* Input FILE *pstream : in file
*
* Parameter Output:
* None
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFgetc(FILE *pstream)
{
return fgetc(pstream);
}
/***********************************************************
* Name:
* LuxFputc
*
* Summary:
* LuxFputc() writes the character c, cast to an unsigned char, to stream.
*
*
* Return Value:
* return the character written as an unsigned char cast to an int or EOF on error.
* Parameter Input:
* pcPathName:
* Input int chara :character to file stream.
* Input FILE *pstream : in file
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFputc(int chara, FILE *pstream)
{
return fputc(chara,pstream);
}
/***********************************************************
* Name:
* LuxFerror
*
* Summary:
* ferror() tests the error indicator for the stream pointed to by stream.
*
* Return Value:
* returning nonzero if it is set. The error indicator can be reset only by the clearerr() function.
* Parameter Input:
* pcPathName:
* Input FILE *pstream : in file
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxFerror(FILE *pstream)
{
if(NULL == pstream)
{
return 0;
}
return ferror(pstream);
}
/***********************************************************
* Name:
* LuxOpendir
*
* Summary:
* The opendir() function opens a directory stream corresponding to the directory name.
*
* Return Value:
* and returns a pointer to the directory stream. The stream is positioned at the first entry in the direc‐tory.
* Parameter Input:
* pcPathName:
* Input const char *pcdirname : in file
*
* Parameter Output:
* None
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
DIR* LuxOpendir(const char *pcdirname)
{
if(NULL == pcdirname)
{
return NULL;
}
return opendir(pcdirname);
}
/***********************************************************
* Name:
* LuxInetNtop
*
* Summary:
* convert IPv4 and IPv6 addresses from binary to text form
*
* Return Value:
* On success, inet_ntop() returns a non-null pointer to dst.
* NULL is returned if there was an error, with errno set to indicate the error.
*
* Parameter Input:
* AF_INET
* src points to a struct in_addr (in network byte order) which is
* converted to an IPv4 network address in the dotted-decimal for©\
* mat, "ddd.ddd.ddd.ddd". The buffer dst must be at least
* INET_ADDRSTRLEN bytes long.
* AF_INET6
* src points to a struct in6_addr (in network byte order) which is
* converted to a representation of this address in the most appro©\
* priate IPv6 network address format for this address. The buffer
* dst must be at least INET6_ADDRSTRLEN bytes long.
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
const char* LuxInetNtop(int af, const void* pSrc, char* pcDst, size_t size)
{
return inet_ntop(af,pSrc,pcDst,size);
}
/***********************************************************
* Name:
* LuxInetPton
*
* Summary:
* convert IPv4 and IPv6 addresses from text to binary form
*
* Return Value:
* inet_pton() returns 1 on success (network address was successfully converted).
* 0 is returned if src does not contain a character string representing a valid network address in the specified
* address family.
* If af does not contain a valid address family, -1 is returned and errno is set to EAFNOSUPPORT.
*
* Parameter Input:
* AF_INET
* src points to a struct in_addr (in network byte order) which is
* converted to an IPv4 network address in the dotted-decimal for©\
* mat, "ddd.ddd.ddd.ddd". The buffer dst must be at least
* INET_ADDRSTRLEN bytes long.
* AF_INET6
* src points to a struct in6_addr (in network byte order) which is
* converted to a representation of this address in the most appro©\
* priate IPv6 network address format for this address. The buffer
* dst must be at least INET6_ADDRSTRLEN bytes long.
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxInetPton(int af, const char *pcSrc, void *pDst)
{
return inet_pton(af,pcSrc,pDst);
}
/***********************************************************
* Name:
* LuxInetNtoa
*
* Summary:
* The inet_ntoa() function converts the Internet host address in, given in network byte order, to a string in IPv4 dotted-decimal notation.
*
* Return Value:
* The IPV4 address string
* Parameter Input:
* struct in_addr in
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxInetNtoa(struct in_addr in)
{
return inet_ntoa(in);
}
/***********************************************************
* Name:
* LuxSocket
*
* Summary:
* LuxSocket
*
* Return Value:
* None
*
* Parameter Input:
* int domain
* int type
* int protocol
*
* Parameter Output:
* None
*
* Author:
* yulin.yl@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxSocket(int domain, int type, int protocol)
{
return socket(domain, type, protocol);
}
/***********************************************************
* Name:
* LuxIoctl
*
* Summary:
* manipulates the underlying device parameters of special files
*
* Return Value:
* Usually, on success zero is returned. A few ioctl() requests use the return value as an output parameter and return a nonnegative value on success. On error, -1 is returned, and errno is set appropriately.
*
* Parameter Input:
* int fd, unsigned long request, ...
*
* Parameter Output:
* None
*
* Author:
* Wenyu.Li@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxIoctl(int fd, unsigned long request, ...)
{
int iRet = 0;
va_list args;
unsigned long arg;
va_start(args,request);
arg = va_arg(args,unsigned long);
iRet = ioctl(fd,request, arg);
va_end(args);
return iRet;
}
/***********************************************************
* Name:
* LuxReboot
*
* Summary:
* LuxReboot
*
* Return Value:
* None
*
* Parameter Input:
* int iFlag
*
* Parameter Output:
* None
*
* Author:
* tina.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void LuxReboot(int iFlag)
{
reboot(iFlag);
}
/***********************************************************
* Name:
* LuxGetaddrinfo
*
* Summary:
* LuxGetaddrinfo
*
* Return Value:
* None
*
* Parameter Input:
* int iFlag
*
* Parameter Output:
* None
*
* Author:
* chin.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxGetaddrinfo( const char *hostname, const char *service, const struct addrinfo *hints, struct addrinfo **result )
{
return getaddrinfo(hostname,service,hints,result);
}
/***********************************************************
* Name:
* LuxAtoi
*
* Summary:
* LuxAtoi
*
* Return Value:
* int
*
* Parameter Input:
* const char* paddr
*
* Parameter Output:
* None
*
* Author:
* alex-hl.huang@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxAtoi(const char* paddr)
{
return atoi(paddr);
}
/***********************************************************
* Name:
* LuxRegcomp
*
* Summary:
* LuxRegcomp
*
* Return Value:
* int
*
* Parameter Input:
* regex_t *compiled
* const char *pattern
* int cflags
*
* Parameter Output:
* None
*
* Author:
* tina.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxRegcomp(regex_t *compiled, const char *pattern, int cflags)
{
return regcomp(compiled, pattern,cflags);
}
/***********************************************************
* Name:
* LuxRegexec
*
* Summary:
* LuxRegexec
*
* Return Value:
* int
*
* Parameter Input:
* regex_t *compiled
* char *string
* size_t nmatch
* regmatch_t matchptr[]
* int eflags
*
* Parameter Output:
* None
*
* Author:
* tina.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
int LuxRegexec(regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr[], int eflags)
{
return regexec(compiled, string,nmatch,matchptr,eflags);
}
/***********************************************************
* Name:
* LuxRegfree
*
* Summary:
* LuxRegfree
*
* Return Value:
* int
*
* Parameter Input:
* regex_t *compiled
*
* Parameter Output:
* None
*
* Author:
* tina.chen@luxshare-ict.com: Initial Version
*
***********************************************************/
void LuxRegfree(regex_t *compiled)
{
return regfree(compiled);
}