Skip to content

Commit

Permalink
logger: MSVC build warnings fix
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Aug 3, 2024
1 parent 9e9e8ef commit b184ff6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ extern "C" {
#endif

#if (defined(_WIN32) || defined(_WIN64))
#include <io.h>
#define __format_printf(x, y)
#define __noreturn
#define __noreturn __declspec(noreturn)
#define __weak
#define __unreachable() __assume(0)
#define likely(p) (p)
#define unlikely(p) (p)
#define isatty _isatty
#define isatty _isatty /* from io.h */
#define fileno _fileno
#else
#define __format_printf(x, y) __attribute__((format(printf, x, y)))
Expand Down
16 changes: 15 additions & 1 deletion src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

/* To disable warnings about use of strncpy and suggestions to use the more
* secure variant strncpy_s in MSVC */
#define _CRT_SECURE_NO_WARNINGS

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -15,6 +20,14 @@

#include <utils/logger.h>

#if (defined(_WIN32) || defined(_WIN64))
/*
* For MSVC, we are expected use _write() and the type of len is unsigned int
* instead of size_t in unix.
*/
#define write(fd, data, len) _write((fd), (data), (unsigned int)(len))
#endif

#define RED "\x1B[31m"
#define GRN "\x1B[32m"
#define YEL "\x1B[33m"
Expand Down Expand Up @@ -46,7 +59,8 @@ static const char *log_level_names[LOG_MAX_LEVEL] = {

static inline void logger_log_set_color(logger_t *ctx, const char *color)
{
int ret, len;
int ret;
size_t len;

if (ctx->flags & LOGGER_FLAG_NO_COLORS)
return;
Expand Down

0 comments on commit b184ff6

Please sign in to comment.