Skip to content

Commit b184ff6

Browse files
committedAug 3, 2024
logger: MSVC build warnings fix
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 9e9e8ef commit b184ff6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
 

‎include/utils/utils.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ extern "C" {
132132
#endif
133133

134134
#if (defined(_WIN32) || defined(_WIN64))
135+
#include <io.h>
135136
#define __format_printf(x, y)
136-
#define __noreturn
137+
#define __noreturn __declspec(noreturn)
137138
#define __weak
138139
#define __unreachable() __assume(0)
139140
#define likely(p) (p)
140141
#define unlikely(p) (p)
141-
#define isatty _isatty
142+
#define isatty _isatty /* from io.h */
142143
#define fileno _fileno
143144
#else
144145
#define __format_printf(x, y) __attribute__((format(printf, x, y)))

‎src/logger.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6+
7+
/* To disable warnings about use of strncpy and suggestions to use the more
8+
* secure variant strncpy_s in MSVC */
9+
#define _CRT_SECURE_NO_WARNINGS
10+
611
#include <stdarg.h>
712
#include <stdio.h>
813
#include <stdlib.h>
@@ -15,6 +20,14 @@
1520

1621
#include <utils/logger.h>
1722

23+
#if (defined(_WIN32) || defined(_WIN64))
24+
/*
25+
* For MSVC, we are expected use _write() and the type of len is unsigned int
26+
* instead of size_t in unix.
27+
*/
28+
#define write(fd, data, len) _write((fd), (data), (unsigned int)(len))
29+
#endif
30+
1831
#define RED "\x1B[31m"
1932
#define GRN "\x1B[32m"
2033
#define YEL "\x1B[33m"
@@ -46,7 +59,8 @@ static const char *log_level_names[LOG_MAX_LEVEL] = {
4659

4760
static inline void logger_log_set_color(logger_t *ctx, const char *color)
4861
{
49-
int ret, len;
62+
int ret;
63+
size_t len;
5064

5165
if (ctx->flags & LOGGER_FLAG_NO_COLORS)
5266
return;

0 commit comments

Comments
 (0)