diff --git a/README.md b/README.md index 2a7c70a..0017b85 100644 --- a/README.md +++ b/README.md @@ -328,11 +328,16 @@ Without indentations enabled: ### Version -There are two ways to get and print slog version with this library. Function `slog_version()` returns char pointer of static array where slog version string is located. If argument is more than zero function returns string with only version and build number. Otherwise it returns full version format with build date. +Get `slog` version with the function `slog_version(3)` +- First argument is destination buffer +- Second argument is destination buffer size +- Third argument is short/full version flag Usage: ```c -printf("slog version: %s", slog_version(0)); +char version[128]; +slog_version(version, sizeof(version), 0); +printf("slog version: %s", version); ``` Output will be something like that: @@ -340,6 +345,12 @@ Output will be something like that: slog version: 1.8 build 22 (Dec 14 2020) ``` +There are also definitions that can be used to check the version without using the function. + +- `SLOG_VERSION_MAJOR` - Major version of the library. +- `SLOG_VERSION_MINOR` - minor version of the library. +- `SLOG_BUILD_NUM` - Build number. + ### Output Here is en example of the log file context created by slog: ``` diff --git a/src/slog.c b/src/slog.c index 6cfcf80..e1e96f3 100644 --- a/src/slog.c +++ b/src/slog.c @@ -185,7 +185,12 @@ static uint8_t slog_open_file(slog_file_t *pFile, const slog_config_t *pCfg, con snprintf(sFilePath, sizeof(sFilePath), "%s/%s-%04d-%02d-%02d.log", pCfg->sFilePath, pCfg->sFileName, pDate->nYear, pDate->nMonth, pDate->nDay); +#ifdef _WIN32 + if (fopen_s(&pFile->pHandle, sFilePath, "a")) pFile->pHandle = NULL; +#else pFile->pHandle = fopen(sFilePath, "a"); +#endif + if (pFile->pHandle == NULL) { printf("<%s:%d> %s: [ERROR] Failed to open file: %s (%s)\n", diff --git a/src/slog.h b/src/slog.h index 61d78c4..e0c6057 100644 --- a/src/slog.h +++ b/src/slog.h @@ -36,7 +36,7 @@ extern "C" { /* SLog version information */ #define SLOG_VERSION_MAJOR 1 #define SLOG_VERSION_MINOR 8 -#define SLOG_BUILD_NUM 35 +#define SLOG_BUILD_NUM 36 /* Supported colors */ #define SLOG_COLOR_NORMAL "\x1B[0m"