diff --git a/tests/include/win32/setenv.h b/tests/include/win32/setenv.h new file mode 100644 index 00000000000..5a8e5d23865 --- /dev/null +++ b/tests/include/win32/setenv.h @@ -0,0 +1,52 @@ +/* Fluent Bit + * ========== + * Copyright (C) 2015-2023 The Fluent Bit Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This file provides windows wrappers for libc's setenv and unsetenv by using + * the _putenv_s function, which behaves in a similar manner. + * + * setenv man page: + * https://man7.org/linux/man-pages/man3/setenv.3.html + * SetEnvironmentVariable docs: + * https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setenvironmentvariable + * + * - Braydon Kains, @braydonk + */ + +#ifndef SET_ENV_H_ +#define SET_ENV_H_ + +/** + * Just in case some silly goose includes it in a non-Windows build. + */ +#ifdef _WIN32 + +#include + +int setenv(char *name, char *value, int overwrite) +{ + return _putenv_s(name, value); +} + +int unsetenv(char *name) +{ + return _putenv_s(name, ""); +} + +#endif /* _WIN32 */ + +#endif /* SET_ENV_H_ */ \ No newline at end of file diff --git a/tests/internal/parser.c b/tests/internal/parser.c index 67acb1b90a0..593f903b222 100644 --- a/tests/internal/parser.c +++ b/tests/internal/parser.c @@ -11,6 +11,10 @@ #include #include "flb_tests_internal.h" +#ifdef _WIN32 +#include "../include/win32/setenv.h" +#endif + /* Parsers configuration */ #define JSON_PARSERS FLB_TESTS_DATA_PATH "/data/parser/json.conf" #define REGEX_PARSERS FLB_TESTS_DATA_PATH "/data/parser/regex.conf" diff --git a/tests/internal/parser_json.c b/tests/internal/parser_json.c index 27f67d871ea..c5994f67fe0 100644 --- a/tests/internal/parser_json.c +++ b/tests/internal/parser_json.c @@ -27,6 +27,10 @@ #include #include "flb_tests_internal.h" +#ifdef _WIN32 +#include "../include/win32/setenv.h" +#endif + static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj) { int ret = -1; diff --git a/tests/internal/parser_logfmt.c b/tests/internal/parser_logfmt.c index b6ea5bbbf8e..5d8cd96ba81 100644 --- a/tests/internal/parser_logfmt.c +++ b/tests/internal/parser_logfmt.c @@ -27,6 +27,10 @@ #include #include "flb_tests_internal.h" +#ifdef _WIN32 +#include "../include/win32/setenv.h" +#endif + static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj) { int ret = -1; diff --git a/tests/internal/parser_ltsv.c b/tests/internal/parser_ltsv.c index 49b44fc45de..73334bae941 100644 --- a/tests/internal/parser_ltsv.c +++ b/tests/internal/parser_ltsv.c @@ -27,6 +27,10 @@ #include #include "flb_tests_internal.h" +#ifdef _WIN32 +#include "../include/win32/setenv.h" +#endif + static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj) { int ret = -1; diff --git a/tests/internal/parser_regex.c b/tests/internal/parser_regex.c index 582466cbf42..0edc5532cd6 100644 --- a/tests/internal/parser_regex.c +++ b/tests/internal/parser_regex.c @@ -27,6 +27,10 @@ #include #include "flb_tests_internal.h" +#ifdef _WIN32 +#include "../include/win32/setenv.h" +#endif + static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj) { int ret = -1; diff --git a/tests/runtime/filter_parser.c b/tests/runtime/filter_parser.c index d45ec975b7a..daaf332cd24 100644 --- a/tests/runtime/filter_parser.c +++ b/tests/runtime/filter_parser.c @@ -5,6 +5,10 @@ #include #include "flb_tests_runtime.h" +#ifdef _WIN32 +#include "../include/win32/setenv.h" +#endif + #define FLUSH_INTERVAL "1.0" pthread_mutex_t result_mutex = PTHREAD_MUTEX_INITIALIZER;