diff --git a/.gitignore b/.gitignore index c6127b3..d75e1cb 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,6 @@ modules.order Module.symvers Mkfile.old dkms.conf + +# Local files +.vscode/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index d4fa555..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "files.associations": { - "random": "c", - "memory_resource": "c", - "aes.h": "c", - "buf.h": "c", - "base64.h": "c", - "hmac.h": "c", - "md5.h": "c", - "basic.h": "c", - "xstd.h": "c", - "crc32.h": "c", - "sha256.h": "c", - "rsa.h": "c", - "execinfo.h": "c", - "array.h": "c", - "fs.h": "c", - "time.h": "c", - "addr.h": "c", - "type.h": "c", - "ntp.h": "c", - "sync.h": "c", - "encoder.h": "c", - "stdint.h": "c", - "string.h": "c", - "xjson.h": "c", - "map.h": "c", - "xtype.h": "c", - "termios.h": "c", - "xbuf.h": "c", - "xsig.h": "c", - "crypt.h": "c", - "xfs.h": "c", - "xver.h": "c", - "api.h": "c", - "http.h": "c", - "event.h": "c", - "if.h": "c", - "syscall.h": "c", - "byteswap.h": "c", - "array": "c", - "string": "c", - "string_view": "c", - "stdio.h": "c", - "sha1.h": "c", - "compare": "c", - "functional": "c", - "tuple": "c", - "type_traits": "c", - "utility": "c", - "xcli.h": "c", - "xlog.h": "c", - "xtime.h": "c", - "stdlib.h": "c", - "xdef.h": "c" - } -} \ No newline at end of file diff --git a/examples/xlog.c b/examples/xlog.c index 4d602c2..c52664d 100644 --- a/examples/xlog.c +++ b/examples/xlog.c @@ -35,8 +35,6 @@ int main() /* Greet users */ greet(); - XASSERT(0, 0); - /* Initialize XLog with default parameters */ XLog_Init("example", XLOG_ALL, 0); xlog_separator("[xutils]"); @@ -85,8 +83,6 @@ int main() xlogd("just another debug message"); xlogt("just another trace message"); - XLOG_ASSERT(XFALSE, 0, "Message from failed assert"); - xlog_destroy(); return 0; } diff --git a/src/crypt/rsa.c b/src/crypt/rsa.c index f429766..3de0bb2 100644 --- a/src/crypt/rsa.c +++ b/src/crypt/rsa.c @@ -108,7 +108,7 @@ XSTATUS XRSA_GenerateKeys(xrsa_ctx_t *pCtx, size_t nKeyLength, size_t nPubKeyExp return XSTDERR; } - nRetVal = RSA_generate_key_ex(pKeyPair, nKeyLength, pBigNum, NULL); + nRetVal = RSA_generate_key_ex(pKeyPair, (int)nKeyLength, pBigNum, NULL); if (nRetVal != XSTDOK) { RSA_free(pKeyPair); @@ -159,7 +159,7 @@ XSTATUS XRSA_GenerateKeys(xrsa_ctx_t *pCtx, size_t nKeyLength, size_t nPubKeyExp return XSTDERR; } - int nRead = BIO_read(pBioPriv, pCtx->pPrivateKey, pCtx->nPrivKeyLen); + int nRead = BIO_read(pBioPriv, pCtx->pPrivateKey, (int)pCtx->nPrivKeyLen); if ((size_t)nRead != pCtx->nPrivKeyLen) { XRSA_Destroy(pCtx); @@ -169,7 +169,7 @@ XSTATUS XRSA_GenerateKeys(xrsa_ctx_t *pCtx, size_t nKeyLength, size_t nPubKeyExp return XSTDERR; } - nRead = BIO_read(pBioPub, pCtx->pPublicKey, pCtx->nPubKeyLen); + nRead = BIO_read(pBioPub, pCtx->pPublicKey, (int)pCtx->nPubKeyLen); if ((size_t)nRead != pCtx->nPubKeyLen) { XRSA_Destroy(pCtx); @@ -201,7 +201,7 @@ uint8_t* XRSA_Crypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength, size uint8_t *pOutput = malloc(nRSASize + 1); XASSERT(pOutput, NULL); - int nOutLength = RSA_public_encrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding); + int nOutLength = RSA_public_encrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding); XASSERT_FREE((nOutLength > 0 && nOutLength <= nRSASize), pOutput, NULL); if (pOutLength) *pOutLength = (size_t)nOutLength; @@ -222,7 +222,7 @@ uint8_t* XRSA_PrivCrypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength, uint8_t *pOutput = malloc(nRSASize + 1); XASSERT(pOutput, NULL); - int nOutLength = RSA_private_encrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding); + int nOutLength = RSA_private_encrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding); XASSERT_FREE((nOutLength > 0 && nOutLength <= nRSASize), pOutput, NULL); if (pOutLength) *pOutLength = (size_t)nOutLength; @@ -243,7 +243,7 @@ uint8_t* XRSA_PubDecrypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength, uint8_t *pOutput = malloc(nRSASize + 1); XASSERT(pOutput, NULL); - int nOutLength = RSA_public_decrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding); + int nOutLength = RSA_public_decrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding); XASSERT_FREE((nOutLength > 0 && nOutLength <= nRSASize), pOutput, NULL); if (pOutLength) *pOutLength = (size_t)nOutLength; @@ -261,7 +261,7 @@ uint8_t* XRSA_Decrypt(xrsa_ctx_t *pCtx, const uint8_t *pData, size_t nLength, si uint8_t *pOutput = malloc(nLength + 1); XASSERT(pOutput, NULL); - int nOutLength = RSA_private_decrypt(nLength, pData, pOutput, pRSA, pCtx->nPadding); + int nOutLength = RSA_private_decrypt((int)nLength, pData, pOutput, pRSA, pCtx->nPadding); XASSERT_FREE((nOutLength > 0), pOutput, NULL); if (pOutLength) *pOutLength = (size_t)nOutLength; @@ -282,7 +282,7 @@ XSTATUS XRSA_LoadPrivKey(xrsa_ctx_t *pCtx) XASSERT(pCtx->pKeyPair, XSTDERR); } - BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPrivateKey, pCtx->nPrivKeyLen); + BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPrivateKey, (int)pCtx->nPrivKeyLen); XASSERT(pBIO, XSTDERR); RSA *pRSA = PEM_read_bio_RSAPrivateKey(pBIO, &pCtx->pKeyPair, NULL, NULL); @@ -302,7 +302,7 @@ XSTATUS XRSA_LoadPubKey(xrsa_ctx_t *pCtx) XASSERT(pCtx->pKeyPair, XSTDERR); } - BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPublicKey, pCtx->nPubKeyLen); + BIO* pBIO = BIO_new_mem_buf((void*)pCtx->pPublicKey, (int)pCtx->nPubKeyLen); XASSERT(pBIO, XSTDERR); RSA *pRSA = PEM_read_bio_RSAPublicKey(pBIO, &pCtx->pKeyPair, NULL, NULL); diff --git a/src/crypt/sha1.c b/src/crypt/sha1.c index 751d138..115f360 100644 --- a/src/crypt/sha1.c +++ b/src/crypt/sha1.c @@ -148,7 +148,7 @@ XSTATUS XSHA1_Compute(uint8_t *pOutput, size_t nSize, const uint8_t *pInput, siz xsha1_ctx_t xsha; XSHA1_Init(&xsha); - XSHA1_Update(&xsha, pInput, nLength); + XSHA1_Update(&xsha, pInput, (uint32_t)nLength); XSHA1_Final(&xsha, pOutput); return XSTDOK; diff --git a/src/data/xbuf.c b/src/data/xbuf.c index 4456deb..ef718d6 100644 --- a/src/data/xbuf.c +++ b/src/data/xbuf.c @@ -179,7 +179,7 @@ int XByteBuffer_OwnData(xbyte_buffer_t *pBuffer, uint8_t *pData, size_t nSize) XByteBuffer_Clear(pBuffer); XByteBuffer_SetData(pBuffer, pData, nSize); pBuffer->nSize = nSize; - return pBuffer->nSize; + return (int)pBuffer->nSize; } int XByteBuffer_Own(xbyte_buffer_t *pBuffer, xbyte_buffer_t *pSrc) @@ -193,7 +193,7 @@ int XByteBuffer_Own(xbyte_buffer_t *pBuffer, xbyte_buffer_t *pSrc) pSrc->pData = NULL; pSrc->nSize = XSTDNON; pSrc->nUsed = XSTDNON; - return pBuffer->nSize; + return (int)pBuffer->nSize; } int XByteBuffer_Add(xbyte_buffer_t *pBuffer, const uint8_t *pData, size_t nSize) diff --git a/src/data/xstr.c b/src/data/xstr.c index 93a530e..2c279fa 100644 --- a/src/data/xstr.c +++ b/src/data/xstr.c @@ -189,10 +189,10 @@ size_t xstrnfill(char *pDst, size_t nSize, size_t nLength, char cFill) char *xstrfill(size_t nLength, char cFill) { static char sRetVal[XSTR_MAX]; + size_t nLen, i = 0; xstrnul(sRetVal); - int i = 0; - int nLen = XSTD_MIN(nLength, sizeof(sRetVal) - 1); + nLen = XSTD_MIN(nLength, sizeof(sRetVal) - 1); for (i = 0; i < nLen; i++) sRetVal[i] = ' '; sRetVal[i] = '\0'; @@ -827,8 +827,8 @@ int xstrnrep(char *pDst, size_t nSize, const char *pOrig, const char *pRep, cons xstrncpys(pOffset, nAvail, pWith, nWithLen); pOrig += (size_t)nFirstPartLen + nRepLen; - nAvail -= nWithLen; - pOffset += nWithLen; + nAvail -= (int)nWithLen; + pOffset += (int)nWithLen; if (nAvail <= 0) return XSTDNON; } diff --git a/src/net/addr.c b/src/net/addr.c index d6316cd..f6bba65 100644 --- a/src/net/addr.c +++ b/src/net/addr.c @@ -218,7 +218,7 @@ int XAddr_GetIFCIP(const char *pIFace, char *pAddr, int nSize) char *pIPAddr = inet_ntoa(((struct sockaddr_in *)&ifbuf.ifr_addr)->sin_addr); return (pAddr != NULL) ? xstrncpyf(pAddr, nSize, "%s", pIPAddr) : XSTDERR; #endif - return xstrncpyf(pAddr, nSize, "0.0.0.0"); + return (int)xstrncpyf(pAddr, nSize, "0.0.0.0"); } int XAddr_GetIFCMac(const char *pIFace, char *pAddr, int nSize) @@ -242,7 +242,7 @@ int XAddr_GetIFCMac(const char *pIFace, char *pAddr, int nSize) return xstrncpyf(pAddr, nSize, "%02x:%02x:%02x:%02x:%02x:%02x", hwaddr[0],hwaddr[1],hwaddr[2],hwaddr[3],hwaddr[4],hwaddr[5]); #endif - return xstrncpyf(pAddr, nSize, "0:0:0:0:0:0"); + return (int)xstrncpyf(pAddr, nSize, "0:0:0:0:0:0"); } int XAddr_GetMAC(char *pAddr, int nSize) @@ -286,6 +286,6 @@ int XAddr_GetMAC(char *pAddr, int nSize) close(sock); return nLength; #endif - return xstrncpyf(pAddr, nSize, "0:0:0:0:0:0"); + return (int)xstrncpyf(pAddr, nSize, "0:0:0:0:0:0"); } diff --git a/src/net/api.c b/src/net/api.c index b87f9dc..ace9e31 100644 --- a/src/net/api.c +++ b/src/net/api.c @@ -264,7 +264,7 @@ xbyte_buffer_t* XAPI_GetTxBuff(xapi_data_t *pApiData) XSTATUS XAPI_PutTxBuff(xapi_data_t *pApiData, xbyte_buffer_t *pBuffer) { XASSERT_RET((pApiData && pBuffer), XSTDINV); - XASSERT_RET(pBuffer->nUsed, pApiData->txBuffer.nUsed); + XASSERT_RET(pBuffer->nUsed, (XSTATUS)pApiData->txBuffer.nUsed); XByteBuffer_AddBuff(&pApiData->txBuffer, pBuffer); if (!pApiData->txBuffer.nUsed) diff --git a/src/net/event.c b/src/net/event.c index c28e6a0..8b7d115 100644 --- a/src/net/event.c +++ b/src/net/event.c @@ -410,7 +410,7 @@ xevent_status_t XEvents_Service(xevents_t *pEv, int nTimeoutMs) if (nRet != XEVENTS_CONTINUE) break; } #else - for (i = 0; i < pEv->nEventCount; i++) + for (i = 0; i < (int)pEv->nEventCount; i++) { if (pEv->pEventArray[i].revents <= 0) continue; else if (pEv->pEventArray[i].fd == XSOCK_INVALID) break; diff --git a/src/net/sock.c b/src/net/sock.c index 81799b3..c320b2b 100644 --- a/src/net/sock.c +++ b/src/net/sock.c @@ -235,7 +235,7 @@ void XSock_DeinitSSL(void) int XSock_LastSSLError(char *pDst, size_t nSize) { if (pDst == NULL) return XSOCK_NONE; - int nLength = 0; + size_t nLength = 0; pDst[0] = XSTR_NUL; #ifdef XSOCK_USE_SSL @@ -262,7 +262,7 @@ int XSock_LastSSLError(char *pDst, size_t nSize) (void)nSize; #endif - return nLength; + return (int)nLength; } int xclosesock(XSOCKET nFd) @@ -588,7 +588,7 @@ int XSock_SSLWrite(xsock_t *pSock, const void *pData, size_t nLength) while (nLeft > 0) { - int nBytes = SSL_write(pSSL, &pBuff[nSent], nLeft); + int nBytes = SSL_write(pSSL, &pBuff[nSent], (int)nLeft); if (nBytes <= 0) { int nError = SSL_get_error(pSSL, nBytes); @@ -623,7 +623,7 @@ int XSock_SSLWrite(xsock_t *pSock, const void *pData, size_t nLength) if (XSock_IsNB(pSock)) break; } - return nSent; + return (int)nSent; #else pSock->eStatus = XSOCK_ERR_NOSSL; XSock_Close(pSock); @@ -826,7 +826,7 @@ XSOCKET XSock_Accept(xsock_t *pSock, xsock_t *pNewSock) } SSL_set_accept_state(pSSL); - SSL_set_fd(pSSL, pNewSock->nFD); + SSL_set_fd(pSSL, (int)pNewSock->nFD); XSOCKET nFD = XSock_SetSSL(pNewSock, pSSL); XASSERT((nFD != XSOCK_INVALID), XSOCK_INVALID); @@ -1463,10 +1463,10 @@ XSOCKET XSock_InitSSLClient(xsock_t *pSock) } SSL_set_connect_state(pSSL); - SSL_set_fd(pSSL, pSock->nFD); + SSL_set_fd(pSSL, (int)pSock->nFD); #ifdef SSL_OP_IGNORE_UNEXPECTED_EOF - long nOpts = SSL_get_options(pSSL); + long nOpts = (long)SSL_get_options(pSSL); nOpts |= SSL_OP_IGNORE_UNEXPECTED_EOF; SSL_set_options(pSSL, nOpts); #endif diff --git a/src/net/ws.c b/src/net/ws.c index 81bebba..1aecad1 100644 --- a/src/net/ws.c +++ b/src/net/ws.c @@ -160,7 +160,7 @@ uint8_t* XWS_CreateFrame(const uint8_t *pPayload, size_t nLength, uint8_t nOpCod if (nLength <= 125) { - nLengthByte = nLength; + nLengthByte = (uint8_t)nLength; } else if (nLength <= 65535) { diff --git a/src/sys/xcli.c b/src/sys/xcli.c index 542183c..e31a047 100644 --- a/src/sys/xcli.c +++ b/src/sys/xcli.c @@ -52,7 +52,7 @@ int XCLI_GetInput(const char *pText, char *pInput, size_t nSize, xbool_t bCutNew pInput[0] = XSTR_NUL; if (pText != NULL) printf("%s", pText); - char *pRet = fgets(pInput, nSize, stdin); + char *pRet = fgets(pInput, (int)nSize, stdin); XASSERT_RET((pRet != NULL), XSTDERR); if (!xstrused(pInput)) return XSTDNON; diff --git a/src/sys/xfs.c b/src/sys/xfs.c index 4704078..7b976f3 100644 --- a/src/sys/xfs.c +++ b/src/sys/xfs.c @@ -368,7 +368,7 @@ int XFile_ReadLine(xfile_t *pFile, char* pLine, size_t nSize, size_t nLineNum) { nRet = XFile_GetLine(pFile, pLine, nSize); if (nRet <= 0) return XSTDERR; - if (++nLine == nLineNum) return nRet; + if (++nLine == nLineNum) return (int)nRet; } return XSTDERR; @@ -611,10 +611,10 @@ long XPath_GetSize(const char *pPath) if (XFile_Open(&srcFile, pPath, NULL, NULL) >= 0) { XFile_GetStats(&srcFile); - long nSize = srcFile.nSize; + size_t nSize = srcFile.nSize; XFile_Close(&srcFile); - return nSize; + return (long)nSize; } return XSTDERR; diff --git a/src/sys/xlog.c b/src/sys/xlog.c index f4dcd4d..ca7bca5 100644 --- a/src/sys/xlog.c +++ b/src/sys/xlog.c @@ -136,7 +136,7 @@ static xbool_t XLog_OpenFile(xlog_file_t *pFile, const xlog_cfg_t *pCfg, const x if (pFile->pHandle == NULL) { printf("<%s:%d> %s: [ERROR] Failed to open file: %s (%s)\n", - __FILE__, __LINE__, __func__, sFilePath, strerror(errno)); + __FILE__, __LINE__, __func__, sFilePath, XSTRERR); return XFALSE; } @@ -544,7 +544,7 @@ void XLog_FlagsSet(uint16_t nFlags) uint16_t XLog_FlagsGet(void) { - XASSERT_RET(XSTDNON, g_bInit); + XASSERT_RET(g_bInit, XSTDNON); XSync_Lock(&g_xlog.lock); uint16_t nFlags = g_xlog.config.nFlags; XSync_Unlock(&g_xlog.lock); @@ -553,7 +553,7 @@ uint16_t XLog_FlagsGet(void) size_t XLog_PathSet(const char *pPath) { - XASSERT_RET(XSTDNON, g_bInit); + XASSERT_RET(g_bInit, XSTDNON); XSync_Lock(&g_xlog.lock); xlog_file_t *pFile = &g_xlog.fileCtx; @@ -569,7 +569,7 @@ size_t XLog_PathSet(const char *pPath) size_t XLog_NameSet(const char *pName) { - XASSERT_RET(XSTDNON, g_bInit); + XASSERT_RET(g_bInit, XSTDNON); XSync_Lock(&g_xlog.lock); xlog_file_t *pFile = &g_xlog.fileCtx; diff --git a/src/xdef.h b/src/xdef.h index fe58880..936e017 100644 --- a/src/xdef.h +++ b/src/xdef.h @@ -10,6 +10,9 @@ #ifndef __XUTILS_STDDEF_H__ #define __XUTILS_STDDEF_H__ +#include +#include + #ifdef _WIN32 typedef int xsocklen_t; typedef long xatomic_t; @@ -99,10 +102,6 @@ typedef uint8_t xbool_t; #define XSTDUSR 2 #endif -#ifndef XSTRERR -#define XSTRERR strerror(errno) -#endif - #define XCLR_RED "\x1B[31m" #define XCLR_RES "\x1B[0m" @@ -226,6 +225,24 @@ typedef uint8_t xbool_t; #define XSTD_FIRSTOF(a,b)(a?a:b) #endif +#ifdef _WIN32 +static inline const char* XSTR_Error() +{ + static char buf[XMSG_MID]; + strerror_s(buf, sizeof(buf), errno); + return buf; +} +#else +static inline const char* XSTR_Error() +{ + return strerror(errno); +} +#endif + +#ifndef XSTRERR +#define XSTRERR XSTR_Error() +#endif + #define XSSL_MINIMAL_API 0x10000000L typedef int XSTATUS; diff --git a/src/xver.h b/src/xver.h index 30dd542..3bf71c6 100644 --- a/src/xver.h +++ b/src/xver.h @@ -12,7 +12,7 @@ #define XUTILS_VERSION_MAX 2 #define XUTILS_VERSION_MIN 5 -#define XUTILS_BUILD_NUMBER 53 +#define XUTILS_BUILD_NUMBER 54 #ifdef __cplusplus extern "C" {